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 | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
| 24 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
| 25 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 27 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 28 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
| 34 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 35 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS; |
| 36 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 37 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 38 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 39 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 40 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 41 | import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 42 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 43 | import android.app.ActivityManager.StackId; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 44 | import android.graphics.Rect; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 45 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 46 | import android.graphics.Region.Op; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 47 | import android.hardware.display.DisplayManagerInternal; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 48 | import android.os.Debug; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 49 | import android.util.DisplayMetrics; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 50 | import android.util.Slog; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 51 | import android.view.Display; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 52 | import android.view.DisplayInfo; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 53 | import android.view.IWindow; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 54 | import android.view.Surface; |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 55 | import android.view.animation.Animation; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 56 | import com.android.internal.util.FastPrintWriter; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 57 | |
| 58 | import java.io.PrintWriter; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 59 | import java.io.StringWriter; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 60 | import java.util.ArrayList; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 61 | import java.util.Arrays; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 62 | |
| 63 | class DisplayContentList extends ArrayList<DisplayContent> { |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 68 | * particular Display. |
| 69 | * |
| 70 | * IMPORTANT: No method from this class should ever be used without holding |
| 71 | * WindowManagerService.mWindowMap. |
| 72 | */ |
| 73 | class DisplayContent { |
| 74 | |
| 75 | /** Unique identifier of this stack. */ |
| 76 | private final int mDisplayId; |
| 77 | |
| 78 | /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element |
| 79 | * from mDisplayWindows; */ |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 80 | private final WindowList mWindows = new WindowList(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 81 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 82 | int mInitialDisplayWidth = 0; |
| 83 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 84 | int mInitialDisplayDensity = 0; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 85 | int mBaseDisplayWidth = 0; |
| 86 | int mBaseDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 87 | int mBaseDisplayDensity = 0; |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 88 | boolean mDisplayScalingDisabled; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 89 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 90 | private final Display mDisplay; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 91 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 92 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 93 | Rect mBaseDisplayRect = new Rect(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 94 | private Rect mContentRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 95 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 96 | // Accessed directly by all users. |
| 97 | boolean layoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 98 | int pendingLayoutChanges; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 99 | final boolean isDefaultDisplay; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 100 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 101 | /** 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] | 102 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 103 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 104 | /** Array containing all TaskStacks on this display. Array |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 105 | * is stored in display order with the current bottom stack at 0. */ |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 106 | private final ArrayList<TaskStack> mStacks = new ArrayList<>(); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 107 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 108 | /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack |
| 109 | * (except a future lockscreen TaskStack) moves to the top. */ |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 110 | private TaskStack mHomeStack = null; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 111 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 112 | /** Detect user tapping outside of current focused task bounds .*/ |
| 113 | TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 114 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 115 | /** Detect user tapping outside of current focused stack bounds .*/ |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 116 | private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 117 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 118 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 119 | private final Rect mTmpRect = new Rect(); |
| 120 | private final Rect mTmpRect2 = new Rect(); |
| 121 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 122 | |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 123 | final WindowManagerService mService; |
| 124 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 125 | /** Remove this display when animation on it has completed. */ |
| 126 | boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 127 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 128 | final DockedStackDividerController mDividerControllerLocked; |
| 129 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 130 | final DimLayerController mDimLayerController; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 131 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 132 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
| 133 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 134 | /** Used when rebuilding window list to keep track of windows that have been removed. */ |
| 135 | private WindowState[] mRebuildTmp = new WindowState[20]; |
| 136 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 137 | private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult = |
| 138 | new TaskForResizePointSearchResult(); |
| 139 | private final GetWindowOnDisplaySearchResult mTmpGetWindowOnDisplaySearchResult = |
| 140 | new GetWindowOnDisplaySearchResult(); |
| 141 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 142 | /** |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 143 | * @param display May not be null. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 144 | * @param service You know. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 145 | */ |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 146 | DisplayContent(Display display, WindowManagerService service) { |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 147 | mDisplay = display; |
| 148 | mDisplayId = display.getDisplayId(); |
| 149 | display.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 150 | display.getMetrics(mDisplayMetrics); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 151 | isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY; |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 152 | mService = service; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 153 | initializeDisplayBaseInfo(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 154 | mDividerControllerLocked = new DockedStackDividerController(service, this); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 155 | mDimLayerController = new DimLayerController(this); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | int getDisplayId() { |
| 159 | return mDisplayId; |
| 160 | } |
| 161 | |
| 162 | WindowList getWindowList() { |
| 163 | return mWindows; |
| 164 | } |
| 165 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 166 | Display getDisplay() { |
| 167 | return mDisplay; |
| 168 | } |
| 169 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 170 | DisplayInfo getDisplayInfo() { |
| 171 | return mDisplayInfo; |
| 172 | } |
| 173 | |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 174 | DisplayMetrics getDisplayMetrics() { |
| 175 | return mDisplayMetrics; |
| 176 | } |
| 177 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 178 | DockedStackDividerController getDockedDividerController() { |
| 179 | return mDividerControllerLocked; |
| 180 | } |
| 181 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 182 | /** |
| 183 | * Returns true if the specified UID has access to this display. |
| 184 | */ |
| 185 | public boolean hasAccess(int uid) { |
| 186 | return mDisplay.hasAccess(uid); |
| 187 | } |
| 188 | |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 189 | public boolean isPrivate() { |
| 190 | return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0; |
| 191 | } |
| 192 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 193 | ArrayList<TaskStack> getStacks() { |
| 194 | return mStacks; |
| 195 | } |
| 196 | |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 197 | TaskStack getHomeStack() { |
Craig Mautner | 333c2ec | 2014-10-02 12:24:02 -0700 | [diff] [blame] | 198 | if (mHomeStack == null && mDisplayId == Display.DEFAULT_DISPLAY) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 199 | Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 200 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 201 | return mHomeStack; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 204 | TaskStack getStackById(int stackId) { |
| 205 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 206 | final TaskStack stack = mStacks.get(i); |
| 207 | if (stack.mStackId == stackId) { |
| 208 | return stack; |
| 209 | } |
| 210 | } |
| 211 | return null; |
| 212 | } |
| 213 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 214 | void checkAppWindowsReadyToShow() { |
| 215 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 216 | final TaskStack stack = mStacks.get(i); |
| 217 | stack.checkAppWindowsReadyToShow(mDisplayId); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void updateAllDrawn() { |
| 222 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 223 | final TaskStack stack = mStacks.get(i); |
| 224 | stack.updateAllDrawn(mDisplayId); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | void stepAppWindowsAnimation(long currentTime) { |
| 229 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 230 | final TaskStack stack = mStacks.get(i); |
| 231 | stack.stepAppWindowsAnimation(currentTime, mDisplayId); |
| 232 | } |
| 233 | } |
| 234 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 235 | void onAppTransitionDone() { |
| 236 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 237 | final TaskStack stack = mStacks.get(i); |
| 238 | stack.onAppTransitionDone(); |
| 239 | } |
| 240 | |
| 241 | rebuildAppWindowList(); |
| 242 | } |
| 243 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 244 | int getOrientation() { |
| 245 | // TODO: Most of the logic here can be removed once this class is converted to use |
| 246 | // WindowContainer which has an abstract implementation of getOrientation that |
| 247 | // should cover this. |
| 248 | if (mService.isStackVisibleLocked(DOCKED_STACK_ID) |
| 249 | || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) { |
| 250 | // Apps and their containers are not allowed to specify an orientation while the docked |
| 251 | // or freeform stack is visible...except for the home stack/task if the docked stack is |
| 252 | // minimized and it actually set something. |
Andrii Kulian | 8072d11 | 2016-09-16 11:11:01 -0700 | [diff] [blame] | 253 | if (mHomeStack != null && mHomeStack.isVisible() |
| 254 | && mDividerControllerLocked.isMinimizedDock()) { |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 255 | final int orientation = mHomeStack.getOrientation(); |
| 256 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 257 | return orientation; |
| 258 | } |
| 259 | } |
| 260 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 261 | } |
| 262 | |
| 263 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 264 | final TaskStack stack = mStacks.get(i); |
| 265 | if (!stack.isVisible()) { |
| 266 | continue; |
| 267 | } |
| 268 | |
| 269 | final int orientation = stack.getOrientation(); |
| 270 | |
| 271 | if (orientation == SCREEN_ORIENTATION_BEHIND) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 276 | if (stack.fillsParent() || orientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
| 277 | return orientation; |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 283 | "No app is requesting an orientation, return " + mService.mLastOrientation); |
| 284 | // The next app has not been requested to be visible, so we keep the current orientation |
| 285 | // to prevent freezing/unfreezing the display too early. |
| 286 | return mService.mLastOrientation; |
| 287 | } |
| 288 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 289 | void updateDisplayInfo() { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 290 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 291 | mDisplay.getMetrics(mDisplayMetrics); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 292 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 293 | mStacks.get(i).updateDisplayInfo(null); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 294 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 297 | void initializeDisplayBaseInfo() { |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 298 | final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal; |
| 299 | if (displayManagerInternal != null) { |
| 300 | // Bootstrap the default logical display from the display manager. |
| 301 | final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId); |
| 302 | if (newDisplayInfo != null) { |
| 303 | mDisplayInfo.copyFrom(newDisplayInfo); |
| 304 | } |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 305 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 306 | |
Filip Gruszczynski | 608797e | 2015-11-12 19:08:20 -0800 | [diff] [blame] | 307 | mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 308 | mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 309 | mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
| 310 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 313 | void getLogicalDisplayRect(Rect out) { |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 314 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 315 | final int orientation = mDisplayInfo.rotation; |
| 316 | boolean rotated = (orientation == Surface.ROTATION_90 |
| 317 | || orientation == Surface.ROTATION_270); |
| 318 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 319 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 320 | int width = mDisplayInfo.logicalWidth; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 321 | int left = (physWidth - width) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 322 | int height = mDisplayInfo.logicalHeight; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 323 | int top = (physHeight - height) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 324 | out.set(left, top, left + width, top + height); |
| 325 | } |
| 326 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 327 | void getContentRect(Rect out) { |
| 328 | out.set(mContentRect); |
| 329 | } |
| 330 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 331 | /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */ |
| 332 | void attachStack(TaskStack stack, boolean onTop) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 333 | if (stack.mStackId == HOME_STACK_ID) { |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 334 | if (mHomeStack != null) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 335 | throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first."); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 336 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 337 | mHomeStack = stack; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 338 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 339 | if (onTop) { |
| 340 | mStacks.add(stack); |
| 341 | } else { |
| 342 | mStacks.add(0, stack); |
| 343 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 344 | layoutNeeded = true; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 347 | void moveStack(TaskStack stack, boolean toTop) { |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 348 | if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) { |
| 349 | // This stack is always-on-top silly... |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 350 | Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom"); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 351 | return; |
| 352 | } |
| 353 | |
Filip Gruszczynski | 26ed265 | 2015-08-10 11:02:53 -0700 | [diff] [blame] | 354 | if (!mStacks.remove(stack)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 355 | Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable()); |
Filip Gruszczynski | 26ed265 | 2015-08-10 11:02:53 -0700 | [diff] [blame] | 356 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 357 | |
| 358 | int addIndex = toTop ? mStacks.size() : 0; |
| 359 | |
| 360 | if (toTop |
| 361 | && mService.isStackVisibleLocked(PINNED_STACK_ID) |
| 362 | && stack.mStackId != PINNED_STACK_ID) { |
| 363 | // The pinned stack is always the top most stack (always-on-top) when it is visible. |
| 364 | // So, stack is moved just below the pinned stack. |
| 365 | addIndex--; |
| 366 | TaskStack topStack = mStacks.get(addIndex); |
| 367 | if (topStack.mStackId != PINNED_STACK_ID) { |
| 368 | throw new IllegalStateException("Pinned stack isn't top stack??? " + mStacks); |
| 369 | } |
| 370 | } |
| 371 | mStacks.add(addIndex, stack); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 372 | } |
| 373 | |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 374 | // TODO: Don't forget to switch to WC.removeChild |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 375 | void detachChild(TaskStack stack) { |
| 376 | detachStack(stack); |
| 377 | if (stack.detachFromDisplay()) { |
| 378 | mService.mWindowPlacerLocked.requestTraversal(); |
| 379 | } |
| 380 | if (stack.mStackId == DOCKED_STACK_ID) { |
| 381 | mService.getDefaultDisplayContentLocked().mDividerControllerLocked |
| 382 | .notifyDockedStackExistsChanged(false); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | // TODO: See about removing this by untangling the use case in WMS.attachStack() |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 387 | void detachStack(TaskStack stack) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 388 | mDimLayerController.removeDimLayerUser(stack); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 389 | mStacks.remove(stack); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Propagate the new bounds to all child stacks. |
| 394 | * @param contentRect The bounds to apply at the top level. |
| 395 | */ |
| 396 | void resize(Rect contentRect) { |
| 397 | mContentRect.set(contentRect); |
| 398 | } |
| 399 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 400 | int taskIdFromPoint(int x, int y) { |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 401 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 402 | final TaskStack stack = mStacks.get(stackNdx); |
| 403 | final int taskId = stack.taskIdFromPoint(x, y); |
| 404 | if (taskId != -1) { |
| 405 | return taskId; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 406 | } |
| 407 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 408 | return -1; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 411 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 412 | * 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] | 413 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 414 | */ |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 415 | Task findTaskForResizePoint(int x, int y) { |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 416 | final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 417 | mTmpTaskForResizePointSearchResult.reset(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 418 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 419 | TaskStack stack = mStacks.get(stackNdx); |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 420 | if (!StackId.isTaskResizeAllowed(stack.mStackId)) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 421 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 422 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 423 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 424 | stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult); |
| 425 | if (mTmpTaskForResizePointSearchResult.searchDone) { |
| 426 | return mTmpTaskForResizePointSearchResult.taskForResize; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 429 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 432 | void setTouchExcludeRegion(Task focusedTask) { |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 433 | mTouchExcludeRegion.set(mBaseDisplayRect); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 434 | final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 435 | mTmpRect2.setEmpty(); |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 436 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 437 | final TaskStack stack = mStacks.get(stackNdx); |
| 438 | stack.setTouchExcludeRegion( |
| 439 | focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 440 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 441 | // If we removed the focused task above, add it back and only leave its |
| 442 | // outside touch area in the exclusion. TapDectector is not interested in |
| 443 | // any touch inside the focused task itself. |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 444 | if (!mTmpRect2.isEmpty()) { |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 445 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 446 | } |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 447 | final WindowState inputMethod = mService.mInputMethodWindow; |
| 448 | if (inputMethod != null && inputMethod.isVisibleLw()) { |
| 449 | // If the input method is visible and the user is typing, we don't want these touch |
| 450 | // events to be intercepted and used to change focus. This would likely cause a |
| 451 | // disappearance of the input method. |
| 452 | inputMethod.getTouchableRegion(mTmpRegion); |
| 453 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 454 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 455 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
| 456 | WindowState win = mTapExcludedWindows.get(i); |
| 457 | win.getTouchableRegion(mTmpRegion); |
| 458 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 459 | } |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 460 | if (getDockedStackVisibleForUserLocked() != null) { |
| 461 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 462 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 463 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 464 | } |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 465 | if (mTapDetector != null) { |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 466 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion); |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 467 | } |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 470 | void switchUserStacks() { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 471 | final WindowList windows = getWindowList(); |
| 472 | for (int i = 0; i < windows.size(); i++) { |
| 473 | final WindowState win = windows.get(i); |
| 474 | if (win.isHiddenFromUserLocked()) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 475 | if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 476 | + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 477 | win.hideLw(false); |
| 478 | } |
| 479 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 480 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 481 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 482 | mStacks.get(stackNdx).switchUser(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 483 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 484 | |
| 485 | rebuildAppWindowList(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 488 | void resetAnimationBackgroundAnimator() { |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 489 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 490 | mStacks.get(stackNdx).resetAnimationBackgroundAnimator(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
| 494 | boolean animateDimLayers() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 495 | return mDimLayerController.animateDimLayers(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | void resetDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 499 | mDimLayerController.resetDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | boolean isDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 503 | return mDimLayerController.isDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | void stopDimmingIfNeeded() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 507 | mDimLayerController.stopDimmingIfNeeded(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 510 | void close() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 511 | mDimLayerController.close(); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 512 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 513 | mStacks.get(stackNdx).close(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 517 | boolean isAnimating() { |
| 518 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 519 | final TaskStack stack = mStacks.get(stackNdx); |
| 520 | if (stack.isAnimating()) { |
| 521 | return true; |
| 522 | } |
| 523 | } |
| 524 | return false; |
| 525 | } |
| 526 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 527 | /** Returns true if a removal action is still being deferred. */ |
| 528 | boolean checkCompleteDeferredRemoval() { |
| 529 | boolean stillDeferringRemoval = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 530 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 531 | final TaskStack stack = mStacks.get(stackNdx); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 532 | stillDeferringRemoval |= stack.checkCompleteDeferredRemoval(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 533 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 534 | if (!stillDeferringRemoval && mDeferredRemoval) { |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 535 | mService.onDisplayRemoved(mDisplayId); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 536 | return false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 537 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 538 | return true; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 541 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
| 542 | final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation); |
| 543 | getLogicalDisplayRect(mTmpRect); |
| 544 | switch (rotationDelta) { |
| 545 | case Surface.ROTATION_0: |
| 546 | mTmpRect2.set(bounds); |
| 547 | break; |
| 548 | case Surface.ROTATION_90: |
| 549 | mTmpRect2.top = mTmpRect.bottom - bounds.right; |
| 550 | mTmpRect2.left = bounds.top; |
| 551 | mTmpRect2.right = mTmpRect2.left + bounds.height(); |
| 552 | mTmpRect2.bottom = mTmpRect2.top + bounds.width(); |
| 553 | break; |
| 554 | case Surface.ROTATION_180: |
| 555 | mTmpRect2.top = mTmpRect.bottom - bounds.bottom; |
| 556 | mTmpRect2.left = mTmpRect.right - bounds.right; |
| 557 | mTmpRect2.right = mTmpRect2.left + bounds.width(); |
| 558 | mTmpRect2.bottom = mTmpRect2.top + bounds.height(); |
| 559 | break; |
| 560 | case Surface.ROTATION_270: |
| 561 | mTmpRect2.top = bounds.left; |
| 562 | mTmpRect2.left = mTmpRect.right - bounds.bottom; |
| 563 | mTmpRect2.right = mTmpRect2.left + bounds.height(); |
| 564 | mTmpRect2.bottom = mTmpRect2.top + bounds.width(); |
| 565 | break; |
| 566 | } |
| 567 | bounds.set(mTmpRect2); |
| 568 | } |
| 569 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 570 | static int deltaRotation(int oldRotation, int newRotation) { |
| 571 | int delta = newRotation - oldRotation; |
| 572 | if (delta < 0) delta += 4; |
| 573 | return delta; |
| 574 | } |
| 575 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 576 | public void dump(String prefix, PrintWriter pw) { |
| 577 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 578 | final String subPrefix = " " + prefix; |
| 579 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 580 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 581 | pw.print("dpi"); |
| 582 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 583 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 584 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 585 | pw.print(" base="); |
| 586 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 587 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 588 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 589 | if (mDisplayScalingDisabled) { |
| 590 | pw.println(" noscale"); |
| 591 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 592 | pw.print(" cur="); |
| 593 | pw.print(mDisplayInfo.logicalWidth); |
| 594 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 595 | pw.print(" app="); |
| 596 | pw.print(mDisplayInfo.appWidth); |
| 597 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 598 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 599 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 600 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 601 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 602 | pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval); |
| 603 | pw.print(" layoutNeeded="); pw.println(layoutNeeded); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 604 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 605 | pw.println(); |
Craig Mautner | e8b85fd | 2014-10-22 09:23:25 -0700 | [diff] [blame] | 606 | pw.println(" Application tokens in top down Z order:"); |
Craig Mautner | e8b85fd | 2014-10-22 09:23:25 -0700 | [diff] [blame] | 607 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Craig Mautner | bcb6eb9 | 2015-01-13 13:09:22 -0800 | [diff] [blame] | 608 | final TaskStack stack = mStacks.get(stackNdx); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 609 | stack.dump(prefix + " ", pw); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 610 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 611 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 612 | pw.println(); |
| 613 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 614 | pw.println(); |
| 615 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 616 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 617 | WindowToken token = mExitingTokens.get(i); |
| 618 | pw.print(" Exiting #"); pw.print(i); |
| 619 | pw.print(' '); pw.print(token); |
| 620 | pw.println(':'); |
| 621 | token.dump(pw, " "); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 622 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 623 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 624 | pw.println(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 625 | mDimLayerController.dump(prefix + " ", pw); |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 626 | pw.println(); |
| 627 | mDividerControllerLocked.dump(prefix + " ", pw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 628 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 629 | |
| 630 | @Override |
| 631 | public String toString() { |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 632 | return getName() + " stacks=" + mStacks; |
| 633 | } |
| 634 | |
| 635 | String getName() { |
| 636 | return "Display " + mDisplayId + " info=" + mDisplayInfo; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 637 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 638 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 639 | /** |
| 640 | * @return The docked stack, but only if it is visible, and {@code null} otherwise. |
| 641 | */ |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 642 | TaskStack getDockedStackLocked() { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 643 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 644 | return (stack != null && stack.isVisible()) ? stack : null; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 645 | } |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 646 | |
| 647 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 648 | * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not |
| 649 | * visible, as long as it's not hidden because the current user doesn't have any tasks there. |
| 650 | */ |
| 651 | TaskStack getDockedStackVisibleForUserLocked() { |
| 652 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 653 | return (stack != null && stack.isVisible(true /* ignoreKeyguard */)) ? stack : null; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 656 | /** Find the visible, touch-deliverable window under the given point */ |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 657 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
| 658 | WindowState touchedWin = null; |
| 659 | final int x = (int) xf; |
| 660 | final int y = (int) yf; |
| 661 | |
| 662 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 663 | WindowState window = mWindows.get(i); |
| 664 | final int flags = window.mAttrs.flags; |
| 665 | if (!window.isVisibleLw()) { |
| 666 | continue; |
| 667 | } |
| 668 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
| 669 | continue; |
| 670 | } |
| 671 | |
| 672 | window.getVisibleBounds(mTmpRect); |
| 673 | if (!mTmpRect.contains(x, y)) { |
| 674 | continue; |
| 675 | } |
| 676 | |
| 677 | window.getTouchableRegion(mTmpRegion); |
| 678 | |
| 679 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
| 680 | if (mTmpRegion.contains(x, y) || touchFlags == 0) { |
| 681 | touchedWin = window; |
| 682 | break; |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | return touchedWin; |
| 687 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 688 | |
| 689 | /** |
| 690 | * See {@link WindowManagerService#overridePlayingAppAnimationsLw}. |
| 691 | */ |
| 692 | void overridePlayingAppAnimationsLw(Animation a) { |
| 693 | for (int i = mStacks.size() - 1; i >= 0; i--) { |
| 694 | mStacks.get(i).overridePlayingAppAnimations(a); |
| 695 | } |
| 696 | } |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 697 | |
| 698 | boolean canAddToastWindowForUid(int uid) { |
| 699 | // We allow one toast window per UID being shown at a time. |
| 700 | WindowList windows = getWindowList(); |
| 701 | final int windowCount = windows.size(); |
| 702 | for (int i = 0; i < windowCount; i++) { |
| 703 | WindowState window = windows.get(i); |
| 704 | if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == uid |
| 705 | && !window.mPermanentlyHidden && !window.mAnimatingExit) { |
| 706 | return false; |
| 707 | } |
| 708 | } |
| 709 | return true; |
| 710 | } |
| 711 | |
| 712 | void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, |
| 713 | WindowState newFocus) { |
| 714 | if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) { |
| 715 | return; |
| 716 | } |
| 717 | final int lostFocusUid = oldFocus.mOwnerUid; |
| 718 | WindowList windows = getWindowList(); |
| 719 | final int windowCount = windows.size(); |
| 720 | for (int i = 0; i < windowCount; i++) { |
| 721 | WindowState window = windows.get(i); |
| 722 | if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == lostFocusUid) { |
| 723 | if (!mService.mH.hasMessages(WindowManagerService.H.WINDOW_HIDE_TIMEOUT, window)) { |
| 724 | mService.mH.sendMessageDelayed( |
| 725 | mService.mH.obtainMessage( |
| 726 | WindowManagerService.H.WINDOW_HIDE_TIMEOUT, window), |
| 727 | window.mAttrs.hideTimeoutMilliseconds); |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 732 | |
| 733 | WindowState findFocusedWindow() { |
| 734 | final AppWindowToken focusedApp = mService.mFocusedApp; |
| 735 | |
| 736 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 737 | final WindowState win = mWindows.get(i); |
| 738 | |
| 739 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + i + " = " + win |
| 740 | + ", flags=" + win.mAttrs.flags + ", canReceive=" + win.canReceiveKeys()); |
| 741 | |
| 742 | if (!win.canReceiveKeys()) { |
| 743 | continue; |
| 744 | } |
| 745 | |
| 746 | final AppWindowToken wtoken = win.mAppToken; |
| 747 | |
| 748 | // If this window's application has been removed, just skip it. |
| 749 | if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) { |
| 750 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because " |
| 751 | + (wtoken.removed ? "removed" : "sendingToBottom")); |
| 752 | continue; |
| 753 | } |
| 754 | |
| 755 | if (focusedApp == null) { |
| 756 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null" |
| 757 | + " using new focus @ " + i + " = " + win); |
| 758 | return win; |
| 759 | } |
| 760 | |
| 761 | if (!focusedApp.windowsAreFocusable()) { |
| 762 | // Current focused app windows aren't focusable... |
| 763 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not" |
| 764 | + " focusable using new focus @ " + i + " = " + win); |
| 765 | return win; |
| 766 | } |
| 767 | |
| 768 | // Descend through all of the app tokens and find the first that either matches |
| 769 | // win.mAppToken (return win) or mFocusedApp (return null). |
| 770 | if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 771 | final TaskStack focusedAppStack = focusedApp.mTask.mStack; |
| 772 | final TaskStack appStack = wtoken.mTask.mStack; |
| 773 | |
| 774 | // TODO: Use WindowContainer.compareTo() once everything is using WindowContainer |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame^] | 775 | if ((focusedAppStack == appStack && focusedApp.compareTo(wtoken) > 0) |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 776 | || mStacks.indexOf(focusedAppStack) > mStacks.indexOf(appStack)) { |
| 777 | // App stack below focused app stack. No focus for you!!! |
| 778 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, |
| 779 | "findFocusedWindow: Reached focused app=" + focusedApp); |
| 780 | return null; |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " |
| 785 | + i + " = " + win); |
| 786 | return win; |
| 787 | } |
| 788 | |
| 789 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows."); |
| 790 | return null; |
| 791 | } |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 792 | |
| 793 | int addAppWindowToWindowList(final WindowState win) { |
| 794 | final IWindow client = win.mClient; |
| 795 | |
| 796 | WindowList tokenWindowList = getTokenWindowsOnDisplay(win.mToken); |
| 797 | if (!tokenWindowList.isEmpty()) { |
| 798 | return addAppWindowExisting(win, tokenWindowList); |
| 799 | } |
| 800 | |
| 801 | // No windows from this token on this display |
| 802 | if (mService.localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window " |
| 803 | + client.asBinder() + " (token=" + this + ")"); |
| 804 | |
| 805 | final WindowToken wToken = win.mToken; |
| 806 | |
| 807 | // 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] | 808 | mTmpGetWindowOnDisplaySearchResult.reset(); |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 809 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 810 | final TaskStack stack = mStacks.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 811 | stack.getWindowOnDisplayBeforeToken(this, wToken, mTmpGetWindowOnDisplaySearchResult); |
| 812 | if (mTmpGetWindowOnDisplaySearchResult.reachedToken) { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 813 | // We have reach the token we are interested in. End search. |
| 814 | break; |
| 815 | } |
| 816 | } |
| 817 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 818 | WindowState pos = mTmpGetWindowOnDisplaySearchResult.foundWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 819 | |
| 820 | // We now know the index into the apps. If we found an app window above, that gives us the |
| 821 | // position; else we need to look some more. |
| 822 | if (pos != null) { |
| 823 | // Move behind any windows attached to this one. |
| 824 | final WindowToken atoken = mService.mTokenMap.get(pos.mClient.asBinder()); |
| 825 | if (atoken != null) { |
| 826 | tokenWindowList = getTokenWindowsOnDisplay(atoken); |
| 827 | final int NC = tokenWindowList.size(); |
| 828 | if (NC > 0) { |
| 829 | WindowState bottom = tokenWindowList.get(0); |
| 830 | if (bottom.mSubLayer < 0) { |
| 831 | pos = bottom; |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | addWindowToListBefore(win, pos); |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | // 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] | 840 | mTmpGetWindowOnDisplaySearchResult.reset(); |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 841 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
| 842 | final TaskStack stack = mStacks.get(i); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 843 | stack.getWindowOnDisplayAfterToken(this, wToken, mTmpGetWindowOnDisplaySearchResult); |
| 844 | if (mTmpGetWindowOnDisplaySearchResult.foundWindow != null) { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 845 | // We have found a window after the token. End search. |
| 846 | break; |
| 847 | } |
| 848 | } |
| 849 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 850 | pos = mTmpGetWindowOnDisplaySearchResult.foundWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 851 | |
| 852 | if (pos != null) { |
| 853 | // Move in front of any windows attached to this one. |
| 854 | final WindowToken atoken = mService.mTokenMap.get(pos.mClient.asBinder()); |
| 855 | if (atoken != null) { |
| 856 | final WindowState top = atoken.getTopWindow(); |
| 857 | if (top != null && top.mSubLayer >= 0) { |
| 858 | pos = top; |
| 859 | } |
| 860 | } |
| 861 | addWindowToListAfter(win, pos); |
| 862 | return 0; |
| 863 | } |
| 864 | |
| 865 | // Just search for the start of this layer. |
| 866 | final int myLayer = win.mBaseLayer; |
| 867 | int i; |
| 868 | for (i = mWindows.size() - 1; i >= 0; --i) { |
| 869 | final WindowState w = mWindows.get(i); |
| 870 | // Dock divider shares the base layer with application windows, but we want to always |
| 871 | // keep it above the application windows. The sharing of the base layer is intended |
| 872 | // for window animations, which need to be above the dock divider for the duration |
| 873 | // of the animation. |
| 874 | if (w.mBaseLayer <= myLayer && w.mAttrs.type != TYPE_DOCK_DIVIDER) { |
| 875 | break; |
| 876 | } |
| 877 | } |
| 878 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 879 | "Based on layer: Adding window " + win + " at " + (i + 1) + " of " |
| 880 | + mWindows.size()); |
| 881 | mWindows.add(i + 1, win); |
| 882 | mService.mWindowsChanged = true; |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | /** Adds this non-app window to the window list. */ |
| 887 | void addNonAppWindowToWindowList(WindowState win) { |
| 888 | // Figure out where window should go, based on layer. |
| 889 | int i; |
| 890 | for (i = mWindows.size() - 1; i >= 0; i--) { |
| 891 | final WindowState otherWin = mWindows.get(i); |
| 892 | if (otherWin.getBaseType() != TYPE_WALLPAPER && otherWin.mBaseLayer <= win.mBaseLayer) { |
| 893 | // Wallpaper wanders through the window list, for example to position itself |
| 894 | // directly behind keyguard. Because of this it will break the ordering based on |
| 895 | // WindowState.mBaseLayer. There might windows with higher mBaseLayer behind it and |
| 896 | // we don't want the new window to appear above them. An example of this is adding |
| 897 | // of the docked stack divider. Consider a scenario with the following ordering (top |
| 898 | // to bottom): keyguard, wallpaper, assist preview, apps. We want the dock divider |
| 899 | // to land below the assist preview, so the dock divider must ignore the wallpaper, |
| 900 | // with which it shares the base layer. |
| 901 | break; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | i++; |
| 906 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 907 | "Free window: Adding window " + this + " at " + i + " of " + mWindows.size()); |
| 908 | mWindows.add(i, win); |
| 909 | mService.mWindowsChanged = true; |
| 910 | } |
| 911 | |
| 912 | void addChildWindowToWindowList(WindowState win) { |
| 913 | final WindowState parentWindow = win.getParentWindow(); |
| 914 | |
| 915 | WindowList windowsOnSameDisplay = getTokenWindowsOnDisplay(win.mToken); |
| 916 | |
| 917 | // Figure out this window's ordering relative to the parent window. |
| 918 | final int wCount = windowsOnSameDisplay.size(); |
| 919 | final int sublayer = win.mSubLayer; |
| 920 | int largestSublayer = Integer.MIN_VALUE; |
| 921 | WindowState windowWithLargestSublayer = null; |
| 922 | int i; |
| 923 | for (i = 0; i < wCount; i++) { |
| 924 | WindowState w = windowsOnSameDisplay.get(i); |
| 925 | final int wSublayer = w.mSubLayer; |
| 926 | if (wSublayer >= largestSublayer) { |
| 927 | largestSublayer = wSublayer; |
| 928 | windowWithLargestSublayer = w; |
| 929 | } |
| 930 | if (sublayer < 0) { |
| 931 | // For negative sublayers, we go below all windows in the same sublayer. |
| 932 | if (wSublayer >= sublayer) { |
| 933 | addWindowToListBefore(win, wSublayer >= 0 ? parentWindow : w); |
| 934 | break; |
| 935 | } |
| 936 | } else { |
| 937 | // For positive sublayers, we go above all windows in the same sublayer. |
| 938 | if (wSublayer > sublayer) { |
| 939 | addWindowToListBefore(win, w); |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | if (i >= wCount) { |
| 945 | if (sublayer < 0) { |
| 946 | addWindowToListBefore(win, parentWindow); |
| 947 | } else { |
| 948 | addWindowToListAfter(win, |
| 949 | largestSublayer >= 0 ? windowWithLargestSublayer : parentWindow); |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 954 | /** |
| 955 | * Z-orders the display window list so that: |
| 956 | * <ul> |
| 957 | * <li>Any windows that are currently below the wallpaper window stay below the wallpaper |
| 958 | * window. |
| 959 | * <li>Exiting application windows are at the bottom, but above the wallpaper window. |
| 960 | * <li>All other application windows are above the exiting application windows and ordered based |
| 961 | * on the ordering of their stacks and tasks on the display. |
| 962 | * <li>Non-application windows are at the very top. |
| 963 | * </ul> |
| 964 | * <p> |
| 965 | * NOTE: This isn't a complete picture of what the user see. Further manipulation of the window |
| 966 | * surface layering is done in {@link WindowLayersController}. |
| 967 | */ |
| 968 | void rebuildAppWindowList() { |
| 969 | int count = mWindows.size(); |
| 970 | int i; |
| 971 | int lastBelow = -1; |
| 972 | int numRemoved = 0; |
| 973 | |
| 974 | if (mRebuildTmp.length < count) { |
| 975 | mRebuildTmp = new WindowState[count + 10]; |
| 976 | } |
| 977 | |
| 978 | // First remove all existing app windows. |
| 979 | i = 0; |
| 980 | while (i < count) { |
| 981 | final WindowState w = mWindows.get(i); |
| 982 | if (w.mAppToken != null) { |
| 983 | final WindowState win = mWindows.remove(i); |
| 984 | win.mRebuilding = true; |
| 985 | mRebuildTmp[numRemoved] = win; |
| 986 | mService.mWindowsChanged = true; |
| 987 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Rebuild removing window: " + win); |
| 988 | count--; |
| 989 | numRemoved++; |
| 990 | continue; |
| 991 | } else if (lastBelow == i-1) { |
| 992 | if (w.mAttrs.type == TYPE_WALLPAPER) { |
| 993 | lastBelow = i; |
| 994 | } |
| 995 | } |
| 996 | i++; |
| 997 | } |
| 998 | |
| 999 | // Keep whatever windows were below the app windows still below, by skipping them. |
| 1000 | lastBelow++; |
| 1001 | i = lastBelow; |
| 1002 | |
| 1003 | // First add all of the exiting app tokens... these are no longer in the main app list, |
| 1004 | // but still have windows shown. We put them in the back because now that the animation is |
| 1005 | // over we no longer will care about them. |
| 1006 | final int numStacks = mStacks.size(); |
| 1007 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 1008 | AppTokenList exitingAppTokens = mStacks.get(stackNdx).mExitingAppTokens; |
| 1009 | int NT = exitingAppTokens.size(); |
| 1010 | for (int j = 0; j < NT; j++) { |
| 1011 | i = exitingAppTokens.get(j).rebuildWindowList(this, i); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | // And add in the still active app tokens in Z order. |
| 1016 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 1017 | i = mStacks.get(stackNdx).rebuildWindowList(this, i); |
| 1018 | } |
| 1019 | |
| 1020 | i -= lastBelow; |
| 1021 | if (i != numRemoved) { |
| 1022 | layoutNeeded = true; |
| 1023 | Slog.w(TAG_WM, "On display=" + mDisplayId + " Rebuild removed " + numRemoved |
| 1024 | + " windows but added " + i + " rebuildAppWindowListLocked() " |
| 1025 | + " callers=" + Debug.getCallers(10)); |
| 1026 | for (i = 0; i < numRemoved; i++) { |
| 1027 | WindowState ws = mRebuildTmp[i]; |
| 1028 | if (ws.mRebuilding) { |
| 1029 | StringWriter sw = new StringWriter(); |
| 1030 | PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 1031 | ws.dump(pw, "", true); |
| 1032 | pw.flush(); |
| 1033 | Slog.w(TAG_WM, "This window was lost: " + ws); |
| 1034 | Slog.w(TAG_WM, sw.toString()); |
| 1035 | ws.mWinAnimator.destroySurfaceLocked(); |
| 1036 | } |
| 1037 | } |
| 1038 | Slog.w(TAG_WM, "Current app token list:"); |
| 1039 | dumpChildrenNames(); |
| 1040 | Slog.w(TAG_WM, "Final window list:"); |
| 1041 | dumpWindows(); |
| 1042 | } |
| 1043 | Arrays.fill(mRebuildTmp, null); |
| 1044 | } |
| 1045 | |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1046 | /** Return the list of Windows on this display associated with the input token. */ |
| 1047 | WindowList getTokenWindowsOnDisplay(WindowToken token) { |
| 1048 | final WindowList windowList = new WindowList(); |
| 1049 | final int count = mWindows.size(); |
| 1050 | for (int i = 0; i < count; i++) { |
| 1051 | final WindowState win = mWindows.get(i); |
| 1052 | if (win.mToken == token) { |
| 1053 | windowList.add(win); |
| 1054 | } |
| 1055 | } |
| 1056 | return windowList; |
| 1057 | } |
| 1058 | |
| 1059 | private int addAppWindowExisting(WindowState win, WindowList tokenWindowList) { |
| 1060 | |
| 1061 | int tokenWindowsPos; |
| 1062 | // If this application has existing windows, we simply place the new window on top of |
| 1063 | // them... but keep the starting window on top. |
| 1064 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1065 | // Base windows go behind everything else. |
| 1066 | final WindowState lowestWindow = tokenWindowList.get(0); |
| 1067 | addWindowToListBefore(win, lowestWindow); |
| 1068 | tokenWindowsPos = win.mToken.getWindowIndex(lowestWindow); |
| 1069 | } else { |
| 1070 | final AppWindowToken atoken = win.mAppToken; |
| 1071 | final int windowListPos = tokenWindowList.size(); |
| 1072 | final WindowState lastWindow = tokenWindowList.get(windowListPos - 1); |
| 1073 | if (atoken != null && lastWindow == atoken.startingWindow) { |
| 1074 | addWindowToListBefore(win, lastWindow); |
| 1075 | tokenWindowsPos = win.mToken.getWindowIndex(lastWindow); |
| 1076 | } else { |
| 1077 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1078 | // There is a window above this one associated with the same apptoken note that the |
| 1079 | // window could be a floating window that was created later or a window at the top |
| 1080 | // of the list of windows associated with this token. |
| 1081 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1082 | "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of " |
| 1083 | + mWindows.size()); |
| 1084 | mWindows.add(newIdx + 1, win); |
| 1085 | if (newIdx < 0) { |
| 1086 | // No window from token found on win's display. |
| 1087 | tokenWindowsPos = 0; |
| 1088 | } else { |
| 1089 | tokenWindowsPos = win.mToken.getWindowIndex(mWindows.get(newIdx)) + 1; |
| 1090 | } |
| 1091 | mService.mWindowsChanged = true; |
| 1092 | } |
| 1093 | } |
| 1094 | return tokenWindowsPos; |
| 1095 | } |
| 1096 | |
| 1097 | /** Places the first input window after the second input window in the window list. */ |
| 1098 | private void addWindowToListAfter(WindowState first, WindowState second) { |
| 1099 | final int i = mWindows.indexOf(second); |
| 1100 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1101 | "Adding window " + this + " at " + (i + 1) + " of " + mWindows.size() |
| 1102 | + " (after " + second + ")"); |
| 1103 | mWindows.add(i + 1, first); |
| 1104 | mService.mWindowsChanged = true; |
| 1105 | } |
| 1106 | |
| 1107 | /** Places the first input window before the second input window in the window list. */ |
| 1108 | private void addWindowToListBefore(WindowState first, WindowState second) { |
| 1109 | int i = mWindows.indexOf(second); |
| 1110 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1111 | "Adding window " + this + " at " + i + " of " + mWindows.size() |
| 1112 | + " (before " + second + ")"); |
| 1113 | if (i < 0) { |
| 1114 | Slog.w(TAG_WM, "addWindowToListBefore: Unable to find " + second + " in " + mWindows); |
| 1115 | i = 0; |
| 1116 | } |
| 1117 | mWindows.add(i, first); |
| 1118 | mService.mWindowsChanged = true; |
| 1119 | } |
| 1120 | |
| 1121 | /** |
| 1122 | * This method finds out the index of a window that has the same app token as win. used for z |
| 1123 | * ordering the windows in mWindows |
| 1124 | */ |
| 1125 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1126 | for(int j = mWindows.size() - 1; j >= 0; j--) { |
| 1127 | final WindowState wentry = mWindows.get(j); |
| 1128 | if(wentry.mAppToken == win.mAppToken) { |
| 1129 | return j; |
| 1130 | } |
| 1131 | } |
| 1132 | return -1; |
| 1133 | } |
| 1134 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1135 | private void dumpChildrenNames() { |
| 1136 | StringWriter sw = new StringWriter(); |
| 1137 | PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 1138 | dumpChildrenNames(pw, " "); |
| 1139 | } |
| 1140 | |
| 1141 | private void dumpChildrenNames(PrintWriter pw, String prefix) { |
| 1142 | final String childPrefix = prefix + prefix; |
| 1143 | for (int j = mStacks.size() - 1; j >= 0; j--) { |
| 1144 | final TaskStack stack = mStacks.get(j); |
| 1145 | pw.println("#" + j + " " + getName()); |
| 1146 | stack.dumpChildrenNames(pw, childPrefix); |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | private void dumpWindows() { |
| 1151 | final int numDisplays = mService.mDisplayContents.size(); |
| 1152 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 1153 | final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx); |
| 1154 | Slog.v(TAG_WM, " Display #" + displayContent.getDisplayId()); |
| 1155 | final WindowList windows = displayContent.getWindowList(); |
| 1156 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 1157 | Slog.v(TAG_WM, " #" + winNdx + ": " + windows.get(winNdx)); |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1162 | static final class GetWindowOnDisplaySearchResult { |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 1163 | boolean reachedToken; |
| 1164 | WindowState foundWindow; |
| 1165 | |
| 1166 | void reset() { |
| 1167 | reachedToken = false; |
| 1168 | foundWindow = null; |
| 1169 | } |
| 1170 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1171 | |
| 1172 | static final class TaskForResizePointSearchResult { |
| 1173 | boolean searchDone; |
| 1174 | Task taskForResize; |
| 1175 | |
| 1176 | void reset() { |
| 1177 | searchDone = false; |
| 1178 | taskForResize = null; |
| 1179 | } |
| 1180 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1181 | } |