blob: 4bbf586388961cddddf1d47384ae33ec7b64a34e [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;
Craig Mautner858d8a62013-04-23 17:08:34 -070022import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
Craig Mautnerde4ef022013-04-07 19:01:33 -070023import static com.android.server.wm.WindowManagerService.TAG;
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
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800113 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700114 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800115 * @param service You know.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700116 */
Craig Mautner9d808b12013-08-06 18:00:25 -0700117 DisplayContent(Display display, WindowManagerService service) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700118 mDisplay = display;
119 mDisplayId = display.getDisplayId();
120 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700121 display.getMetrics(mDisplayMetrics);
Craig Mautner69b08182012-09-05 13:07:13 -0700122 isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700123 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700124 initializeDisplayBaseInfo();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700125 mDividerControllerLocked = new DockedStackDividerController(service.mContext, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800126 mDimLayerController = new DimLayerController(this);
Craig Mautner59c00972012-07-30 12:10:24 -0700127 }
128
129 int getDisplayId() {
130 return mDisplayId;
131 }
132
133 WindowList getWindowList() {
134 return mWindows;
135 }
136
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700137 Display getDisplay() {
138 return mDisplay;
139 }
140
Craig Mautner59c00972012-07-30 12:10:24 -0700141 DisplayInfo getDisplayInfo() {
142 return mDisplayInfo;
143 }
144
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700145 DisplayMetrics getDisplayMetrics() {
146 return mDisplayMetrics;
147 }
148
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100149 DockedStackDividerController getDockedDividerController() {
150 return mDividerControllerLocked;
151 }
152
Jeff Browna506a6e2013-06-04 00:02:38 -0700153 /**
154 * Returns true if the specified UID has access to this display.
155 */
156 public boolean hasAccess(int uid) {
157 return mDisplay.hasAccess(uid);
158 }
159
keunyounga446bf02013-06-21 19:07:57 -0700160 public boolean isPrivate() {
161 return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
162 }
163
Craig Mautnerdc548482014-02-05 13:35:24 -0800164 ArrayList<TaskStack> getStacks() {
165 return mStacks;
166 }
167
Craig Mautner00af9fe2013-03-25 09:13:41 -0700168 /**
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700169 * Retrieve the tasks on this display in stack order from the bottommost TaskStack up.
Craig Mautner00af9fe2013-03-25 09:13:41 -0700170 * @return All the Tasks, in order, on this display.
171 */
Craig Mautnerc00204b2013-03-05 15:02:14 -0800172 ArrayList<Task> getTasks() {
Craig Mautnerdc548482014-02-05 13:35:24 -0800173 mTmpTaskHistory.clear();
174 final int numStacks = mStacks.size();
175 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
176 mTmpTaskHistory.addAll(mStacks.get(stackNdx).getTasks());
Craig Mautnerd9a22882013-03-16 15:00:36 -0700177 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800178 return mTmpTaskHistory;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800179 }
180
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700181 TaskStack getHomeStack() {
Craig Mautner333c2ec2014-10-02 12:24:02 -0700182 if (mHomeStack == null && mDisplayId == Display.DEFAULT_DISPLAY) {
Craig Mautnere0a38842013-12-16 16:14:02 -0800183 Slog.e(TAG, "getHomeStack: Returning null from this=" + this);
184 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700185 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700186 }
187
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700188 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700189 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700190 mDisplay.getMetrics(mDisplayMetrics);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800191 for (int i = mStacks.size() - 1; i >= 0; --i) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700192 mStacks.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800193 }
Craig Mautner722285e2012-09-07 13:55:58 -0700194 }
195
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700196 void initializeDisplayBaseInfo() {
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800197 // Bootstrap the default logical display from the display manager.
198 final DisplayInfo newDisplayInfo =
199 mService.mDisplayManagerInternal.getDisplayInfo(mDisplayId);
200 if (newDisplayInfo != null) {
201 mDisplayInfo.copyFrom(newDisplayInfo);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700202 }
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800203 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
204 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
205 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
206 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700207 }
208
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700209 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700210 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800211 final int orientation = mDisplayInfo.rotation;
212 boolean rotated = (orientation == Surface.ROTATION_90
213 || orientation == Surface.ROTATION_270);
214 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
215 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700216 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800217 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700218 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800219 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700220 out.set(left, top, left + width, top + height);
221 }
222
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700223 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
224 void attachStack(TaskStack stack, boolean onTop) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800225 if (stack.mStackId == HOME_STACK_ID) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800226 if (mHomeStack != null) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800227 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700228 }
Craig Mautnerdf88d732014-01-27 09:21:32 -0800229 mHomeStack = stack;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800230 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700231 if (onTop) {
232 mStacks.add(stack);
233 } else {
234 mStacks.add(0, stack);
235 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800236 layoutNeeded = true;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800237 }
238
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800239 void moveStack(TaskStack stack, boolean toTop) {
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700240 if (stack.mStackId == PINNED_STACK_ID && !toTop) {
241 // Pinned stack is always-on-top silly...
242 Slog.w(TAG, "Ignoring move of always-on-top stack=" + stack + " to bottom");
243 return;
244 }
245
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700246 if (!mStacks.remove(stack)) {
247 Slog.wtf(TAG, "moving stack that was not added: " + stack, new Throwable());
248 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700249
250 int addIndex = toTop ? mStacks.size() : 0;
251
252 if (toTop
253 && mService.isStackVisibleLocked(PINNED_STACK_ID)
254 && stack.mStackId != PINNED_STACK_ID) {
255 // The pinned stack is always the top most stack (always-on-top) when it is visible.
256 // So, stack is moved just below the pinned stack.
257 addIndex--;
258 TaskStack topStack = mStacks.get(addIndex);
259 if (topStack.mStackId != PINNED_STACK_ID) {
260 throw new IllegalStateException("Pinned stack isn't top stack??? " + mStacks);
261 }
262 }
263 mStacks.add(addIndex, stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800264 }
265
Craig Mautnerdf88d732014-01-27 09:21:32 -0800266 void detachStack(TaskStack stack) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800267 mDimLayerController.removeDimLayerUser(stack);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800268 mStacks.remove(stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800269 }
270
271 /**
272 * Propagate the new bounds to all child stacks.
273 * @param contentRect The bounds to apply at the top level.
274 */
275 void resize(Rect contentRect) {
276 mContentRect.set(contentRect);
277 }
278
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700279 int taskIdFromPoint(int x, int y) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800280 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800281 TaskStack stack = mStacks.get(stackNdx);
282 stack.getBounds(mTmpRect);
283 if (!mTmpRect.contains(x, y)) {
284 continue;
285 }
286 final ArrayList<Task> tasks = stack.getTasks();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700287 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
288 final Task task = tasks.get(taskNdx);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800289 final WindowState win = task.getTopVisibleAppMainWindow();
290 if (win == null) {
291 continue;
292 }
293 // We need to use the task's dim bounds (which is derived from the visible
294 // bounds of its apps windows) for any touch-related tests. Can't use
295 // the task's original bounds because it might be adjusted to fit the
296 // content frame. For example, the presence of the IME adjusting the
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700297 // windows frames when the app window is the IME target.
Chong Zhangd8ceb852015-11-11 14:53:41 -0800298 task.getDimBounds(mTmpRect);
299 if (mTmpRect.contains(x, y)) {
300 return task.mTaskId;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700301 }
Craig Mautner967212c2013-04-13 21:10:58 -0700302 }
303 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800304 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700305 }
306
Chong Zhang8e89b312015-09-09 15:09:30 -0700307 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -0800308 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -0700309 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700310 */
Chong Zhangd8ceb852015-11-11 14:53:41 -0800311 Task findTaskForControlPoint(int x, int y) {
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700312 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhang8e89b312015-09-09 15:09:30 -0700313 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
314 TaskStack stack = mStacks.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700315 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700316 break;
317 }
318 final ArrayList<Task> tasks = stack.getTasks();
319 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
320 final Task task = tasks.get(taskNdx);
321 if (task.isFullscreen()) {
Chong Zhang9184ec62015-09-24 12:32:21 -0700322 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700323 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700324
Chong Zhangd8ceb852015-11-11 14:53:41 -0800325 // We need to use the task's dim bounds (which is derived from the visible
326 // bounds of its apps windows) for any touch-related tests. Can't use
327 // the task's original bounds because it might be adjusted to fit the
328 // content frame. One example is when the task is put to top-left quadrant,
329 // the actual visible area would not start at (0,0) after it's adjusted
330 // for the status bar.
331 task.getDimBounds(mTmpRect);
332 mTmpRect.inset(-delta, -delta);
333 if (mTmpRect.contains(x, y)) {
334 mTmpRect.inset(delta, delta);
335 if (!mTmpRect.contains(x, y)) {
336 return task;
Chong Zhang8e89b312015-09-09 15:09:30 -0700337 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800338 // User touched inside the task. No need to look further,
339 // focus transfer will be handled in ACTION_UP.
340 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700341 }
342 }
343 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700344 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700345 }
346
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700347 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700348 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700349 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800350 boolean addBackFocusedTask = false;
Chong Zhangb15758a2015-11-17 12:12:03 -0800351 mNonResizeableRegion.setEmpty();
Chong Zhangd8ceb852015-11-11 14:53:41 -0800352 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
353 TaskStack stack = mStacks.get(stackNdx);
354 final ArrayList<Task> tasks = stack.getTasks();
355 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
356 final Task task = tasks.get(taskNdx);
357 final WindowState win = task.getTopVisibleAppMainWindow();
358 if (win == null) {
359 continue;
360 }
361
Chong Zhang8e89b312015-09-09 15:09:30 -0700362 /**
363 * Exclusion region is the region that TapDetector doesn't care about.
364 * Here we want to remove all non-focused tasks from the exclusion region.
365 * We also remove the outside touch area for resizing for all freeform
366 * tasks (including the focused).
367 *
368 * (For freeform focused task, the below logic will first remove the enlarged
369 * area, then add back the inner area.)
370 */
Chong Zhang09b21ef2015-09-14 10:20:21 -0700371 final boolean isFreeformed = task.inFreeformWorkspace();
Chong Zhang8e89b312015-09-09 15:09:30 -0700372 if (task != focusedTask || isFreeformed) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800373 task.getDimBounds(mTmpRect);
Chong Zhang8e89b312015-09-09 15:09:30 -0700374 if (isFreeformed) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800375 // If we're removing a freeform, focused app from the exclusion region,
376 // we need to add back its touchable frame later. Remember the touchable
377 // frame now.
378 if (task == focusedTask) {
379 addBackFocusedTask = true;
380 mTmpRect2.set(mTmpRect);
381 }
382 // If the task is freeformed, enlarge the area to account for outside
383 // touch area for resize.
Chong Zhang8e89b312015-09-09 15:09:30 -0700384 mTmpRect.inset(-delta, -delta);
Chong Zhang73c3fcf2015-11-05 13:18:33 -0800385 // Intersect with display content rect. If we have system decor (status bar/
386 // navigation bar), we want to exclude that from the tap detection.
387 // Otherwise, if the app is partially placed under some system button (eg.
388 // Recents, Home), pressing that button would cause a full series of
389 // unwanted transfer focus/resume/pause, before we could go home.
390 mTmpRect.intersect(mContentRect);
Chong Zhang8e89b312015-09-09 15:09:30 -0700391 }
392 mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
393 }
Chong Zhangb15758a2015-11-17 12:12:03 -0800394 if (task.isDockedInEffect() && !task.isResizeable()) {
395 stack.getBounds(mTmpRect);
396 mNonResizeableRegion.op(mTmpRect, Region.Op.UNION);
397 break;
398 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700399 }
400 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800401 // If we removed the focused task above, add it back and only leave its
402 // outside touch area in the exclusion. TapDectector is not interested in
403 // any touch inside the focused task itself.
404 if (addBackFocusedTask) {
405 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
406 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800407 final WindowState inputMethod = mService.mInputMethodWindow;
408 if (inputMethod != null && inputMethod.isVisibleLw()) {
409 // If the input method is visible and the user is typing, we don't want these touch
410 // events to be intercepted and used to change focus. This would likely cause a
411 // disappearance of the input method.
412 inputMethod.getTouchableRegion(mTmpRegion);
413 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
414 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800415 if (mTapDetector != null) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800416 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion, mNonResizeableRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -0800417 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700418 }
419
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800420 void switchUserStacks() {
Craig Mautner858d8a62013-04-23 17:08:34 -0700421 final WindowList windows = getWindowList();
422 for (int i = 0; i < windows.size(); i++) {
423 final WindowState win = windows.get(i);
424 if (win.isHiddenFromUserLocked()) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800425 if (DEBUG_VISIBILITY) Slog.w(TAG, "user changing, hiding " + win
426 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700427 win.hideLw(false);
428 }
429 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700430
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800431 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800432 mStacks.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700433 }
434 }
435
Craig Mautner05d29032013-05-03 13:40:13 -0700436 void resetAnimationBackgroundAnimator() {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800437 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
438 mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700439 }
440 }
441
442 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800443 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700444 }
445
446 void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800447 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700448 }
449
450 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800451 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700452 }
453
454 void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800455 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700456 }
457
Craig Mautner2eb15342013-08-07 13:13:35 -0700458 void close() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800459 mDimLayerController.close();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800460 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
461 mStacks.get(stackNdx).close();
Craig Mautner2eb15342013-08-07 13:13:35 -0700462 }
463 }
464
Craig Mautner95da1082014-02-24 17:54:35 -0800465 boolean isAnimating() {
466 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
467 final TaskStack stack = mStacks.get(stackNdx);
468 if (stack.isAnimating()) {
469 return true;
470 }
471 }
472 return false;
473 }
474
475 void checkForDeferredActions() {
476 boolean animating = false;
477 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
478 final TaskStack stack = mStacks.get(stackNdx);
479 if (stack.isAnimating()) {
480 animating = true;
481 } else {
482 if (stack.mDeferDetach) {
483 mService.detachStackLocked(this, stack);
484 }
485 final ArrayList<Task> tasks = stack.getTasks();
486 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
487 final Task task = tasks.get(taskNdx);
488 AppTokenList tokens = task.mAppTokens;
489 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
490 AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800491 if (wtoken.mIsExiting) {
Craig Mautnere3119b72015-01-20 15:02:36 -0800492 wtoken.removeAppFromTaskLocked();
Craig Mautner95da1082014-02-24 17:54:35 -0800493 }
494 }
Craig Mautner95da1082014-02-24 17:54:35 -0800495 }
496 }
497 }
498 if (!animating && mDeferredRemoval) {
499 mService.onDisplayRemoved(mDisplayId);
500 }
501 }
502
Wale Ogunwale94744212015-09-21 19:01:47 -0700503 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
504 final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation);
505 getLogicalDisplayRect(mTmpRect);
506 switch (rotationDelta) {
507 case Surface.ROTATION_0:
508 mTmpRect2.set(bounds);
509 break;
510 case Surface.ROTATION_90:
511 mTmpRect2.top = mTmpRect.bottom - bounds.right;
512 mTmpRect2.left = bounds.top;
513 mTmpRect2.right = mTmpRect2.left + bounds.height();
514 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
515 break;
516 case Surface.ROTATION_180:
517 mTmpRect2.top = mTmpRect.bottom - bounds.bottom;
518 mTmpRect2.left = mTmpRect.right - bounds.right;
519 mTmpRect2.right = mTmpRect2.left + bounds.width();
520 mTmpRect2.bottom = mTmpRect2.top + bounds.height();
521 break;
522 case Surface.ROTATION_270:
523 mTmpRect2.top = bounds.left;
524 mTmpRect2.left = mTmpRect.right - bounds.bottom;
525 mTmpRect2.right = mTmpRect2.left + bounds.height();
526 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
527 break;
528 }
529 bounds.set(mTmpRect2);
530 }
531
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800532 static int deltaRotation(int oldRotation, int newRotation) {
533 int delta = newRotation - oldRotation;
534 if (delta < 0) delta += 4;
535 return delta;
536 }
537
Craig Mautnera91f9e22012-09-14 16:22:08 -0700538 public void dump(String prefix, PrintWriter pw) {
539 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
540 final String subPrefix = " " + prefix;
541 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
542 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
543 pw.print("dpi");
544 if (mInitialDisplayWidth != mBaseDisplayWidth
545 || mInitialDisplayHeight != mBaseDisplayHeight
546 || mInitialDisplayDensity != mBaseDisplayDensity) {
547 pw.print(" base=");
548 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
549 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
550 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700551 if (mDisplayScalingDisabled) {
552 pw.println(" noscale");
553 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700554 pw.print(" cur=");
555 pw.print(mDisplayInfo.logicalWidth);
556 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
557 pw.print(" app=");
558 pw.print(mDisplayInfo.appWidth);
559 pw.print("x"); pw.print(mDisplayInfo.appHeight);
560 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
561 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
562 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
563 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Craig Mautner95da1082014-02-24 17:54:35 -0800564 pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval);
565 pw.print(" layoutNeeded="); pw.println(layoutNeeded);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800566 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
567 final TaskStack stack = mStacks.get(stackNdx);
568 pw.print(prefix); pw.print("mStacks[" + stackNdx + "]"); pw.println(stack.mStackId);
569 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700570 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800571 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700572 pw.println(" Application tokens in top down Z order:");
Craig Mautnerdc548482014-02-05 13:35:24 -0800573 int ndx = 0;
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700574 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800575 final TaskStack stack = mStacks.get(stackNdx);
576 pw.print(" mStackId="); pw.println(stack.mStackId);
577 ArrayList<Task> tasks = stack.getTasks();
Craig Mautnerdc548482014-02-05 13:35:24 -0800578 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800579 final Task task = tasks.get(taskNdx);
Craig Mautner83162a92015-01-26 14:43:30 -0800580 pw.print(" mTaskId="); pw.println(task.mTaskId);
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800581 AppTokenList tokens = task.mAppTokens;
582 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx, ++ndx) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700583 final AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800584 pw.print(" Activity #"); pw.print(tokenNdx);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700585 pw.print(' '); pw.print(wtoken); pw.println(":");
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800586 wtoken.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800587 }
588 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700589 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800590 if (ndx == 0) {
591 pw.println(" None");
592 }
593 pw.println();
594 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700595 pw.println();
596 pw.println(" Exiting tokens:");
597 for (int i=mExitingTokens.size()-1; i>=0; i--) {
598 WindowToken token = mExitingTokens.get(i);
599 pw.print(" Exiting #"); pw.print(i);
600 pw.print(' '); pw.print(token);
601 pw.println(':');
602 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800603 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700604 }
Craig Mautner59c00972012-07-30 12:10:24 -0700605 pw.println();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800606 mDimLayerController.dump(prefix + " ", pw);
Craig Mautner59c00972012-07-30 12:10:24 -0700607 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800608
609 @Override
610 public String toString() {
611 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
612 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700613
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700614 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700615 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
616 return (stack != null && stack.isVisibleLocked()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700617 }
Craig Mautner59c00972012-07-30 12:10:24 -0700618}