blob: 990405a3bdeb0c0fda9d02635a5691015735c8de [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;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070033import android.hardware.display.DisplayManagerInternal;
Chong Zhang8e89b312015-09-09 15:09:30 -070034import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -070035import android.util.Slog;
Craig Mautnerb47bbc32012-08-22 17:41:48 -070036import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070037import android.view.DisplayInfo;
Craig Mautner4a1cb222013-12-04 16:14:06 -080038import android.view.Surface;
Jorim Jaggi6626f542016-08-22 13:08:44 -070039import android.view.animation.Animation;
Craig Mautner59c00972012-07-30 12:10:24 -070040
41import java.io.PrintWriter;
42import java.util.ArrayList;
43
44class DisplayContentList extends ArrayList<DisplayContent> {
45}
46
47/**
48 * Utility class for keeping track of the WindowStates and other pertinent contents of a
49 * particular Display.
50 *
51 * IMPORTANT: No method from this class should ever be used without holding
52 * WindowManagerService.mWindowMap.
53 */
54class DisplayContent {
55
56 /** Unique identifier of this stack. */
57 private final int mDisplayId;
58
59 /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
60 * from mDisplayWindows; */
Craig Mautnerdc548482014-02-05 13:35:24 -080061 private final WindowList mWindows = new WindowList();
Craig Mautner59c00972012-07-30 12:10:24 -070062
Craig Mautner59c00972012-07-30 12:10:24 -070063 int mInitialDisplayWidth = 0;
64 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070065 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -070066 int mBaseDisplayWidth = 0;
67 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070068 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -070069 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -070070 private final DisplayInfo mDisplayInfo = new DisplayInfo();
71 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070072 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -070073
Craig Mautner6601b7b2013-04-29 10:29:11 -070074 Rect mBaseDisplayRect = new Rect();
Craig Mautnerbdc748af2013-12-02 14:08:25 -080075 Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -070076
Craig Mautner39834192012-09-02 07:47:24 -070077 // Accessed directly by all users.
78 boolean layoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -070079 int pendingLayoutChanges;
Craig Mautner69b08182012-09-05 13:07:13 -070080 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -070081
Craig Mautnerdc548482014-02-05 13:35:24 -080082 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070083 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080084
Craig Mautnerbdc748af2013-12-02 14:08:25 -080085 /** Array containing all TaskStacks on this display. Array
Craig Mautnercf910b02013-04-23 11:23:27 -070086 * is stored in display order with the current bottom stack at 0. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070087 private final ArrayList<TaskStack> mStacks = new ArrayList<>();
Craig Mautnerc00204b2013-03-05 15:02:14 -080088
Craig Mautnerbdc748af2013-12-02 14:08:25 -080089 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
90 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -070091 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070092
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070093 /** Detect user tapping outside of current focused task bounds .*/
94 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -070095
Craig Mautner6601b7b2013-04-29 10:29:11 -070096 /** Detect user tapping outside of current focused stack bounds .*/
97 Region mTouchExcludeRegion = new Region();
98
Craig Mautner6601b7b2013-04-29 10:29:11 -070099 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800100 private final Rect mTmpRect = new Rect();
101 private final Rect mTmpRect2 = new Rect();
102 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700103
Craig Mautnerdc548482014-02-05 13:35:24 -0800104 /** For gathering Task objects in order. */
105 final ArrayList<Task> mTmpTaskHistory = new ArrayList<Task>();
106
Craig Mautner9d808b12013-08-06 18:00:25 -0700107 final WindowManagerService mService;
108
Craig Mautner95da1082014-02-24 17:54:35 -0800109 /** Remove this display when animation on it has completed. */
110 boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800111
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700112 final DockedStackDividerController mDividerControllerLocked;
113
Chong Zhang112eb8c2015-11-02 11:17:00 -0800114 final DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700115
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800116 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
117
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800118 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700119 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800120 * @param service You know.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700121 */
Craig Mautner9d808b12013-08-06 18:00:25 -0700122 DisplayContent(Display display, WindowManagerService service) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700123 mDisplay = display;
124 mDisplayId = display.getDisplayId();
125 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700126 display.getMetrics(mDisplayMetrics);
Craig Mautner69b08182012-09-05 13:07:13 -0700127 isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700128 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700129 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800130 mDividerControllerLocked = new DockedStackDividerController(service, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800131 mDimLayerController = new DimLayerController(this);
Craig Mautner59c00972012-07-30 12:10:24 -0700132 }
133
134 int getDisplayId() {
135 return mDisplayId;
136 }
137
138 WindowList getWindowList() {
139 return mWindows;
140 }
141
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700142 Display getDisplay() {
143 return mDisplay;
144 }
145
Craig Mautner59c00972012-07-30 12:10:24 -0700146 DisplayInfo getDisplayInfo() {
147 return mDisplayInfo;
148 }
149
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700150 DisplayMetrics getDisplayMetrics() {
151 return mDisplayMetrics;
152 }
153
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100154 DockedStackDividerController getDockedDividerController() {
155 return mDividerControllerLocked;
156 }
157
Jeff Browna506a6e2013-06-04 00:02:38 -0700158 /**
159 * Returns true if the specified UID has access to this display.
160 */
161 public boolean hasAccess(int uid) {
162 return mDisplay.hasAccess(uid);
163 }
164
keunyounga446bf02013-06-21 19:07:57 -0700165 public boolean isPrivate() {
166 return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
167 }
168
Craig Mautnerdc548482014-02-05 13:35:24 -0800169 ArrayList<TaskStack> getStacks() {
170 return mStacks;
171 }
172
Craig Mautner00af9fe2013-03-25 09:13:41 -0700173 /**
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700174 * Retrieve the tasks on this display in stack order from the bottommost TaskStack up.
Craig Mautner00af9fe2013-03-25 09:13:41 -0700175 * @return All the Tasks, in order, on this display.
176 */
Craig Mautnerc00204b2013-03-05 15:02:14 -0800177 ArrayList<Task> getTasks() {
Craig Mautnerdc548482014-02-05 13:35:24 -0800178 mTmpTaskHistory.clear();
179 final int numStacks = mStacks.size();
180 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
181 mTmpTaskHistory.addAll(mStacks.get(stackNdx).getTasks());
Craig Mautnerd9a22882013-03-16 15:00:36 -0700182 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800183 return mTmpTaskHistory;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800184 }
185
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700186 TaskStack getHomeStack() {
Craig Mautner333c2ec2014-10-02 12:24:02 -0700187 if (mHomeStack == null && mDisplayId == Display.DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800188 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -0800189 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700190 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700191 }
192
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700193 TaskStack getStackById(int stackId) {
194 for (int i = mStacks.size() - 1; i >= 0; --i) {
195 final TaskStack stack = mStacks.get(i);
196 if (stack.mStackId == stackId) {
197 return stack;
198 }
199 }
200 return null;
201 }
202
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700203 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700204 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700205 mDisplay.getMetrics(mDisplayMetrics);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800206 for (int i = mStacks.size() - 1; i >= 0; --i) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700207 mStacks.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800208 }
Craig Mautner722285e2012-09-07 13:55:58 -0700209 }
210
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700211 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700212 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
213 if (displayManagerInternal != null) {
214 // Bootstrap the default logical display from the display manager.
215 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
216 if (newDisplayInfo != null) {
217 mDisplayInfo.copyFrom(newDisplayInfo);
218 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700219 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700220
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800221 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
222 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
223 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
224 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700225 }
226
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700227 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700228 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800229 final int orientation = mDisplayInfo.rotation;
230 boolean rotated = (orientation == Surface.ROTATION_90
231 || orientation == Surface.ROTATION_270);
232 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
233 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700234 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800235 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700236 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800237 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700238 out.set(left, top, left + width, top + height);
239 }
240
Chong Zhangf66db432016-01-13 10:39:51 -0800241 void getContentRect(Rect out) {
242 out.set(mContentRect);
243 }
244
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700245 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
246 void attachStack(TaskStack stack, boolean onTop) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800247 if (stack.mStackId == HOME_STACK_ID) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800248 if (mHomeStack != null) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800249 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700250 }
Craig Mautnerdf88d732014-01-27 09:21:32 -0800251 mHomeStack = stack;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800252 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700253 if (onTop) {
254 mStacks.add(stack);
255 } else {
256 mStacks.add(0, stack);
257 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800258 layoutNeeded = true;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800259 }
260
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800261 void moveStack(TaskStack stack, boolean toTop) {
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800262 if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
263 // This stack is always-on-top silly...
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800264 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700265 return;
266 }
267
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700268 if (!mStacks.remove(stack)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800269 Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700270 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700271
272 int addIndex = toTop ? mStacks.size() : 0;
273
274 if (toTop
275 && mService.isStackVisibleLocked(PINNED_STACK_ID)
276 && stack.mStackId != PINNED_STACK_ID) {
277 // The pinned stack is always the top most stack (always-on-top) when it is visible.
278 // So, stack is moved just below the pinned stack.
279 addIndex--;
280 TaskStack topStack = mStacks.get(addIndex);
281 if (topStack.mStackId != PINNED_STACK_ID) {
282 throw new IllegalStateException("Pinned stack isn't top stack??? " + mStacks);
283 }
284 }
285 mStacks.add(addIndex, stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800286 }
287
Craig Mautnerdf88d732014-01-27 09:21:32 -0800288 void detachStack(TaskStack stack) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800289 mDimLayerController.removeDimLayerUser(stack);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800290 mStacks.remove(stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800291 }
292
293 /**
294 * Propagate the new bounds to all child stacks.
295 * @param contentRect The bounds to apply at the top level.
296 */
297 void resize(Rect contentRect) {
298 mContentRect.set(contentRect);
299 }
300
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700301 int taskIdFromPoint(int x, int y) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800302 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800303 TaskStack stack = mStacks.get(stackNdx);
304 stack.getBounds(mTmpRect);
Jorim Jaggib72c9ad2016-04-11 18:27:58 -0700305 if (!mTmpRect.contains(x, y) || stack.isAdjustedForMinimizedDockedStack()) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800306 continue;
307 }
308 final ArrayList<Task> tasks = stack.getTasks();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700309 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
310 final Task task = tasks.get(taskNdx);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800311 final WindowState win = task.getTopVisibleAppMainWindow();
312 if (win == null) {
313 continue;
314 }
315 // We need to use the task's dim bounds (which is derived from the visible
316 // bounds of its apps windows) for any touch-related tests. Can't use
317 // the task's original bounds because it might be adjusted to fit the
318 // content frame. For example, the presence of the IME adjusting the
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700319 // windows frames when the app window is the IME target.
Chong Zhangd8ceb852015-11-11 14:53:41 -0800320 task.getDimBounds(mTmpRect);
321 if (mTmpRect.contains(x, y)) {
322 return task.mTaskId;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700323 }
Craig Mautner967212c2013-04-13 21:10:58 -0700324 }
325 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800326 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700327 }
328
Chong Zhang8e89b312015-09-09 15:09:30 -0700329 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -0800330 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -0700331 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700332 */
Chong Zhangd8ceb852015-11-11 14:53:41 -0800333 Task findTaskForControlPoint(int x, int y) {
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700334 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhang8e89b312015-09-09 15:09:30 -0700335 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
336 TaskStack stack = mStacks.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700337 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700338 break;
339 }
340 final ArrayList<Task> tasks = stack.getTasks();
341 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
342 final Task task = tasks.get(taskNdx);
343 if (task.isFullscreen()) {
Chong Zhang9184ec62015-09-24 12:32:21 -0700344 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700345 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700346
Chong Zhangd8ceb852015-11-11 14:53:41 -0800347 // We need to use the task's dim bounds (which is derived from the visible
348 // bounds of its apps windows) for any touch-related tests. Can't use
349 // the task's original bounds because it might be adjusted to fit the
350 // content frame. One example is when the task is put to top-left quadrant,
351 // the actual visible area would not start at (0,0) after it's adjusted
352 // for the status bar.
353 task.getDimBounds(mTmpRect);
354 mTmpRect.inset(-delta, -delta);
355 if (mTmpRect.contains(x, y)) {
356 mTmpRect.inset(delta, delta);
357 if (!mTmpRect.contains(x, y)) {
358 return task;
Chong Zhang8e89b312015-09-09 15:09:30 -0700359 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800360 // User touched inside the task. No need to look further,
361 // focus transfer will be handled in ACTION_UP.
362 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700363 }
364 }
365 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700366 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700367 }
368
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700369 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700370 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700371 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800372 boolean addBackFocusedTask = false;
373 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
374 TaskStack stack = mStacks.get(stackNdx);
375 final ArrayList<Task> tasks = stack.getTasks();
376 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
377 final Task task = tasks.get(taskNdx);
Robert Carr9e76d322016-04-22 12:37:57 -0700378 AppWindowToken token = task.getTopVisibleAppToken();
379 if (token == null || !token.isVisible()) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800380 continue;
381 }
382
Chong Zhang8e89b312015-09-09 15:09:30 -0700383 /**
384 * Exclusion region is the region that TapDetector doesn't care about.
385 * Here we want to remove all non-focused tasks from the exclusion region.
386 * We also remove the outside touch area for resizing for all freeform
387 * tasks (including the focused).
388 *
Robert Carr9e76d322016-04-22 12:37:57 -0700389 * We save the focused task region once we find it, and add it back at the end.
Chong Zhang8e89b312015-09-09 15:09:30 -0700390 */
Robert Carr9e76d322016-04-22 12:37:57 -0700391
Wale Ogunwalee4dd9642016-05-10 08:39:01 -0700392 task.getDimBounds(mTmpRect);
393
Robert Carr9e76d322016-04-22 12:37:57 -0700394 if (task == focusedTask) {
395 addBackFocusedTask = true;
396 mTmpRect2.set(mTmpRect);
397 }
398
Chong Zhang09b21ef2015-09-14 10:20:21 -0700399 final boolean isFreeformed = task.inFreeformWorkspace();
Chong Zhang8e89b312015-09-09 15:09:30 -0700400 if (task != focusedTask || isFreeformed) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700401 if (isFreeformed) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800402 // If the task is freeformed, enlarge the area to account for outside
403 // touch area for resize.
Chong Zhang8e89b312015-09-09 15:09:30 -0700404 mTmpRect.inset(-delta, -delta);
Chong Zhang73c3fcf2015-11-05 13:18:33 -0800405 // Intersect with display content rect. If we have system decor (status bar/
406 // navigation bar), we want to exclude that from the tap detection.
407 // Otherwise, if the app is partially placed under some system button (eg.
408 // Recents, Home), pressing that button would cause a full series of
409 // unwanted transfer focus/resume/pause, before we could go home.
410 mTmpRect.intersect(mContentRect);
Chong Zhang8e89b312015-09-09 15:09:30 -0700411 }
412 mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
413 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700414 }
415 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800416 // If we removed the focused task above, add it back and only leave its
417 // outside touch area in the exclusion. TapDectector is not interested in
418 // any touch inside the focused task itself.
419 if (addBackFocusedTask) {
420 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
421 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800422 final WindowState inputMethod = mService.mInputMethodWindow;
423 if (inputMethod != null && inputMethod.isVisibleLw()) {
424 // If the input method is visible and the user is typing, we don't want these touch
425 // events to be intercepted and used to change focus. This would likely cause a
426 // disappearance of the input method.
427 inputMethod.getTouchableRegion(mTmpRegion);
428 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
429 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800430 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
431 WindowState win = mTapExcludedWindows.get(i);
432 win.getTouchableRegion(mTmpRegion);
433 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
434 }
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100435 if (getDockedStackVisibleForUserLocked() != null) {
436 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -0700437 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100438 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
439 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800440 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700441 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -0800442 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700443 }
444
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800445 void switchUserStacks() {
Craig Mautner858d8a62013-04-23 17:08:34 -0700446 final WindowList windows = getWindowList();
447 for (int i = 0; i < windows.size(); i++) {
448 final WindowState win = windows.get(i);
449 if (win.isHiddenFromUserLocked()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800450 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800451 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700452 win.hideLw(false);
453 }
454 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700455
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800456 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800457 mStacks.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700458 }
459 }
460
Craig Mautner05d29032013-05-03 13:40:13 -0700461 void resetAnimationBackgroundAnimator() {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800462 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
463 mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700464 }
465 }
466
467 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800468 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700469 }
470
471 void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800472 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700473 }
474
475 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800476 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700477 }
478
479 void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800480 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700481 }
482
Craig Mautner2eb15342013-08-07 13:13:35 -0700483 void close() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800484 mDimLayerController.close();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800485 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
486 mStacks.get(stackNdx).close();
Craig Mautner2eb15342013-08-07 13:13:35 -0700487 }
488 }
489
Craig Mautner95da1082014-02-24 17:54:35 -0800490 boolean isAnimating() {
491 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
492 final TaskStack stack = mStacks.get(stackNdx);
493 if (stack.isAnimating()) {
494 return true;
495 }
496 }
497 return false;
498 }
499
500 void checkForDeferredActions() {
501 boolean animating = false;
502 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
503 final TaskStack stack = mStacks.get(stackNdx);
504 if (stack.isAnimating()) {
505 animating = true;
506 } else {
507 if (stack.mDeferDetach) {
508 mService.detachStackLocked(this, stack);
509 }
510 final ArrayList<Task> tasks = stack.getTasks();
511 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
512 final Task task = tasks.get(taskNdx);
513 AppTokenList tokens = task.mAppTokens;
514 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
515 AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800516 if (wtoken.mIsExiting) {
Craig Mautnere3119b72015-01-20 15:02:36 -0800517 wtoken.removeAppFromTaskLocked();
Craig Mautner95da1082014-02-24 17:54:35 -0800518 }
519 }
Craig Mautner95da1082014-02-24 17:54:35 -0800520 }
521 }
522 }
523 if (!animating && mDeferredRemoval) {
524 mService.onDisplayRemoved(mDisplayId);
525 }
526 }
527
Wale Ogunwale94744212015-09-21 19:01:47 -0700528 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
529 final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation);
530 getLogicalDisplayRect(mTmpRect);
531 switch (rotationDelta) {
532 case Surface.ROTATION_0:
533 mTmpRect2.set(bounds);
534 break;
535 case Surface.ROTATION_90:
536 mTmpRect2.top = mTmpRect.bottom - bounds.right;
537 mTmpRect2.left = bounds.top;
538 mTmpRect2.right = mTmpRect2.left + bounds.height();
539 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
540 break;
541 case Surface.ROTATION_180:
542 mTmpRect2.top = mTmpRect.bottom - bounds.bottom;
543 mTmpRect2.left = mTmpRect.right - bounds.right;
544 mTmpRect2.right = mTmpRect2.left + bounds.width();
545 mTmpRect2.bottom = mTmpRect2.top + bounds.height();
546 break;
547 case Surface.ROTATION_270:
548 mTmpRect2.top = bounds.left;
549 mTmpRect2.left = mTmpRect.right - bounds.bottom;
550 mTmpRect2.right = mTmpRect2.left + bounds.height();
551 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
552 break;
553 }
554 bounds.set(mTmpRect2);
555 }
556
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800557 static int deltaRotation(int oldRotation, int newRotation) {
558 int delta = newRotation - oldRotation;
559 if (delta < 0) delta += 4;
560 return delta;
561 }
562
Craig Mautnera91f9e22012-09-14 16:22:08 -0700563 public void dump(String prefix, PrintWriter pw) {
564 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
565 final String subPrefix = " " + prefix;
566 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
567 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
568 pw.print("dpi");
569 if (mInitialDisplayWidth != mBaseDisplayWidth
570 || mInitialDisplayHeight != mBaseDisplayHeight
571 || mInitialDisplayDensity != mBaseDisplayDensity) {
572 pw.print(" base=");
573 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
574 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
575 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700576 if (mDisplayScalingDisabled) {
577 pw.println(" noscale");
578 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700579 pw.print(" cur=");
580 pw.print(mDisplayInfo.logicalWidth);
581 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
582 pw.print(" app=");
583 pw.print(mDisplayInfo.appWidth);
584 pw.print("x"); pw.print(mDisplayInfo.appHeight);
585 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
586 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
587 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
588 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Craig Mautner95da1082014-02-24 17:54:35 -0800589 pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval);
590 pw.print(" layoutNeeded="); pw.println(layoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800591
Craig Mautnerdc548482014-02-05 13:35:24 -0800592 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700593 pw.println(" Application tokens in top down Z order:");
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700594 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800595 final TaskStack stack = mStacks.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800596 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700597 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800598
Craig Mautnerdc548482014-02-05 13:35:24 -0800599 pw.println();
600 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700601 pw.println();
602 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800603 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700604 WindowToken token = mExitingTokens.get(i);
605 pw.print(" Exiting #"); pw.print(i);
606 pw.print(' '); pw.print(token);
607 pw.println(':');
608 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800609 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700610 }
Craig Mautner59c00972012-07-30 12:10:24 -0700611 pw.println();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800612 mDimLayerController.dump(prefix + " ", pw);
Jorim Jaggi31f71702016-05-04 16:43:04 -0700613 pw.println();
614 mDividerControllerLocked.dump(prefix + " ", pw);
Craig Mautner59c00972012-07-30 12:10:24 -0700615 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800616
617 @Override
618 public String toString() {
619 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
620 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700621
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800622 /**
623 * @return The docked stack, but only if it is visible, and {@code null} otherwise.
624 */
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700625 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700626 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700627 return (stack != null && stack.isVisible()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700628 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800629
630 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800631 * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not
632 * visible, as long as it's not hidden because the current user doesn't have any tasks there.
633 */
634 TaskStack getDockedStackVisibleForUserLocked() {
635 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700636 return (stack != null && stack.isVisible(true /* ignoreKeyguard */)) ? stack : null;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800637 }
638
639 /**
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800640 * Find the visible, touch-deliverable window under the given point
641 */
642 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
643 WindowState touchedWin = null;
644 final int x = (int) xf;
645 final int y = (int) yf;
646
647 for (int i = mWindows.size() - 1; i >= 0; i--) {
648 WindowState window = mWindows.get(i);
649 final int flags = window.mAttrs.flags;
650 if (!window.isVisibleLw()) {
651 continue;
652 }
653 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
654 continue;
655 }
656
657 window.getVisibleBounds(mTmpRect);
658 if (!mTmpRect.contains(x, y)) {
659 continue;
660 }
661
662 window.getTouchableRegion(mTmpRegion);
663
664 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
665 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
666 touchedWin = window;
667 break;
668 }
669 }
670
671 return touchedWin;
672 }
Jorim Jaggi6626f542016-08-22 13:08:44 -0700673
674 /**
675 * See {@link WindowManagerService#overridePlayingAppAnimationsLw}.
676 */
677 void overridePlayingAppAnimationsLw(Animation a) {
678 for (int i = mStacks.size() - 1; i >= 0; i--) {
679 mStacks.get(i).overridePlayingAppAnimations(a);
680 }
681 }
Craig Mautner59c00972012-07-30 12:10:24 -0700682}