blob: aba64e8cc08177cac57f47fd562a42e86ce78a7f [file] [log] [blame]
Craig Mautner59c00972012-07-30 12:10:24 -07001/*
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
17package com.android.server.wm;
18
Wale Ogunwale3797c222015-10-27 14:21:58 -070019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
20import static android.app.ActivityManager.StackId.HOME_STACK_ID;
21import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080022import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
23import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
24import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080025import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
26import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070027import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070028
Wale Ogunwale3797c222015-10-27 14:21:58 -070029import android.app.ActivityManager.StackId;
Craig Mautnerc00204b2013-03-05 15:02:14 -080030import android.graphics.Rect;
Craig Mautner6601b7b2013-04-29 10:29:11 -070031import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +010032import android.graphics.Region.Op;
Chong Zhang8e89b312015-09-09 15:09:30 -070033import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -070034import android.util.Slog;
Craig Mautnerb47bbc32012-08-22 17:41:48 -070035import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070036import android.view.DisplayInfo;
Craig Mautner4a1cb222013-12-04 16:14:06 -080037import android.view.Surface;
Craig Mautner59c00972012-07-30 12:10:24 -070038
39import java.io.PrintWriter;
40import java.util.ArrayList;
41
42class 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 */
52class 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 Mautnerdc548482014-02-05 13:35:24 -080059 private final WindowList mWindows = new WindowList();
Craig Mautner59c00972012-07-30 12:10:24 -070060
Craig Mautner59c00972012-07-30 12:10:24 -070061 int mInitialDisplayWidth = 0;
62 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070063 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -070064 int mBaseDisplayWidth = 0;
65 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070066 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -070067 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -070068 private final DisplayInfo mDisplayInfo = new DisplayInfo();
69 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070070 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -070071
Craig Mautner6601b7b2013-04-29 10:29:11 -070072 Rect mBaseDisplayRect = new Rect();
Craig Mautnerbdc748af2013-12-02 14:08:25 -080073 Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -070074
Craig Mautner39834192012-09-02 07:47:24 -070075 // Accessed directly by all users.
76 boolean layoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -070077 int pendingLayoutChanges;
Craig Mautner69b08182012-09-05 13:07:13 -070078 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -070079
Craig Mautnerdc548482014-02-05 13:35:24 -080080 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070081 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080082
Craig Mautnerbdc748af2013-12-02 14:08:25 -080083 /** Array containing all TaskStacks on this display. Array
Craig Mautnercf910b02013-04-23 11:23:27 -070084 * is stored in display order with the current bottom stack at 0. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070085 private final ArrayList<TaskStack> mStacks = new ArrayList<>();
Craig Mautnerc00204b2013-03-05 15:02:14 -080086
Craig Mautnerbdc748af2013-12-02 14:08:25 -080087 /** 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 Mautnerde4ef022013-04-07 19:01:33 -070089 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070090
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070091 /** Detect user tapping outside of current focused task bounds .*/
92 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -070093
Craig Mautner6601b7b2013-04-29 10:29:11 -070094 /** Detect user tapping outside of current focused stack bounds .*/
95 Region mTouchExcludeRegion = new Region();
96
Chong Zhangb15758a2015-11-17 12:12:03 -080097 /** Detect user tapping in a non-resizeable task in docked or fullscreen stack .*/
98 Region mNonResizeableRegion = new Region();
99
Craig Mautner6601b7b2013-04-29 10:29:11 -0700100 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800101 private final Rect mTmpRect = new Rect();
102 private final Rect mTmpRect2 = new Rect();
103 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700104
Craig Mautnerdc548482014-02-05 13:35:24 -0800105 /** For gathering Task objects in order. */
106 final ArrayList<Task> mTmpTaskHistory = new ArrayList<Task>();
107
Craig Mautner9d808b12013-08-06 18:00:25 -0700108 final WindowManagerService mService;
109
Craig Mautner95da1082014-02-24 17:54:35 -0800110 /** Remove this display when animation on it has completed. */
111 boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800112
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700113 final DockedStackDividerController mDividerControllerLocked;
114
Chong Zhang112eb8c2015-11-02 11:17:00 -0800115 final DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700116
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800117 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
118
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800119 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700120 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800121 * @param service You know.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700122 */
Craig Mautner9d808b12013-08-06 18:00:25 -0700123 DisplayContent(Display display, WindowManagerService service) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700124 mDisplay = display;
125 mDisplayId = display.getDisplayId();
126 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700127 display.getMetrics(mDisplayMetrics);
Craig Mautner69b08182012-09-05 13:07:13 -0700128 isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700129 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700130 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800131 mDividerControllerLocked = new DockedStackDividerController(service, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800132 mDimLayerController = new DimLayerController(this);
Craig Mautner59c00972012-07-30 12:10:24 -0700133 }
134
135 int getDisplayId() {
136 return mDisplayId;
137 }
138
139 WindowList getWindowList() {
140 return mWindows;
141 }
142
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700143 Display getDisplay() {
144 return mDisplay;
145 }
146
Craig Mautner59c00972012-07-30 12:10:24 -0700147 DisplayInfo getDisplayInfo() {
148 return mDisplayInfo;
149 }
150
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700151 DisplayMetrics getDisplayMetrics() {
152 return mDisplayMetrics;
153 }
154
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100155 DockedStackDividerController getDockedDividerController() {
156 return mDividerControllerLocked;
157 }
158
Jeff Browna506a6e2013-06-04 00:02:38 -0700159 /**
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
keunyounga446bf02013-06-21 19:07:57 -0700166 public boolean isPrivate() {
167 return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
168 }
169
Craig Mautnerdc548482014-02-05 13:35:24 -0800170 ArrayList<TaskStack> getStacks() {
171 return mStacks;
172 }
173
Craig Mautner00af9fe2013-03-25 09:13:41 -0700174 /**
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700175 * Retrieve the tasks on this display in stack order from the bottommost TaskStack up.
Craig Mautner00af9fe2013-03-25 09:13:41 -0700176 * @return All the Tasks, in order, on this display.
177 */
Craig Mautnerc00204b2013-03-05 15:02:14 -0800178 ArrayList<Task> getTasks() {
Craig Mautnerdc548482014-02-05 13:35:24 -0800179 mTmpTaskHistory.clear();
180 final int numStacks = mStacks.size();
181 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
182 mTmpTaskHistory.addAll(mStacks.get(stackNdx).getTasks());
Craig Mautnerd9a22882013-03-16 15:00:36 -0700183 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800184 return mTmpTaskHistory;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800185 }
186
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700187 TaskStack getHomeStack() {
Craig Mautner333c2ec2014-10-02 12:24:02 -0700188 if (mHomeStack == null && mDisplayId == Display.DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800189 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -0800190 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700191 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700192 }
193
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700194 TaskStack getStackById(int stackId) {
195 for (int i = mStacks.size() - 1; i >= 0; --i) {
196 final TaskStack stack = mStacks.get(i);
197 if (stack.mStackId == stackId) {
198 return stack;
199 }
200 }
201 return null;
202 }
203
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700204 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700205 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700206 mDisplay.getMetrics(mDisplayMetrics);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800207 for (int i = mStacks.size() - 1; i >= 0; --i) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700208 mStacks.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800209 }
Craig Mautner722285e2012-09-07 13:55:58 -0700210 }
211
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700212 void initializeDisplayBaseInfo() {
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800213 // Bootstrap the default logical display from the display manager.
214 final DisplayInfo newDisplayInfo =
215 mService.mDisplayManagerInternal.getDisplayInfo(mDisplayId);
216 if (newDisplayInfo != null) {
217 mDisplayInfo.copyFrom(newDisplayInfo);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700218 }
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800219 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
220 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
221 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
222 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700223 }
224
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700225 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700226 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800227 final int orientation = mDisplayInfo.rotation;
228 boolean rotated = (orientation == Surface.ROTATION_90
229 || orientation == Surface.ROTATION_270);
230 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
231 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700232 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800233 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700234 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800235 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700236 out.set(left, top, left + width, top + height);
237 }
238
Chong Zhangf66db432016-01-13 10:39:51 -0800239 void getContentRect(Rect out) {
240 out.set(mContentRect);
241 }
242
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700243 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
244 void attachStack(TaskStack stack, boolean onTop) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800245 if (stack.mStackId == HOME_STACK_ID) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800246 if (mHomeStack != null) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800247 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700248 }
Craig Mautnerdf88d732014-01-27 09:21:32 -0800249 mHomeStack = stack;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800250 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700251 if (onTop) {
252 mStacks.add(stack);
253 } else {
254 mStacks.add(0, stack);
255 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800256 layoutNeeded = true;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800257 }
258
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800259 void moveStack(TaskStack stack, boolean toTop) {
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800260 if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
261 // This stack is always-on-top silly...
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800262 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700263 return;
264 }
265
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700266 if (!mStacks.remove(stack)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800267 Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700268 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700269
270 int addIndex = toTop ? mStacks.size() : 0;
271
272 if (toTop
273 && mService.isStackVisibleLocked(PINNED_STACK_ID)
274 && stack.mStackId != PINNED_STACK_ID) {
275 // The pinned stack is always the top most stack (always-on-top) when it is visible.
276 // So, stack is moved just below the pinned stack.
277 addIndex--;
278 TaskStack topStack = mStacks.get(addIndex);
279 if (topStack.mStackId != PINNED_STACK_ID) {
280 throw new IllegalStateException("Pinned stack isn't top stack??? " + mStacks);
281 }
282 }
283 mStacks.add(addIndex, stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800284 }
285
Craig Mautnerdf88d732014-01-27 09:21:32 -0800286 void detachStack(TaskStack stack) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800287 mDimLayerController.removeDimLayerUser(stack);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800288 mStacks.remove(stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800289 }
290
291 /**
292 * Propagate the new bounds to all child stacks.
293 * @param contentRect The bounds to apply at the top level.
294 */
295 void resize(Rect contentRect) {
296 mContentRect.set(contentRect);
297 }
298
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700299 int taskIdFromPoint(int x, int y) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800300 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800301 TaskStack stack = mStacks.get(stackNdx);
302 stack.getBounds(mTmpRect);
Jorim Jaggib72c9ad2016-04-11 18:27:58 -0700303 if (!mTmpRect.contains(x, y) || stack.isAdjustedForMinimizedDockedStack()) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800304 continue;
305 }
306 final ArrayList<Task> tasks = stack.getTasks();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700307 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
308 final Task task = tasks.get(taskNdx);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800309 final WindowState win = task.getTopVisibleAppMainWindow();
310 if (win == null) {
311 continue;
312 }
313 // We need to use the task's dim bounds (which is derived from the visible
314 // bounds of its apps windows) for any touch-related tests. Can't use
315 // the task's original bounds because it might be adjusted to fit the
316 // content frame. For example, the presence of the IME adjusting the
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700317 // windows frames when the app window is the IME target.
Chong Zhangd8ceb852015-11-11 14:53:41 -0800318 task.getDimBounds(mTmpRect);
319 if (mTmpRect.contains(x, y)) {
320 return task.mTaskId;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700321 }
Craig Mautner967212c2013-04-13 21:10:58 -0700322 }
323 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800324 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700325 }
326
Chong Zhang8e89b312015-09-09 15:09:30 -0700327 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -0800328 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -0700329 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700330 */
Chong Zhangd8ceb852015-11-11 14:53:41 -0800331 Task findTaskForControlPoint(int x, int y) {
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700332 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhang8e89b312015-09-09 15:09:30 -0700333 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
334 TaskStack stack = mStacks.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700335 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700336 break;
337 }
338 final ArrayList<Task> tasks = stack.getTasks();
339 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
340 final Task task = tasks.get(taskNdx);
341 if (task.isFullscreen()) {
Chong Zhang9184ec62015-09-24 12:32:21 -0700342 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700343 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700344
Chong Zhangd8ceb852015-11-11 14:53:41 -0800345 // We need to use the task's dim bounds (which is derived from the visible
346 // bounds of its apps windows) for any touch-related tests. Can't use
347 // the task's original bounds because it might be adjusted to fit the
348 // content frame. One example is when the task is put to top-left quadrant,
349 // the actual visible area would not start at (0,0) after it's adjusted
350 // for the status bar.
351 task.getDimBounds(mTmpRect);
352 mTmpRect.inset(-delta, -delta);
353 if (mTmpRect.contains(x, y)) {
354 mTmpRect.inset(delta, delta);
355 if (!mTmpRect.contains(x, y)) {
356 return task;
Chong Zhang8e89b312015-09-09 15:09:30 -0700357 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800358 // User touched inside the task. No need to look further,
359 // focus transfer will be handled in ACTION_UP.
360 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700361 }
362 }
363 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700364 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700365 }
366
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700367 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700368 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700369 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800370 boolean addBackFocusedTask = false;
Chong Zhangb15758a2015-11-17 12:12:03 -0800371 mNonResizeableRegion.setEmpty();
Chong Zhangd8ceb852015-11-11 14:53:41 -0800372 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
373 TaskStack stack = mStacks.get(stackNdx);
374 final ArrayList<Task> tasks = stack.getTasks();
375 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
376 final Task task = tasks.get(taskNdx);
Robert Carr9e76d322016-04-22 12:37:57 -0700377 AppWindowToken token = task.getTopVisibleAppToken();
378 if (token == null || !token.isVisible()) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800379 continue;
380 }
381
Chong Zhang8e89b312015-09-09 15:09:30 -0700382 /**
383 * Exclusion region is the region that TapDetector doesn't care about.
384 * Here we want to remove all non-focused tasks from the exclusion region.
385 * We also remove the outside touch area for resizing for all freeform
386 * tasks (including the focused).
387 *
Robert Carr9e76d322016-04-22 12:37:57 -0700388 * We save the focused task region once we find it, and add it back at the end.
Chong Zhang8e89b312015-09-09 15:09:30 -0700389 */
Robert Carr9e76d322016-04-22 12:37:57 -0700390
Wale Ogunwalee4dd9642016-05-10 08:39:01 -0700391 task.getDimBounds(mTmpRect);
392
Robert Carr9e76d322016-04-22 12:37:57 -0700393 if (task == focusedTask) {
394 addBackFocusedTask = true;
395 mTmpRect2.set(mTmpRect);
396 }
397
Chong Zhang09b21ef2015-09-14 10:20:21 -0700398 final boolean isFreeformed = task.inFreeformWorkspace();
Chong Zhang8e89b312015-09-09 15:09:30 -0700399 if (task != focusedTask || isFreeformed) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700400 if (isFreeformed) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800401 // If the task is freeformed, enlarge the area to account for outside
402 // touch area for resize.
Chong Zhang8e89b312015-09-09 15:09:30 -0700403 mTmpRect.inset(-delta, -delta);
Chong Zhang73c3fcf2015-11-05 13:18:33 -0800404 // Intersect with display content rect. If we have system decor (status bar/
405 // navigation bar), we want to exclude that from the tap detection.
406 // Otherwise, if the app is partially placed under some system button (eg.
407 // Recents, Home), pressing that button would cause a full series of
408 // unwanted transfer focus/resume/pause, before we could go home.
409 mTmpRect.intersect(mContentRect);
Chong Zhang8e89b312015-09-09 15:09:30 -0700410 }
411 mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
412 }
Chong Zhang2a88fc32016-01-11 17:14:24 -0800413 if (task.isTwoFingerScrollMode()) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800414 stack.getBounds(mTmpRect);
415 mNonResizeableRegion.op(mTmpRect, Region.Op.UNION);
416 break;
417 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700418 }
419 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800420 // If we removed the focused task above, add it back and only leave its
421 // outside touch area in the exclusion. TapDectector is not interested in
422 // any touch inside the focused task itself.
423 if (addBackFocusedTask) {
424 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
425 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800426 final WindowState inputMethod = mService.mInputMethodWindow;
427 if (inputMethod != null && inputMethod.isVisibleLw()) {
428 // If the input method is visible and the user is typing, we don't want these touch
429 // events to be intercepted and used to change focus. This would likely cause a
430 // disappearance of the input method.
431 inputMethod.getTouchableRegion(mTmpRegion);
432 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
433 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800434 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
435 WindowState win = mTapExcludedWindows.get(i);
436 win.getTouchableRegion(mTmpRegion);
437 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
438 }
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100439 if (getDockedStackVisibleForUserLocked() != null) {
440 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -0700441 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100442 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
443 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800444 if (mTapDetector != null) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800445 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion, mNonResizeableRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -0800446 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700447 }
448
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800449 void switchUserStacks() {
Craig Mautner858d8a62013-04-23 17:08:34 -0700450 final WindowList windows = getWindowList();
451 for (int i = 0; i < windows.size(); i++) {
452 final WindowState win = windows.get(i);
453 if (win.isHiddenFromUserLocked()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800454 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800455 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700456 win.hideLw(false);
457 }
458 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700459
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800460 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800461 mStacks.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700462 }
463 }
464
Craig Mautner05d29032013-05-03 13:40:13 -0700465 void resetAnimationBackgroundAnimator() {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800466 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
467 mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700468 }
469 }
470
471 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800472 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700473 }
474
475 void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800476 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700477 }
478
479 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800480 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700481 }
482
483 void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800484 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700485 }
486
Craig Mautner2eb15342013-08-07 13:13:35 -0700487 void close() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800488 mDimLayerController.close();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800489 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
490 mStacks.get(stackNdx).close();
Craig Mautner2eb15342013-08-07 13:13:35 -0700491 }
492 }
493
Craig Mautner95da1082014-02-24 17:54:35 -0800494 boolean isAnimating() {
495 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
496 final TaskStack stack = mStacks.get(stackNdx);
497 if (stack.isAnimating()) {
498 return true;
499 }
500 }
501 return false;
502 }
503
504 void checkForDeferredActions() {
505 boolean animating = false;
506 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
507 final TaskStack stack = mStacks.get(stackNdx);
508 if (stack.isAnimating()) {
509 animating = true;
510 } else {
511 if (stack.mDeferDetach) {
512 mService.detachStackLocked(this, stack);
513 }
514 final ArrayList<Task> tasks = stack.getTasks();
515 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
516 final Task task = tasks.get(taskNdx);
517 AppTokenList tokens = task.mAppTokens;
518 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
519 AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800520 if (wtoken.mIsExiting) {
Craig Mautnere3119b72015-01-20 15:02:36 -0800521 wtoken.removeAppFromTaskLocked();
Craig Mautner95da1082014-02-24 17:54:35 -0800522 }
523 }
Craig Mautner95da1082014-02-24 17:54:35 -0800524 }
525 }
526 }
527 if (!animating && mDeferredRemoval) {
528 mService.onDisplayRemoved(mDisplayId);
529 }
530 }
531
Wale Ogunwale94744212015-09-21 19:01:47 -0700532 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
533 final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation);
534 getLogicalDisplayRect(mTmpRect);
535 switch (rotationDelta) {
536 case Surface.ROTATION_0:
537 mTmpRect2.set(bounds);
538 break;
539 case Surface.ROTATION_90:
540 mTmpRect2.top = mTmpRect.bottom - bounds.right;
541 mTmpRect2.left = bounds.top;
542 mTmpRect2.right = mTmpRect2.left + bounds.height();
543 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
544 break;
545 case Surface.ROTATION_180:
546 mTmpRect2.top = mTmpRect.bottom - bounds.bottom;
547 mTmpRect2.left = mTmpRect.right - bounds.right;
548 mTmpRect2.right = mTmpRect2.left + bounds.width();
549 mTmpRect2.bottom = mTmpRect2.top + bounds.height();
550 break;
551 case Surface.ROTATION_270:
552 mTmpRect2.top = bounds.left;
553 mTmpRect2.left = mTmpRect.right - bounds.bottom;
554 mTmpRect2.right = mTmpRect2.left + bounds.height();
555 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
556 break;
557 }
558 bounds.set(mTmpRect2);
559 }
560
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800561 static int deltaRotation(int oldRotation, int newRotation) {
562 int delta = newRotation - oldRotation;
563 if (delta < 0) delta += 4;
564 return delta;
565 }
566
Craig Mautnera91f9e22012-09-14 16:22:08 -0700567 public void dump(String prefix, PrintWriter pw) {
568 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
569 final String subPrefix = " " + prefix;
570 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
571 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
572 pw.print("dpi");
573 if (mInitialDisplayWidth != mBaseDisplayWidth
574 || mInitialDisplayHeight != mBaseDisplayHeight
575 || mInitialDisplayDensity != mBaseDisplayDensity) {
576 pw.print(" base=");
577 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
578 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
579 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700580 if (mDisplayScalingDisabled) {
581 pw.println(" noscale");
582 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700583 pw.print(" cur=");
584 pw.print(mDisplayInfo.logicalWidth);
585 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
586 pw.print(" app=");
587 pw.print(mDisplayInfo.appWidth);
588 pw.print("x"); pw.print(mDisplayInfo.appHeight);
589 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
590 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
591 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
592 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Craig Mautner95da1082014-02-24 17:54:35 -0800593 pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval);
594 pw.print(" layoutNeeded="); pw.println(layoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800595
Craig Mautnerdc548482014-02-05 13:35:24 -0800596 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700597 pw.println(" Application tokens in top down Z order:");
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700598 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800599 final TaskStack stack = mStacks.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800600 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700601 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800602
Craig Mautnerdc548482014-02-05 13:35:24 -0800603 pw.println();
604 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700605 pw.println();
606 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800607 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700608 WindowToken token = mExitingTokens.get(i);
609 pw.print(" Exiting #"); pw.print(i);
610 pw.print(' '); pw.print(token);
611 pw.println(':');
612 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800613 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700614 }
Craig Mautner59c00972012-07-30 12:10:24 -0700615 pw.println();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800616 mDimLayerController.dump(prefix + " ", pw);
Jorim Jaggi31f71702016-05-04 16:43:04 -0700617 pw.println();
618 mDividerControllerLocked.dump(prefix + " ", pw);
Craig Mautner59c00972012-07-30 12:10:24 -0700619 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800620
621 @Override
622 public String toString() {
623 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
624 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700625
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800626 /**
627 * @return The docked stack, but only if it is visible, and {@code null} otherwise.
628 */
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700629 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700630 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
631 return (stack != null && stack.isVisibleLocked()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700632 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800633
634 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800635 * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not
636 * visible, as long as it's not hidden because the current user doesn't have any tasks there.
637 */
638 TaskStack getDockedStackVisibleForUserLocked() {
639 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Jorim Jaggi160a3c52016-08-25 15:57:41 -0700640 return (stack != null && stack.isVisibleLocked(true /* ignoreKeyguard */)) ? stack : null;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800641 }
642
643 /**
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800644 * Find the visible, touch-deliverable window under the given point
645 */
646 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
647 WindowState touchedWin = null;
648 final int x = (int) xf;
649 final int y = (int) yf;
650
651 for (int i = mWindows.size() - 1; i >= 0; i--) {
652 WindowState window = mWindows.get(i);
653 final int flags = window.mAttrs.flags;
654 if (!window.isVisibleLw()) {
655 continue;
656 }
657 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
658 continue;
659 }
660
661 window.getVisibleBounds(mTmpRect);
662 if (!mTmpRect.contains(x, y)) {
663 continue;
664 }
665
666 window.getTouchableRegion(mTmpRegion);
667
668 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
669 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
670 touchedWin = window;
671 break;
672 }
673 }
674
675 return touchedWin;
676 }
Craig Mautner59c00972012-07-30 12:10:24 -0700677}