blob: a9025bda2fbcb7425c718f96f3a021a31986cc5b [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;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080022import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
23import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070024import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070025
Wale Ogunwale3797c222015-10-27 14:21:58 -070026import android.app.ActivityManager.StackId;
Craig Mautnerc00204b2013-03-05 15:02:14 -080027import android.graphics.Rect;
Craig Mautner6601b7b2013-04-29 10:29:11 -070028import android.graphics.Region;
Chong Zhang8e89b312015-09-09 15:09:30 -070029import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -070030import android.util.Slog;
Craig Mautnerb47bbc32012-08-22 17:41:48 -070031import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070032import android.view.DisplayInfo;
Craig Mautner4a1cb222013-12-04 16:14:06 -080033import android.view.Surface;
Craig Mautner59c00972012-07-30 12:10:24 -070034
35import java.io.PrintWriter;
36import java.util.ArrayList;
37
38class DisplayContentList extends ArrayList<DisplayContent> {
39}
40
41/**
42 * Utility class for keeping track of the WindowStates and other pertinent contents of a
43 * particular Display.
44 *
45 * IMPORTANT: No method from this class should ever be used without holding
46 * WindowManagerService.mWindowMap.
47 */
48class DisplayContent {
49
50 /** Unique identifier of this stack. */
51 private final int mDisplayId;
52
53 /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
54 * from mDisplayWindows; */
Craig Mautnerdc548482014-02-05 13:35:24 -080055 private final WindowList mWindows = new WindowList();
Craig Mautner59c00972012-07-30 12:10:24 -070056
Craig Mautner59c00972012-07-30 12:10:24 -070057 int mInitialDisplayWidth = 0;
58 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070059 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -070060 int mBaseDisplayWidth = 0;
61 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070062 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -070063 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -070064 private final DisplayInfo mDisplayInfo = new DisplayInfo();
65 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070066 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -070067
Craig Mautner6601b7b2013-04-29 10:29:11 -070068 Rect mBaseDisplayRect = new Rect();
Craig Mautnerbdc748af2013-12-02 14:08:25 -080069 Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -070070
Craig Mautner39834192012-09-02 07:47:24 -070071 // Accessed directly by all users.
72 boolean layoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -070073 int pendingLayoutChanges;
Craig Mautner69b08182012-09-05 13:07:13 -070074 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -070075
Craig Mautnerdc548482014-02-05 13:35:24 -080076 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070077 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080078
Craig Mautnerbdc748af2013-12-02 14:08:25 -080079 /** Array containing all TaskStacks on this display. Array
Craig Mautnercf910b02013-04-23 11:23:27 -070080 * is stored in display order with the current bottom stack at 0. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070081 private final ArrayList<TaskStack> mStacks = new ArrayList<>();
Craig Mautnerc00204b2013-03-05 15:02:14 -080082
Craig Mautnerbdc748af2013-12-02 14:08:25 -080083 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
84 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -070085 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070086
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070087 /** Detect user tapping outside of current focused task bounds .*/
88 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -070089
Craig Mautner6601b7b2013-04-29 10:29:11 -070090 /** Detect user tapping outside of current focused stack bounds .*/
91 Region mTouchExcludeRegion = new Region();
92
Chong Zhangb15758a2015-11-17 12:12:03 -080093 /** Detect user tapping in a non-resizeable task in docked or fullscreen stack .*/
94 Region mNonResizeableRegion = new Region();
95
Craig Mautner6601b7b2013-04-29 10:29:11 -070096 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -080097 private final Rect mTmpRect = new Rect();
98 private final Rect mTmpRect2 = new Rect();
99 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700100
Craig Mautnerdc548482014-02-05 13:35:24 -0800101 /** For gathering Task objects in order. */
102 final ArrayList<Task> mTmpTaskHistory = new ArrayList<Task>();
103
Craig Mautner9d808b12013-08-06 18:00:25 -0700104 final WindowManagerService mService;
105
Craig Mautner95da1082014-02-24 17:54:35 -0800106 /** Remove this display when animation on it has completed. */
107 boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800108
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700109 final DockedStackDividerController mDividerControllerLocked;
110
Chong Zhang112eb8c2015-11-02 11:17:00 -0800111 final DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700112
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800113 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
114
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800115 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700116 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800117 * @param service You know.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700118 */
Craig Mautner9d808b12013-08-06 18:00:25 -0700119 DisplayContent(Display display, WindowManagerService service) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700120 mDisplay = display;
121 mDisplayId = display.getDisplayId();
122 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700123 display.getMetrics(mDisplayMetrics);
Craig Mautner69b08182012-09-05 13:07:13 -0700124 isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700125 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700126 initializeDisplayBaseInfo();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700127 mDividerControllerLocked = new DockedStackDividerController(service.mContext, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800128 mDimLayerController = new DimLayerController(this);
Craig Mautner59c00972012-07-30 12:10:24 -0700129 }
130
131 int getDisplayId() {
132 return mDisplayId;
133 }
134
135 WindowList getWindowList() {
136 return mWindows;
137 }
138
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700139 Display getDisplay() {
140 return mDisplay;
141 }
142
Craig Mautner59c00972012-07-30 12:10:24 -0700143 DisplayInfo getDisplayInfo() {
144 return mDisplayInfo;
145 }
146
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700147 DisplayMetrics getDisplayMetrics() {
148 return mDisplayMetrics;
149 }
150
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100151 DockedStackDividerController getDockedDividerController() {
152 return mDividerControllerLocked;
153 }
154
Jeff Browna506a6e2013-06-04 00:02:38 -0700155 /**
156 * Returns true if the specified UID has access to this display.
157 */
158 public boolean hasAccess(int uid) {
159 return mDisplay.hasAccess(uid);
160 }
161
keunyounga446bf02013-06-21 19:07:57 -0700162 public boolean isPrivate() {
163 return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
164 }
165
Craig Mautnerdc548482014-02-05 13:35:24 -0800166 ArrayList<TaskStack> getStacks() {
167 return mStacks;
168 }
169
Craig Mautner00af9fe2013-03-25 09:13:41 -0700170 /**
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700171 * Retrieve the tasks on this display in stack order from the bottommost TaskStack up.
Craig Mautner00af9fe2013-03-25 09:13:41 -0700172 * @return All the Tasks, in order, on this display.
173 */
Craig Mautnerc00204b2013-03-05 15:02:14 -0800174 ArrayList<Task> getTasks() {
Craig Mautnerdc548482014-02-05 13:35:24 -0800175 mTmpTaskHistory.clear();
176 final int numStacks = mStacks.size();
177 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
178 mTmpTaskHistory.addAll(mStacks.get(stackNdx).getTasks());
Craig Mautnerd9a22882013-03-16 15:00:36 -0700179 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800180 return mTmpTaskHistory;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800181 }
182
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700183 TaskStack getHomeStack() {
Craig Mautner333c2ec2014-10-02 12:24:02 -0700184 if (mHomeStack == null && mDisplayId == Display.DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800185 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -0800186 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700187 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700188 }
189
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700190 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700191 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700192 mDisplay.getMetrics(mDisplayMetrics);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800193 for (int i = mStacks.size() - 1; i >= 0; --i) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700194 mStacks.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800195 }
Craig Mautner722285e2012-09-07 13:55:58 -0700196 }
197
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700198 void initializeDisplayBaseInfo() {
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800199 // Bootstrap the default logical display from the display manager.
200 final DisplayInfo newDisplayInfo =
201 mService.mDisplayManagerInternal.getDisplayInfo(mDisplayId);
202 if (newDisplayInfo != null) {
203 mDisplayInfo.copyFrom(newDisplayInfo);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700204 }
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800205 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
206 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
207 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
208 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700209 }
210
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700211 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700212 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800213 final int orientation = mDisplayInfo.rotation;
214 boolean rotated = (orientation == Surface.ROTATION_90
215 || orientation == Surface.ROTATION_270);
216 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
217 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700218 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800219 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700220 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800221 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700222 out.set(left, top, left + width, top + height);
223 }
224
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700225 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
226 void attachStack(TaskStack stack, boolean onTop) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800227 if (stack.mStackId == HOME_STACK_ID) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800228 if (mHomeStack != null) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800229 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700230 }
Craig Mautnerdf88d732014-01-27 09:21:32 -0800231 mHomeStack = stack;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800232 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700233 if (onTop) {
234 mStacks.add(stack);
235 } else {
236 mStacks.add(0, stack);
237 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800238 layoutNeeded = true;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800239 }
240
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800241 void moveStack(TaskStack stack, boolean toTop) {
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800242 if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
243 // This stack is always-on-top silly...
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800244 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700245 return;
246 }
247
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700248 if (!mStacks.remove(stack)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800249 Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700250 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700251
252 int addIndex = toTop ? mStacks.size() : 0;
253
254 if (toTop
255 && mService.isStackVisibleLocked(PINNED_STACK_ID)
256 && stack.mStackId != PINNED_STACK_ID) {
257 // The pinned stack is always the top most stack (always-on-top) when it is visible.
258 // So, stack is moved just below the pinned stack.
259 addIndex--;
260 TaskStack topStack = mStacks.get(addIndex);
261 if (topStack.mStackId != PINNED_STACK_ID) {
262 throw new IllegalStateException("Pinned stack isn't top stack??? " + mStacks);
263 }
264 }
265 mStacks.add(addIndex, stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800266 }
267
Craig Mautnerdf88d732014-01-27 09:21:32 -0800268 void detachStack(TaskStack stack) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800269 mDimLayerController.removeDimLayerUser(stack);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800270 mStacks.remove(stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800271 }
272
273 /**
274 * Propagate the new bounds to all child stacks.
275 * @param contentRect The bounds to apply at the top level.
276 */
277 void resize(Rect contentRect) {
278 mContentRect.set(contentRect);
279 }
280
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700281 int taskIdFromPoint(int x, int y) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800282 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800283 TaskStack stack = mStacks.get(stackNdx);
284 stack.getBounds(mTmpRect);
285 if (!mTmpRect.contains(x, y)) {
286 continue;
287 }
288 final ArrayList<Task> tasks = stack.getTasks();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700289 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
290 final Task task = tasks.get(taskNdx);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800291 final WindowState win = task.getTopVisibleAppMainWindow();
292 if (win == null) {
293 continue;
294 }
295 // We need to use the task's dim bounds (which is derived from the visible
296 // bounds of its apps windows) for any touch-related tests. Can't use
297 // the task's original bounds because it might be adjusted to fit the
298 // content frame. For example, the presence of the IME adjusting the
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700299 // windows frames when the app window is the IME target.
Chong Zhangd8ceb852015-11-11 14:53:41 -0800300 task.getDimBounds(mTmpRect);
301 if (mTmpRect.contains(x, y)) {
302 return task.mTaskId;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700303 }
Craig Mautner967212c2013-04-13 21:10:58 -0700304 }
305 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800306 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700307 }
308
Chong Zhang8e89b312015-09-09 15:09:30 -0700309 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -0800310 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -0700311 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700312 */
Chong Zhangd8ceb852015-11-11 14:53:41 -0800313 Task findTaskForControlPoint(int x, int y) {
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700314 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhang8e89b312015-09-09 15:09:30 -0700315 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
316 TaskStack stack = mStacks.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700317 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700318 break;
319 }
320 final ArrayList<Task> tasks = stack.getTasks();
321 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
322 final Task task = tasks.get(taskNdx);
323 if (task.isFullscreen()) {
Chong Zhang9184ec62015-09-24 12:32:21 -0700324 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700325 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700326
Chong Zhangd8ceb852015-11-11 14:53:41 -0800327 // We need to use the task's dim bounds (which is derived from the visible
328 // bounds of its apps windows) for any touch-related tests. Can't use
329 // the task's original bounds because it might be adjusted to fit the
330 // content frame. One example is when the task is put to top-left quadrant,
331 // the actual visible area would not start at (0,0) after it's adjusted
332 // for the status bar.
333 task.getDimBounds(mTmpRect);
334 mTmpRect.inset(-delta, -delta);
335 if (mTmpRect.contains(x, y)) {
336 mTmpRect.inset(delta, delta);
337 if (!mTmpRect.contains(x, y)) {
338 return task;
Chong Zhang8e89b312015-09-09 15:09:30 -0700339 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800340 // User touched inside the task. No need to look further,
341 // focus transfer will be handled in ACTION_UP.
342 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700343 }
344 }
345 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700346 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700347 }
348
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700349 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700350 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700351 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800352 boolean addBackFocusedTask = false;
Chong Zhangb15758a2015-11-17 12:12:03 -0800353 mNonResizeableRegion.setEmpty();
Chong Zhangd8ceb852015-11-11 14:53:41 -0800354 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
355 TaskStack stack = mStacks.get(stackNdx);
356 final ArrayList<Task> tasks = stack.getTasks();
357 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
358 final Task task = tasks.get(taskNdx);
359 final WindowState win = task.getTopVisibleAppMainWindow();
360 if (win == null) {
361 continue;
362 }
363
Chong Zhang8e89b312015-09-09 15:09:30 -0700364 /**
365 * Exclusion region is the region that TapDetector doesn't care about.
366 * Here we want to remove all non-focused tasks from the exclusion region.
367 * We also remove the outside touch area for resizing for all freeform
368 * tasks (including the focused).
369 *
370 * (For freeform focused task, the below logic will first remove the enlarged
371 * area, then add back the inner area.)
372 */
Chong Zhang09b21ef2015-09-14 10:20:21 -0700373 final boolean isFreeformed = task.inFreeformWorkspace();
Chong Zhang8e89b312015-09-09 15:09:30 -0700374 if (task != focusedTask || isFreeformed) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800375 task.getDimBounds(mTmpRect);
Chong Zhang8e89b312015-09-09 15:09:30 -0700376 if (isFreeformed) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800377 // If we're removing a freeform, focused app from the exclusion region,
378 // we need to add back its touchable frame later. Remember the touchable
379 // frame now.
380 if (task == focusedTask) {
381 addBackFocusedTask = true;
382 mTmpRect2.set(mTmpRect);
383 }
384 // If the task is freeformed, enlarge the area to account for outside
385 // touch area for resize.
Chong Zhang8e89b312015-09-09 15:09:30 -0700386 mTmpRect.inset(-delta, -delta);
Chong Zhang73c3fcf2015-11-05 13:18:33 -0800387 // Intersect with display content rect. If we have system decor (status bar/
388 // navigation bar), we want to exclude that from the tap detection.
389 // Otherwise, if the app is partially placed under some system button (eg.
390 // Recents, Home), pressing that button would cause a full series of
391 // unwanted transfer focus/resume/pause, before we could go home.
392 mTmpRect.intersect(mContentRect);
Chong Zhang8e89b312015-09-09 15:09:30 -0700393 }
394 mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
395 }
Chong Zhang2a88fc32016-01-11 17:14:24 -0800396 if (task.isTwoFingerScrollMode()) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800397 stack.getBounds(mTmpRect);
398 mNonResizeableRegion.op(mTmpRect, Region.Op.UNION);
399 break;
400 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700401 }
402 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800403 // If we removed the focused task above, add it back and only leave its
404 // outside touch area in the exclusion. TapDectector is not interested in
405 // any touch inside the focused task itself.
406 if (addBackFocusedTask) {
407 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
408 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800409 final WindowState inputMethod = mService.mInputMethodWindow;
410 if (inputMethod != null && inputMethod.isVisibleLw()) {
411 // If the input method is visible and the user is typing, we don't want these touch
412 // events to be intercepted and used to change focus. This would likely cause a
413 // disappearance of the input method.
414 inputMethod.getTouchableRegion(mTmpRegion);
415 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
416 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800417 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
418 WindowState win = mTapExcludedWindows.get(i);
419 win.getTouchableRegion(mTmpRegion);
420 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
421 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800422 if (mTapDetector != null) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800423 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion, mNonResizeableRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -0800424 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700425 }
426
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800427 void switchUserStacks() {
Craig Mautner858d8a62013-04-23 17:08:34 -0700428 final WindowList windows = getWindowList();
429 for (int i = 0; i < windows.size(); i++) {
430 final WindowState win = windows.get(i);
431 if (win.isHiddenFromUserLocked()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800432 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800433 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700434 win.hideLw(false);
435 }
436 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700437
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800438 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800439 mStacks.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700440 }
441 }
442
Craig Mautner05d29032013-05-03 13:40:13 -0700443 void resetAnimationBackgroundAnimator() {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800444 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
445 mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700446 }
447 }
448
449 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800450 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700451 }
452
453 void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800454 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700455 }
456
457 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800458 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700459 }
460
461 void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800462 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700463 }
464
Craig Mautner2eb15342013-08-07 13:13:35 -0700465 void close() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800466 mDimLayerController.close();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800467 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
468 mStacks.get(stackNdx).close();
Craig Mautner2eb15342013-08-07 13:13:35 -0700469 }
470 }
471
Craig Mautner95da1082014-02-24 17:54:35 -0800472 boolean isAnimating() {
473 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
474 final TaskStack stack = mStacks.get(stackNdx);
475 if (stack.isAnimating()) {
476 return true;
477 }
478 }
479 return false;
480 }
481
482 void checkForDeferredActions() {
483 boolean animating = false;
484 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
485 final TaskStack stack = mStacks.get(stackNdx);
486 if (stack.isAnimating()) {
487 animating = true;
488 } else {
489 if (stack.mDeferDetach) {
490 mService.detachStackLocked(this, stack);
491 }
492 final ArrayList<Task> tasks = stack.getTasks();
493 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
494 final Task task = tasks.get(taskNdx);
495 AppTokenList tokens = task.mAppTokens;
496 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
497 AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800498 if (wtoken.mIsExiting) {
Craig Mautnere3119b72015-01-20 15:02:36 -0800499 wtoken.removeAppFromTaskLocked();
Craig Mautner95da1082014-02-24 17:54:35 -0800500 }
501 }
Craig Mautner95da1082014-02-24 17:54:35 -0800502 }
503 }
504 }
505 if (!animating && mDeferredRemoval) {
506 mService.onDisplayRemoved(mDisplayId);
507 }
508 }
509
Wale Ogunwale94744212015-09-21 19:01:47 -0700510 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
511 final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation);
512 getLogicalDisplayRect(mTmpRect);
513 switch (rotationDelta) {
514 case Surface.ROTATION_0:
515 mTmpRect2.set(bounds);
516 break;
517 case Surface.ROTATION_90:
518 mTmpRect2.top = mTmpRect.bottom - bounds.right;
519 mTmpRect2.left = bounds.top;
520 mTmpRect2.right = mTmpRect2.left + bounds.height();
521 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
522 break;
523 case Surface.ROTATION_180:
524 mTmpRect2.top = mTmpRect.bottom - bounds.bottom;
525 mTmpRect2.left = mTmpRect.right - bounds.right;
526 mTmpRect2.right = mTmpRect2.left + bounds.width();
527 mTmpRect2.bottom = mTmpRect2.top + bounds.height();
528 break;
529 case Surface.ROTATION_270:
530 mTmpRect2.top = bounds.left;
531 mTmpRect2.left = mTmpRect.right - bounds.bottom;
532 mTmpRect2.right = mTmpRect2.left + bounds.height();
533 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
534 break;
535 }
536 bounds.set(mTmpRect2);
537 }
538
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800539 static int deltaRotation(int oldRotation, int newRotation) {
540 int delta = newRotation - oldRotation;
541 if (delta < 0) delta += 4;
542 return delta;
543 }
544
Craig Mautnera91f9e22012-09-14 16:22:08 -0700545 public void dump(String prefix, PrintWriter pw) {
546 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
547 final String subPrefix = " " + prefix;
548 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
549 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
550 pw.print("dpi");
551 if (mInitialDisplayWidth != mBaseDisplayWidth
552 || mInitialDisplayHeight != mBaseDisplayHeight
553 || mInitialDisplayDensity != mBaseDisplayDensity) {
554 pw.print(" base=");
555 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
556 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
557 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700558 if (mDisplayScalingDisabled) {
559 pw.println(" noscale");
560 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700561 pw.print(" cur=");
562 pw.print(mDisplayInfo.logicalWidth);
563 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
564 pw.print(" app=");
565 pw.print(mDisplayInfo.appWidth);
566 pw.print("x"); pw.print(mDisplayInfo.appHeight);
567 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
568 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
569 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
570 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Craig Mautner95da1082014-02-24 17:54:35 -0800571 pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval);
572 pw.print(" layoutNeeded="); pw.println(layoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800573
Craig Mautnerdc548482014-02-05 13:35:24 -0800574 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700575 pw.println(" Application tokens in top down Z order:");
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700576 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800577 final TaskStack stack = mStacks.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800578 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700579 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800580
Craig Mautnerdc548482014-02-05 13:35:24 -0800581 pw.println();
582 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700583 pw.println();
584 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800585 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700586 WindowToken token = mExitingTokens.get(i);
587 pw.print(" Exiting #"); pw.print(i);
588 pw.print(' '); pw.print(token);
589 pw.println(':');
590 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800591 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700592 }
Craig Mautner59c00972012-07-30 12:10:24 -0700593 pw.println();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800594 mDimLayerController.dump(prefix + " ", pw);
Craig Mautner59c00972012-07-30 12:10:24 -0700595 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800596
597 @Override
598 public String toString() {
599 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
600 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700601
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700602 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700603 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
604 return (stack != null && stack.isVisibleLocked()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700605 }
Craig Mautner59c00972012-07-30 12:10:24 -0700606}