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