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; |
| 20 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
| 21 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 23 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 24 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 25 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 27 | import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 28 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 29 | import android.app.ActivityManager.StackId; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 30 | import android.graphics.Rect; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 31 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 32 | import android.graphics.Region.Op; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 33 | import android.util.DisplayMetrics; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 34 | import android.util.Slog; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 35 | import android.view.Display; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 36 | import android.view.DisplayInfo; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 37 | import android.view.Surface; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 38 | |
| 39 | import java.io.PrintWriter; |
| 40 | import java.util.ArrayList; |
| 41 | |
| 42 | class DisplayContentList extends ArrayList<DisplayContent> { |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 47 | * particular Display. |
| 48 | * |
| 49 | * IMPORTANT: No method from this class should ever be used without holding |
| 50 | * WindowManagerService.mWindowMap. |
| 51 | */ |
| 52 | class DisplayContent { |
| 53 | |
| 54 | /** Unique identifier of this stack. */ |
| 55 | private final int mDisplayId; |
| 56 | |
| 57 | /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element |
| 58 | * from mDisplayWindows; */ |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 59 | private final WindowList mWindows = new WindowList(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 60 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 61 | int mInitialDisplayWidth = 0; |
| 62 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 63 | int mInitialDisplayDensity = 0; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 64 | int mBaseDisplayWidth = 0; |
| 65 | int mBaseDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 66 | int mBaseDisplayDensity = 0; |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 67 | boolean mDisplayScalingDisabled; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 68 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 69 | private final Display mDisplay; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 70 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 71 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 72 | Rect mBaseDisplayRect = new Rect(); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 73 | Rect mContentRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 74 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 75 | // Accessed directly by all users. |
| 76 | boolean layoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 77 | int pendingLayoutChanges; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 78 | final boolean isDefaultDisplay; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 79 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 80 | /** 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] | 81 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 82 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 83 | /** Array containing all TaskStacks on this display. Array |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 84 | * is stored in display order with the current bottom stack at 0. */ |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 85 | private final ArrayList<TaskStack> mStacks = new ArrayList<>(); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 86 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 87 | /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack |
| 88 | * (except a future lockscreen TaskStack) moves to the top. */ |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 89 | private TaskStack mHomeStack = null; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 90 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 91 | /** Detect user tapping outside of current focused task bounds .*/ |
| 92 | TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 93 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 94 | /** Detect user tapping outside of current focused stack bounds .*/ |
| 95 | Region mTouchExcludeRegion = new Region(); |
| 96 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 97 | /** Detect user tapping in a non-resizeable task in docked or fullscreen stack .*/ |
| 98 | Region mNonResizeableRegion = new Region(); |
| 99 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 100 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 101 | private final Rect mTmpRect = new Rect(); |
| 102 | private final Rect mTmpRect2 = new Rect(); |
| 103 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 104 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 105 | /** For gathering Task objects in order. */ |
| 106 | final ArrayList<Task> mTmpTaskHistory = new ArrayList<Task>(); |
| 107 | |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 108 | final WindowManagerService mService; |
| 109 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 110 | /** Remove this display when animation on it has completed. */ |
| 111 | boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 112 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 113 | final DockedStackDividerController mDividerControllerLocked; |
| 114 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 115 | final DimLayerController mDimLayerController; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 116 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 117 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
| 118 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 119 | /** |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 120 | * @param display May not be null. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 121 | * @param service You know. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 122 | */ |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 123 | DisplayContent(Display display, WindowManagerService service) { |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 124 | mDisplay = display; |
| 125 | mDisplayId = display.getDisplayId(); |
| 126 | display.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 127 | display.getMetrics(mDisplayMetrics); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 128 | isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY; |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 129 | mService = service; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 130 | initializeDisplayBaseInfo(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 131 | mDividerControllerLocked = new DockedStackDividerController(service, this); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 132 | mDimLayerController = new DimLayerController(this); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | int getDisplayId() { |
| 136 | return mDisplayId; |
| 137 | } |
| 138 | |
| 139 | WindowList getWindowList() { |
| 140 | return mWindows; |
| 141 | } |
| 142 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 143 | Display getDisplay() { |
| 144 | return mDisplay; |
| 145 | } |
| 146 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 147 | DisplayInfo getDisplayInfo() { |
| 148 | return mDisplayInfo; |
| 149 | } |
| 150 | |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 151 | DisplayMetrics getDisplayMetrics() { |
| 152 | return mDisplayMetrics; |
| 153 | } |
| 154 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 155 | DockedStackDividerController getDockedDividerController() { |
| 156 | return mDividerControllerLocked; |
| 157 | } |
| 158 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Returns true if the specified UID has access to this display. |
| 161 | */ |
| 162 | public boolean hasAccess(int uid) { |
| 163 | return mDisplay.hasAccess(uid); |
| 164 | } |
| 165 | |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 166 | public boolean isPrivate() { |
| 167 | return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0; |
| 168 | } |
| 169 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 170 | ArrayList<TaskStack> getStacks() { |
| 171 | return mStacks; |
| 172 | } |
| 173 | |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 174 | /** |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 175 | * Retrieve the tasks on this display in stack order from the bottommost TaskStack up. |
Craig Mautner | 00af9fe | 2013-03-25 09:13:41 -0700 | [diff] [blame] | 176 | * @return All the Tasks, in order, on this display. |
| 177 | */ |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 178 | ArrayList<Task> getTasks() { |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 179 | mTmpTaskHistory.clear(); |
| 180 | final int numStacks = mStacks.size(); |
| 181 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 182 | mTmpTaskHistory.addAll(mStacks.get(stackNdx).getTasks()); |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 183 | } |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 184 | return mTmpTaskHistory; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 187 | TaskStack getHomeStack() { |
Craig Mautner | 333c2ec | 2014-10-02 12:24:02 -0700 | [diff] [blame] | 188 | if (mHomeStack == null && mDisplayId == Display.DEFAULT_DISPLAY) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 189 | Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 190 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 191 | return mHomeStack; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 194 | void updateDisplayInfo() { |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 195 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 196 | mDisplay.getMetrics(mDisplayMetrics); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 197 | for (int i = mStacks.size() - 1; i >= 0; --i) { |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 198 | mStacks.get(i).updateDisplayInfo(null); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 199 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 202 | void initializeDisplayBaseInfo() { |
Filip Gruszczynski | 608797e | 2015-11-12 19:08:20 -0800 | [diff] [blame] | 203 | // Bootstrap the default logical display from the display manager. |
| 204 | final DisplayInfo newDisplayInfo = |
| 205 | mService.mDisplayManagerInternal.getDisplayInfo(mDisplayId); |
| 206 | if (newDisplayInfo != null) { |
| 207 | mDisplayInfo.copyFrom(newDisplayInfo); |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 208 | } |
Filip Gruszczynski | 608797e | 2015-11-12 19:08:20 -0800 | [diff] [blame] | 209 | mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 210 | mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 211 | mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
| 212 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 215 | void getLogicalDisplayRect(Rect out) { |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 216 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 217 | final int orientation = mDisplayInfo.rotation; |
| 218 | boolean rotated = (orientation == Surface.ROTATION_90 |
| 219 | || orientation == Surface.ROTATION_270); |
| 220 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 221 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 222 | int width = mDisplayInfo.logicalWidth; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 223 | int left = (physWidth - width) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 224 | int height = mDisplayInfo.logicalHeight; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 225 | int top = (physHeight - height) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 226 | out.set(left, top, left + width, top + height); |
| 227 | } |
| 228 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 229 | void getContentRect(Rect out) { |
| 230 | out.set(mContentRect); |
| 231 | } |
| 232 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 233 | /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */ |
| 234 | void attachStack(TaskStack stack, boolean onTop) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 235 | if (stack.mStackId == HOME_STACK_ID) { |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 236 | if (mHomeStack != null) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 237 | throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first."); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 238 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 239 | mHomeStack = stack; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 240 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 241 | if (onTop) { |
| 242 | mStacks.add(stack); |
| 243 | } else { |
| 244 | mStacks.add(0, stack); |
| 245 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 246 | layoutNeeded = true; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 249 | void moveStack(TaskStack stack, boolean toTop) { |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 250 | if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) { |
| 251 | // This stack is always-on-top silly... |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 252 | 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] | 253 | return; |
| 254 | } |
| 255 | |
Filip Gruszczynski | 26ed265 | 2015-08-10 11:02:53 -0700 | [diff] [blame] | 256 | if (!mStacks.remove(stack)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 257 | 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] | 258 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 259 | |
| 260 | int addIndex = toTop ? mStacks.size() : 0; |
| 261 | |
| 262 | if (toTop |
| 263 | && mService.isStackVisibleLocked(PINNED_STACK_ID) |
| 264 | && stack.mStackId != PINNED_STACK_ID) { |
| 265 | // The pinned stack is always the top most stack (always-on-top) when it is visible. |
| 266 | // So, stack is moved just below the pinned stack. |
| 267 | addIndex--; |
| 268 | TaskStack topStack = mStacks.get(addIndex); |
| 269 | if (topStack.mStackId != PINNED_STACK_ID) { |
| 270 | throw new IllegalStateException("Pinned stack isn't top stack??? " + mStacks); |
| 271 | } |
| 272 | } |
| 273 | mStacks.add(addIndex, stack); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 276 | void detachStack(TaskStack stack) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 277 | mDimLayerController.removeDimLayerUser(stack); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 278 | mStacks.remove(stack); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Propagate the new bounds to all child stacks. |
| 283 | * @param contentRect The bounds to apply at the top level. |
| 284 | */ |
| 285 | void resize(Rect contentRect) { |
| 286 | mContentRect.set(contentRect); |
| 287 | } |
| 288 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 289 | int taskIdFromPoint(int x, int y) { |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 290 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 291 | TaskStack stack = mStacks.get(stackNdx); |
| 292 | stack.getBounds(mTmpRect); |
Jorim Jaggi | b72c9ad | 2016-04-11 18:27:58 -0700 | [diff] [blame] | 293 | if (!mTmpRect.contains(x, y) || stack.isAdjustedForMinimizedDockedStack()) { |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 294 | continue; |
| 295 | } |
| 296 | final ArrayList<Task> tasks = stack.getTasks(); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 297 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 298 | final Task task = tasks.get(taskNdx); |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 299 | final WindowState win = task.getTopVisibleAppMainWindow(); |
| 300 | if (win == null) { |
| 301 | continue; |
| 302 | } |
| 303 | // We need to use the task's dim bounds (which is derived from the visible |
| 304 | // bounds of its apps windows) for any touch-related tests. Can't use |
| 305 | // the task's original bounds because it might be adjusted to fit the |
| 306 | // content frame. For example, the presence of the IME adjusting the |
Wale Ogunwale | 12cbd92 | 2015-10-06 11:08:28 -0700 | [diff] [blame] | 307 | // windows frames when the app window is the IME target. |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 308 | task.getDimBounds(mTmpRect); |
| 309 | if (mTmpRect.contains(x, y)) { |
| 310 | return task.mTaskId; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 311 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 314 | return -1; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 317 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 318 | * 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] | 319 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 320 | */ |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 321 | Task findTaskForControlPoint(int x, int y) { |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 322 | final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 323 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 324 | TaskStack stack = mStacks.get(stackNdx); |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 325 | if (!StackId.isTaskResizeAllowed(stack.mStackId)) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 326 | break; |
| 327 | } |
| 328 | final ArrayList<Task> tasks = stack.getTasks(); |
| 329 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 330 | final Task task = tasks.get(taskNdx); |
| 331 | if (task.isFullscreen()) { |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 332 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 333 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 334 | |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 335 | // We need to use the task's dim bounds (which is derived from the visible |
| 336 | // bounds of its apps windows) for any touch-related tests. Can't use |
| 337 | // the task's original bounds because it might be adjusted to fit the |
| 338 | // content frame. One example is when the task is put to top-left quadrant, |
| 339 | // the actual visible area would not start at (0,0) after it's adjusted |
| 340 | // for the status bar. |
| 341 | task.getDimBounds(mTmpRect); |
| 342 | mTmpRect.inset(-delta, -delta); |
| 343 | if (mTmpRect.contains(x, y)) { |
| 344 | mTmpRect.inset(delta, delta); |
| 345 | if (!mTmpRect.contains(x, y)) { |
| 346 | return task; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 347 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 348 | // User touched inside the task. No need to look further, |
| 349 | // focus transfer will be handled in ACTION_UP. |
| 350 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 354 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 357 | void setTouchExcludeRegion(Task focusedTask) { |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 358 | mTouchExcludeRegion.set(mBaseDisplayRect); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 359 | final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 360 | boolean addBackFocusedTask = false; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 361 | mNonResizeableRegion.setEmpty(); |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 362 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 363 | TaskStack stack = mStacks.get(stackNdx); |
| 364 | final ArrayList<Task> tasks = stack.getTasks(); |
| 365 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 366 | final Task task = tasks.get(taskNdx); |
Robert Carr | 9e76d32 | 2016-04-22 12:37:57 -0700 | [diff] [blame] | 367 | AppWindowToken token = task.getTopVisibleAppToken(); |
| 368 | if (token == null || !token.isVisible()) { |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 369 | continue; |
| 370 | } |
| 371 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 372 | /** |
| 373 | * Exclusion region is the region that TapDetector doesn't care about. |
| 374 | * Here we want to remove all non-focused tasks from the exclusion region. |
| 375 | * We also remove the outside touch area for resizing for all freeform |
| 376 | * tasks (including the focused). |
| 377 | * |
Robert Carr | 9e76d32 | 2016-04-22 12:37:57 -0700 | [diff] [blame] | 378 | * We save the focused task region once we find it, and add it back at the end. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 379 | */ |
Robert Carr | 9e76d32 | 2016-04-22 12:37:57 -0700 | [diff] [blame] | 380 | |
Wale Ogunwale | e4dd964 | 2016-05-10 08:39:01 -0700 | [diff] [blame^] | 381 | task.getDimBounds(mTmpRect); |
| 382 | |
Robert Carr | 9e76d32 | 2016-04-22 12:37:57 -0700 | [diff] [blame] | 383 | if (task == focusedTask) { |
| 384 | addBackFocusedTask = true; |
| 385 | mTmpRect2.set(mTmpRect); |
| 386 | } |
| 387 | |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 388 | final boolean isFreeformed = task.inFreeformWorkspace(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 389 | if (task != focusedTask || isFreeformed) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 390 | if (isFreeformed) { |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 391 | // If the task is freeformed, enlarge the area to account for outside |
| 392 | // touch area for resize. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 393 | mTmpRect.inset(-delta, -delta); |
Chong Zhang | 73c3fcf | 2015-11-05 13:18:33 -0800 | [diff] [blame] | 394 | // Intersect with display content rect. If we have system decor (status bar/ |
| 395 | // navigation bar), we want to exclude that from the tap detection. |
| 396 | // Otherwise, if the app is partially placed under some system button (eg. |
| 397 | // Recents, Home), pressing that button would cause a full series of |
| 398 | // unwanted transfer focus/resume/pause, before we could go home. |
| 399 | mTmpRect.intersect(mContentRect); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 400 | } |
| 401 | mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE); |
| 402 | } |
Chong Zhang | 2a88fc3 | 2016-01-11 17:14:24 -0800 | [diff] [blame] | 403 | if (task.isTwoFingerScrollMode()) { |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 404 | stack.getBounds(mTmpRect); |
| 405 | mNonResizeableRegion.op(mTmpRect, Region.Op.UNION); |
| 406 | break; |
| 407 | } |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 410 | // If we removed the focused task above, add it back and only leave its |
| 411 | // outside touch area in the exclusion. TapDectector is not interested in |
| 412 | // any touch inside the focused task itself. |
| 413 | if (addBackFocusedTask) { |
| 414 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 415 | } |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 416 | final WindowState inputMethod = mService.mInputMethodWindow; |
| 417 | if (inputMethod != null && inputMethod.isVisibleLw()) { |
| 418 | // If the input method is visible and the user is typing, we don't want these touch |
| 419 | // events to be intercepted and used to change focus. This would likely cause a |
| 420 | // disappearance of the input method. |
| 421 | inputMethod.getTouchableRegion(mTmpRegion); |
| 422 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 423 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 424 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
| 425 | WindowState win = mTapExcludedWindows.get(i); |
| 426 | win.getTouchableRegion(mTmpRegion); |
| 427 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 428 | } |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 429 | if (getDockedStackVisibleForUserLocked() != null) { |
| 430 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 431 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 432 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 433 | } |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 434 | if (mTapDetector != null) { |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 435 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion, mNonResizeableRegion); |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 436 | } |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 439 | void switchUserStacks() { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 440 | final WindowList windows = getWindowList(); |
| 441 | for (int i = 0; i < windows.size(); i++) { |
| 442 | final WindowState win = windows.get(i); |
| 443 | if (win.isHiddenFromUserLocked()) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 444 | if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 445 | + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 446 | win.hideLw(false); |
| 447 | } |
| 448 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 449 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 450 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Wale Ogunwale | 498e8c9 | 2015-02-13 09:42:46 -0800 | [diff] [blame] | 451 | mStacks.get(stackNdx).switchUser(); |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 455 | void resetAnimationBackgroundAnimator() { |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 456 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 457 | mStacks.get(stackNdx).resetAnimationBackgroundAnimator(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | |
| 461 | boolean animateDimLayers() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 462 | return mDimLayerController.animateDimLayers(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | void resetDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 466 | mDimLayerController.resetDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | boolean isDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 470 | return mDimLayerController.isDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | void stopDimmingIfNeeded() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 474 | mDimLayerController.stopDimmingIfNeeded(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 477 | void close() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 478 | mDimLayerController.close(); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 479 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 480 | mStacks.get(stackNdx).close(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 484 | boolean isAnimating() { |
| 485 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 486 | final TaskStack stack = mStacks.get(stackNdx); |
| 487 | if (stack.isAnimating()) { |
| 488 | return true; |
| 489 | } |
| 490 | } |
| 491 | return false; |
| 492 | } |
| 493 | |
| 494 | void checkForDeferredActions() { |
| 495 | boolean animating = false; |
| 496 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 497 | final TaskStack stack = mStacks.get(stackNdx); |
| 498 | if (stack.isAnimating()) { |
| 499 | animating = true; |
| 500 | } else { |
| 501 | if (stack.mDeferDetach) { |
| 502 | mService.detachStackLocked(this, stack); |
| 503 | } |
| 504 | final ArrayList<Task> tasks = stack.getTasks(); |
| 505 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 506 | final Task task = tasks.get(taskNdx); |
| 507 | AppTokenList tokens = task.mAppTokens; |
| 508 | for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 509 | AppWindowToken wtoken = tokens.get(tokenNdx); |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 510 | if (wtoken.mIsExiting) { |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 511 | wtoken.removeAppFromTaskLocked(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 512 | } |
| 513 | } |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | } |
| 517 | if (!animating && mDeferredRemoval) { |
| 518 | mService.onDisplayRemoved(mDisplayId); |
| 519 | } |
| 520 | } |
| 521 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 522 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
| 523 | final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation); |
| 524 | getLogicalDisplayRect(mTmpRect); |
| 525 | switch (rotationDelta) { |
| 526 | case Surface.ROTATION_0: |
| 527 | mTmpRect2.set(bounds); |
| 528 | break; |
| 529 | case Surface.ROTATION_90: |
| 530 | mTmpRect2.top = mTmpRect.bottom - bounds.right; |
| 531 | mTmpRect2.left = bounds.top; |
| 532 | mTmpRect2.right = mTmpRect2.left + bounds.height(); |
| 533 | mTmpRect2.bottom = mTmpRect2.top + bounds.width(); |
| 534 | break; |
| 535 | case Surface.ROTATION_180: |
| 536 | mTmpRect2.top = mTmpRect.bottom - bounds.bottom; |
| 537 | mTmpRect2.left = mTmpRect.right - bounds.right; |
| 538 | mTmpRect2.right = mTmpRect2.left + bounds.width(); |
| 539 | mTmpRect2.bottom = mTmpRect2.top + bounds.height(); |
| 540 | break; |
| 541 | case Surface.ROTATION_270: |
| 542 | mTmpRect2.top = bounds.left; |
| 543 | mTmpRect2.left = mTmpRect.right - bounds.bottom; |
| 544 | mTmpRect2.right = mTmpRect2.left + bounds.height(); |
| 545 | mTmpRect2.bottom = mTmpRect2.top + bounds.width(); |
| 546 | break; |
| 547 | } |
| 548 | bounds.set(mTmpRect2); |
| 549 | } |
| 550 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 551 | static int deltaRotation(int oldRotation, int newRotation) { |
| 552 | int delta = newRotation - oldRotation; |
| 553 | if (delta < 0) delta += 4; |
| 554 | return delta; |
| 555 | } |
| 556 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 557 | public void dump(String prefix, PrintWriter pw) { |
| 558 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 559 | final String subPrefix = " " + prefix; |
| 560 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 561 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 562 | pw.print("dpi"); |
| 563 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 564 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 565 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 566 | pw.print(" base="); |
| 567 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 568 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 569 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 570 | if (mDisplayScalingDisabled) { |
| 571 | pw.println(" noscale"); |
| 572 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 573 | pw.print(" cur="); |
| 574 | pw.print(mDisplayInfo.logicalWidth); |
| 575 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 576 | pw.print(" app="); |
| 577 | pw.print(mDisplayInfo.appWidth); |
| 578 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 579 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 580 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 581 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 582 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 583 | pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval); |
| 584 | pw.print(" layoutNeeded="); pw.println(layoutNeeded); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 585 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 586 | pw.println(); |
Craig Mautner | e8b85fd | 2014-10-22 09:23:25 -0700 | [diff] [blame] | 587 | pw.println(" Application tokens in top down Z order:"); |
Craig Mautner | e8b85fd | 2014-10-22 09:23:25 -0700 | [diff] [blame] | 588 | for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Craig Mautner | bcb6eb9 | 2015-01-13 13:09:22 -0800 | [diff] [blame] | 589 | final TaskStack stack = mStacks.get(stackNdx); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 590 | stack.dump(prefix + " ", pw); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 591 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 592 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 593 | pw.println(); |
| 594 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 595 | pw.println(); |
| 596 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 597 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 598 | WindowToken token = mExitingTokens.get(i); |
| 599 | pw.print(" Exiting #"); pw.print(i); |
| 600 | pw.print(' '); pw.print(token); |
| 601 | pw.println(':'); |
| 602 | token.dump(pw, " "); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 603 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 604 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 605 | pw.println(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 606 | mDimLayerController.dump(prefix + " ", pw); |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 607 | pw.println(); |
| 608 | mDividerControllerLocked.dump(prefix + " ", pw); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 609 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 610 | |
| 611 | @Override |
| 612 | public String toString() { |
| 613 | return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks; |
| 614 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 615 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 616 | /** |
| 617 | * @return The docked stack, but only if it is visible, and {@code null} otherwise. |
| 618 | */ |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 619 | TaskStack getDockedStackLocked() { |
Wale Ogunwale | e45899a | 2015-10-01 11:30:34 -0700 | [diff] [blame] | 620 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
| 621 | return (stack != null && stack.isVisibleLocked()) ? stack : null; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 622 | } |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 623 | |
| 624 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 625 | * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not |
| 626 | * visible, as long as it's not hidden because the current user doesn't have any tasks there. |
| 627 | */ |
| 628 | TaskStack getDockedStackVisibleForUserLocked() { |
| 629 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
| 630 | return (stack != null && stack.isVisibleForUserLocked()) ? stack : null; |
| 631 | } |
| 632 | |
| 633 | /** |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 634 | * Find the visible, touch-deliverable window under the given point |
| 635 | */ |
| 636 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
| 637 | WindowState touchedWin = null; |
| 638 | final int x = (int) xf; |
| 639 | final int y = (int) yf; |
| 640 | |
| 641 | for (int i = mWindows.size() - 1; i >= 0; i--) { |
| 642 | WindowState window = mWindows.get(i); |
| 643 | final int flags = window.mAttrs.flags; |
| 644 | if (!window.isVisibleLw()) { |
| 645 | continue; |
| 646 | } |
| 647 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
| 648 | continue; |
| 649 | } |
| 650 | |
| 651 | window.getVisibleBounds(mTmpRect); |
| 652 | if (!mTmpRect.contains(x, y)) { |
| 653 | continue; |
| 654 | } |
| 655 | |
| 656 | window.getTouchableRegion(mTmpRegion); |
| 657 | |
| 658 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
| 659 | if (mTmpRegion.contains(x, y) || touchFlags == 0) { |
| 660 | touchedWin = window; |
| 661 | break; |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | return touchedWin; |
| 666 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 667 | } |