blob: 12399bd44b391b3725a7b36aa02b4e54ff952117 [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;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070025import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080026import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
27import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070028import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070029
Wale Ogunwale3797c222015-10-27 14:21:58 -070030import android.app.ActivityManager.StackId;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070031import android.content.pm.ApplicationInfo;
32import android.content.pm.PackageManager;
Craig Mautnerc00204b2013-03-05 15:02:14 -080033import android.graphics.Rect;
Craig Mautner6601b7b2013-04-29 10:29:11 -070034import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +010035import android.graphics.Region.Op;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070036import android.os.Build;
37import android.os.UserHandle;
Chong Zhang8e89b312015-09-09 15:09:30 -070038import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -070039import android.util.Slog;
Craig Mautnerb47bbc32012-08-22 17:41:48 -070040import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070041import android.view.DisplayInfo;
Craig Mautner4a1cb222013-12-04 16:14:06 -080042import android.view.Surface;
Jorim Jaggi6626f542016-08-22 13:08:44 -070043import android.view.animation.Animation;
Craig Mautner59c00972012-07-30 12:10:24 -070044
45import java.io.PrintWriter;
46import java.util.ArrayList;
47
48class DisplayContentList extends ArrayList<DisplayContent> {
49}
50
51/**
52 * Utility class for keeping track of the WindowStates and other pertinent contents of a
53 * particular Display.
54 *
55 * IMPORTANT: No method from this class should ever be used without holding
56 * WindowManagerService.mWindowMap.
57 */
58class DisplayContent {
59
60 /** Unique identifier of this stack. */
61 private final int mDisplayId;
62
63 /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
64 * from mDisplayWindows; */
Craig Mautnerdc548482014-02-05 13:35:24 -080065 private final WindowList mWindows = new WindowList();
Craig Mautner59c00972012-07-30 12:10:24 -070066
Craig Mautner59c00972012-07-30 12:10:24 -070067 int mInitialDisplayWidth = 0;
68 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070069 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -070070 int mBaseDisplayWidth = 0;
71 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070072 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -070073 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -070074 private final DisplayInfo mDisplayInfo = new DisplayInfo();
75 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070076 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -070077
Craig Mautner6601b7b2013-04-29 10:29:11 -070078 Rect mBaseDisplayRect = new Rect();
Craig Mautnerbdc748af2013-12-02 14:08:25 -080079 Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -070080
Craig Mautner39834192012-09-02 07:47:24 -070081 // Accessed directly by all users.
82 boolean layoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -070083 int pendingLayoutChanges;
Craig Mautner69b08182012-09-05 13:07:13 -070084 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -070085
Craig Mautnerdc548482014-02-05 13:35:24 -080086 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070087 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080088
Craig Mautnerbdc748af2013-12-02 14:08:25 -080089 /** Array containing all TaskStacks on this display. Array
Craig Mautnercf910b02013-04-23 11:23:27 -070090 * is stored in display order with the current bottom stack at 0. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070091 private final ArrayList<TaskStack> mStacks = new ArrayList<>();
Craig Mautnerc00204b2013-03-05 15:02:14 -080092
Craig Mautnerbdc748af2013-12-02 14:08:25 -080093 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
94 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -070095 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070096
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070097 /** Detect user tapping outside of current focused task bounds .*/
98 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -070099
Craig Mautner6601b7b2013-04-29 10:29:11 -0700100 /** Detect user tapping outside of current focused stack bounds .*/
101 Region mTouchExcludeRegion = new Region();
102
Chong Zhangb15758a2015-11-17 12:12:03 -0800103 /** Detect user tapping in a non-resizeable task in docked or fullscreen stack .*/
104 Region mNonResizeableRegion = new Region();
105
Craig Mautner6601b7b2013-04-29 10:29:11 -0700106 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800107 private final Rect mTmpRect = new Rect();
108 private final Rect mTmpRect2 = new Rect();
109 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700110
Craig Mautnerdc548482014-02-05 13:35:24 -0800111 /** For gathering Task objects in order. */
112 final ArrayList<Task> mTmpTaskHistory = new ArrayList<Task>();
113
Craig Mautner9d808b12013-08-06 18:00:25 -0700114 final WindowManagerService mService;
115
Craig Mautner95da1082014-02-24 17:54:35 -0800116 /** Remove this display when animation on it has completed. */
117 boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800118
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700119 final DockedStackDividerController mDividerControllerLocked;
120
Chong Zhang112eb8c2015-11-02 11:17:00 -0800121 final DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700122
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800123 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
124
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800125 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700126 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800127 * @param service You know.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700128 */
Craig Mautner9d808b12013-08-06 18:00:25 -0700129 DisplayContent(Display display, WindowManagerService service) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700130 mDisplay = display;
131 mDisplayId = display.getDisplayId();
132 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700133 display.getMetrics(mDisplayMetrics);
Craig Mautner69b08182012-09-05 13:07:13 -0700134 isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700135 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700136 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800137 mDividerControllerLocked = new DockedStackDividerController(service, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800138 mDimLayerController = new DimLayerController(this);
Craig Mautner59c00972012-07-30 12:10:24 -0700139 }
140
141 int getDisplayId() {
142 return mDisplayId;
143 }
144
145 WindowList getWindowList() {
146 return mWindows;
147 }
148
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700149 Display getDisplay() {
150 return mDisplay;
151 }
152
Craig Mautner59c00972012-07-30 12:10:24 -0700153 DisplayInfo getDisplayInfo() {
154 return mDisplayInfo;
155 }
156
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700157 DisplayMetrics getDisplayMetrics() {
158 return mDisplayMetrics;
159 }
160
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100161 DockedStackDividerController getDockedDividerController() {
162 return mDividerControllerLocked;
163 }
164
Jeff Browna506a6e2013-06-04 00:02:38 -0700165 /**
166 * Returns true if the specified UID has access to this display.
167 */
168 public boolean hasAccess(int uid) {
169 return mDisplay.hasAccess(uid);
170 }
171
keunyounga446bf02013-06-21 19:07:57 -0700172 public boolean isPrivate() {
173 return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
174 }
175
Craig Mautnerdc548482014-02-05 13:35:24 -0800176 ArrayList<TaskStack> getStacks() {
177 return mStacks;
178 }
179
Craig Mautner00af9fe2013-03-25 09:13:41 -0700180 /**
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700181 * Retrieve the tasks on this display in stack order from the bottommost TaskStack up.
Craig Mautner00af9fe2013-03-25 09:13:41 -0700182 * @return All the Tasks, in order, on this display.
183 */
Craig Mautnerc00204b2013-03-05 15:02:14 -0800184 ArrayList<Task> getTasks() {
Craig Mautnerdc548482014-02-05 13:35:24 -0800185 mTmpTaskHistory.clear();
186 final int numStacks = mStacks.size();
187 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
188 mTmpTaskHistory.addAll(mStacks.get(stackNdx).getTasks());
Craig Mautnerd9a22882013-03-16 15:00:36 -0700189 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800190 return mTmpTaskHistory;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800191 }
192
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700193 TaskStack getHomeStack() {
Craig Mautner333c2ec2014-10-02 12:24:02 -0700194 if (mHomeStack == null && mDisplayId == Display.DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800195 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -0800196 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700197 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700198 }
199
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700200 TaskStack getStackById(int stackId) {
201 for (int i = mStacks.size() - 1; i >= 0; --i) {
202 final TaskStack stack = mStacks.get(i);
203 if (stack.mStackId == stackId) {
204 return stack;
205 }
206 }
207 return null;
208 }
209
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700210 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700211 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700212 mDisplay.getMetrics(mDisplayMetrics);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800213 for (int i = mStacks.size() - 1; i >= 0; --i) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700214 mStacks.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800215 }
Craig Mautner722285e2012-09-07 13:55:58 -0700216 }
217
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700218 void initializeDisplayBaseInfo() {
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800219 // Bootstrap the default logical display from the display manager.
220 final DisplayInfo newDisplayInfo =
221 mService.mDisplayManagerInternal.getDisplayInfo(mDisplayId);
222 if (newDisplayInfo != null) {
223 mDisplayInfo.copyFrom(newDisplayInfo);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700224 }
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800225 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
226 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
227 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
228 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700229 }
230
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700231 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700232 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800233 final int orientation = mDisplayInfo.rotation;
234 boolean rotated = (orientation == Surface.ROTATION_90
235 || orientation == Surface.ROTATION_270);
236 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
237 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700238 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800239 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700240 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800241 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700242 out.set(left, top, left + width, top + height);
243 }
244
Chong Zhangf66db432016-01-13 10:39:51 -0800245 void getContentRect(Rect out) {
246 out.set(mContentRect);
247 }
248
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700249 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
250 void attachStack(TaskStack stack, boolean onTop) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800251 if (stack.mStackId == HOME_STACK_ID) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800252 if (mHomeStack != null) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800253 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700254 }
Craig Mautnerdf88d732014-01-27 09:21:32 -0800255 mHomeStack = stack;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800256 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700257 if (onTop) {
258 mStacks.add(stack);
259 } else {
260 mStacks.add(0, stack);
261 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800262 layoutNeeded = true;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800263 }
264
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800265 void moveStack(TaskStack stack, boolean toTop) {
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800266 if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
267 // This stack is always-on-top silly...
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800268 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700269 return;
270 }
271
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700272 if (!mStacks.remove(stack)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800273 Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700274 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700275
276 int addIndex = toTop ? mStacks.size() : 0;
277
278 if (toTop
279 && mService.isStackVisibleLocked(PINNED_STACK_ID)
280 && stack.mStackId != PINNED_STACK_ID) {
281 // The pinned stack is always the top most stack (always-on-top) when it is visible.
282 // So, stack is moved just below the pinned stack.
283 addIndex--;
284 TaskStack topStack = mStacks.get(addIndex);
285 if (topStack.mStackId != PINNED_STACK_ID) {
286 throw new IllegalStateException("Pinned stack isn't top stack??? " + mStacks);
287 }
288 }
289 mStacks.add(addIndex, stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800290 }
291
Craig Mautnerdf88d732014-01-27 09:21:32 -0800292 void detachStack(TaskStack stack) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800293 mDimLayerController.removeDimLayerUser(stack);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800294 mStacks.remove(stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800295 }
296
297 /**
298 * Propagate the new bounds to all child stacks.
299 * @param contentRect The bounds to apply at the top level.
300 */
301 void resize(Rect contentRect) {
302 mContentRect.set(contentRect);
303 }
304
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700305 int taskIdFromPoint(int x, int y) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800306 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800307 TaskStack stack = mStacks.get(stackNdx);
308 stack.getBounds(mTmpRect);
Jorim Jaggib72c9ad2016-04-11 18:27:58 -0700309 if (!mTmpRect.contains(x, y) || stack.isAdjustedForMinimizedDockedStack()) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800310 continue;
311 }
312 final ArrayList<Task> tasks = stack.getTasks();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700313 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
314 final Task task = tasks.get(taskNdx);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800315 final WindowState win = task.getTopVisibleAppMainWindow();
316 if (win == null) {
317 continue;
318 }
319 // We need to use the task's dim bounds (which is derived from the visible
320 // bounds of its apps windows) for any touch-related tests. Can't use
321 // the task's original bounds because it might be adjusted to fit the
322 // content frame. For example, the presence of the IME adjusting the
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700323 // windows frames when the app window is the IME target.
Chong Zhangd8ceb852015-11-11 14:53:41 -0800324 task.getDimBounds(mTmpRect);
325 if (mTmpRect.contains(x, y)) {
326 return task.mTaskId;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700327 }
Craig Mautner967212c2013-04-13 21:10:58 -0700328 }
329 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800330 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700331 }
332
Chong Zhang8e89b312015-09-09 15:09:30 -0700333 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -0800334 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -0700335 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700336 */
Chong Zhangd8ceb852015-11-11 14:53:41 -0800337 Task findTaskForControlPoint(int x, int y) {
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700338 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhang8e89b312015-09-09 15:09:30 -0700339 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
340 TaskStack stack = mStacks.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700341 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700342 break;
343 }
344 final ArrayList<Task> tasks = stack.getTasks();
345 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
346 final Task task = tasks.get(taskNdx);
347 if (task.isFullscreen()) {
Chong Zhang9184ec62015-09-24 12:32:21 -0700348 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700349 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700350
Chong Zhangd8ceb852015-11-11 14:53:41 -0800351 // We need to use the task's dim bounds (which is derived from the visible
352 // bounds of its apps windows) for any touch-related tests. Can't use
353 // the task's original bounds because it might be adjusted to fit the
354 // content frame. One example is when the task is put to top-left quadrant,
355 // the actual visible area would not start at (0,0) after it's adjusted
356 // for the status bar.
357 task.getDimBounds(mTmpRect);
358 mTmpRect.inset(-delta, -delta);
359 if (mTmpRect.contains(x, y)) {
360 mTmpRect.inset(delta, delta);
361 if (!mTmpRect.contains(x, y)) {
362 return task;
Chong Zhang8e89b312015-09-09 15:09:30 -0700363 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800364 // User touched inside the task. No need to look further,
365 // focus transfer will be handled in ACTION_UP.
366 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700367 }
368 }
369 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700370 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700371 }
372
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700373 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700374 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700375 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhangd8ceb852015-11-11 14:53:41 -0800376 boolean addBackFocusedTask = false;
Chong Zhangb15758a2015-11-17 12:12:03 -0800377 mNonResizeableRegion.setEmpty();
Chong Zhangd8ceb852015-11-11 14:53:41 -0800378 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
379 TaskStack stack = mStacks.get(stackNdx);
380 final ArrayList<Task> tasks = stack.getTasks();
381 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
382 final Task task = tasks.get(taskNdx);
Robert Carr9e76d322016-04-22 12:37:57 -0700383 AppWindowToken token = task.getTopVisibleAppToken();
384 if (token == null || !token.isVisible()) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800385 continue;
386 }
387
Chong Zhang8e89b312015-09-09 15:09:30 -0700388 /**
389 * Exclusion region is the region that TapDetector doesn't care about.
390 * Here we want to remove all non-focused tasks from the exclusion region.
391 * We also remove the outside touch area for resizing for all freeform
392 * tasks (including the focused).
393 *
Robert Carr9e76d322016-04-22 12:37:57 -0700394 * We save the focused task region once we find it, and add it back at the end.
Chong Zhang8e89b312015-09-09 15:09:30 -0700395 */
Robert Carr9e76d322016-04-22 12:37:57 -0700396
Wale Ogunwalee4dd9642016-05-10 08:39:01 -0700397 task.getDimBounds(mTmpRect);
398
Robert Carr9e76d322016-04-22 12:37:57 -0700399 if (task == focusedTask) {
400 addBackFocusedTask = true;
401 mTmpRect2.set(mTmpRect);
402 }
403
Chong Zhang09b21ef2015-09-14 10:20:21 -0700404 final boolean isFreeformed = task.inFreeformWorkspace();
Chong Zhang8e89b312015-09-09 15:09:30 -0700405 if (task != focusedTask || isFreeformed) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700406 if (isFreeformed) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800407 // If the task is freeformed, enlarge the area to account for outside
408 // touch area for resize.
Chong Zhang8e89b312015-09-09 15:09:30 -0700409 mTmpRect.inset(-delta, -delta);
Chong Zhang73c3fcf2015-11-05 13:18:33 -0800410 // Intersect with display content rect. If we have system decor (status bar/
411 // navigation bar), we want to exclude that from the tap detection.
412 // Otherwise, if the app is partially placed under some system button (eg.
413 // Recents, Home), pressing that button would cause a full series of
414 // unwanted transfer focus/resume/pause, before we could go home.
415 mTmpRect.intersect(mContentRect);
Chong Zhang8e89b312015-09-09 15:09:30 -0700416 }
417 mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
418 }
Chong Zhang2a88fc32016-01-11 17:14:24 -0800419 if (task.isTwoFingerScrollMode()) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800420 stack.getBounds(mTmpRect);
421 mNonResizeableRegion.op(mTmpRect, Region.Op.UNION);
422 break;
423 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700424 }
425 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800426 // If we removed the focused task above, add it back and only leave its
427 // outside touch area in the exclusion. TapDectector is not interested in
428 // any touch inside the focused task itself.
429 if (addBackFocusedTask) {
430 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
431 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800432 final WindowState inputMethod = mService.mInputMethodWindow;
433 if (inputMethod != null && inputMethod.isVisibleLw()) {
434 // If the input method is visible and the user is typing, we don't want these touch
435 // events to be intercepted and used to change focus. This would likely cause a
436 // disappearance of the input method.
437 inputMethod.getTouchableRegion(mTmpRegion);
438 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
439 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800440 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
441 WindowState win = mTapExcludedWindows.get(i);
442 win.getTouchableRegion(mTmpRegion);
443 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
444 }
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100445 if (getDockedStackVisibleForUserLocked() != null) {
446 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -0700447 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100448 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
449 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800450 if (mTapDetector != null) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800451 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion, mNonResizeableRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -0800452 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700453 }
454
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800455 void switchUserStacks() {
Craig Mautner858d8a62013-04-23 17:08:34 -0700456 final WindowList windows = getWindowList();
457 for (int i = 0; i < windows.size(); i++) {
458 final WindowState win = windows.get(i);
459 if (win.isHiddenFromUserLocked()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800460 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800461 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700462 win.hideLw(false);
463 }
464 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700465
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800466 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800467 mStacks.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700468 }
469 }
470
Craig Mautner05d29032013-05-03 13:40:13 -0700471 void resetAnimationBackgroundAnimator() {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800472 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
473 mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700474 }
475 }
476
477 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800478 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700479 }
480
481 void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800482 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700483 }
484
485 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800486 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700487 }
488
489 void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800490 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700491 }
492
Craig Mautner2eb15342013-08-07 13:13:35 -0700493 void close() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800494 mDimLayerController.close();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800495 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
496 mStacks.get(stackNdx).close();
Craig Mautner2eb15342013-08-07 13:13:35 -0700497 }
498 }
499
Craig Mautner95da1082014-02-24 17:54:35 -0800500 boolean isAnimating() {
501 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
502 final TaskStack stack = mStacks.get(stackNdx);
503 if (stack.isAnimating()) {
504 return true;
505 }
506 }
507 return false;
508 }
509
510 void checkForDeferredActions() {
511 boolean animating = false;
512 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
513 final TaskStack stack = mStacks.get(stackNdx);
514 if (stack.isAnimating()) {
515 animating = true;
516 } else {
517 if (stack.mDeferDetach) {
518 mService.detachStackLocked(this, stack);
519 }
520 final ArrayList<Task> tasks = stack.getTasks();
521 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
522 final Task task = tasks.get(taskNdx);
523 AppTokenList tokens = task.mAppTokens;
524 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
525 AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800526 if (wtoken.mIsExiting) {
Craig Mautnere3119b72015-01-20 15:02:36 -0800527 wtoken.removeAppFromTaskLocked();
Craig Mautner95da1082014-02-24 17:54:35 -0800528 }
529 }
Craig Mautner95da1082014-02-24 17:54:35 -0800530 }
531 }
532 }
533 if (!animating && mDeferredRemoval) {
534 mService.onDisplayRemoved(mDisplayId);
535 }
536 }
537
Wale Ogunwale94744212015-09-21 19:01:47 -0700538 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
539 final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation);
540 getLogicalDisplayRect(mTmpRect);
541 switch (rotationDelta) {
542 case Surface.ROTATION_0:
543 mTmpRect2.set(bounds);
544 break;
545 case Surface.ROTATION_90:
546 mTmpRect2.top = mTmpRect.bottom - bounds.right;
547 mTmpRect2.left = bounds.top;
548 mTmpRect2.right = mTmpRect2.left + bounds.height();
549 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
550 break;
551 case Surface.ROTATION_180:
552 mTmpRect2.top = mTmpRect.bottom - bounds.bottom;
553 mTmpRect2.left = mTmpRect.right - bounds.right;
554 mTmpRect2.right = mTmpRect2.left + bounds.width();
555 mTmpRect2.bottom = mTmpRect2.top + bounds.height();
556 break;
557 case Surface.ROTATION_270:
558 mTmpRect2.top = bounds.left;
559 mTmpRect2.left = mTmpRect.right - bounds.bottom;
560 mTmpRect2.right = mTmpRect2.left + bounds.height();
561 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
562 break;
563 }
564 bounds.set(mTmpRect2);
565 }
566
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800567 static int deltaRotation(int oldRotation, int newRotation) {
568 int delta = newRotation - oldRotation;
569 if (delta < 0) delta += 4;
570 return delta;
571 }
572
Craig Mautnera91f9e22012-09-14 16:22:08 -0700573 public void dump(String prefix, PrintWriter pw) {
574 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
575 final String subPrefix = " " + prefix;
576 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
577 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
578 pw.print("dpi");
579 if (mInitialDisplayWidth != mBaseDisplayWidth
580 || mInitialDisplayHeight != mBaseDisplayHeight
581 || mInitialDisplayDensity != mBaseDisplayDensity) {
582 pw.print(" base=");
583 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
584 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
585 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700586 if (mDisplayScalingDisabled) {
587 pw.println(" noscale");
588 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700589 pw.print(" cur=");
590 pw.print(mDisplayInfo.logicalWidth);
591 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
592 pw.print(" app=");
593 pw.print(mDisplayInfo.appWidth);
594 pw.print("x"); pw.print(mDisplayInfo.appHeight);
595 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
596 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
597 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
598 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Craig Mautner95da1082014-02-24 17:54:35 -0800599 pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval);
600 pw.print(" layoutNeeded="); pw.println(layoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800601
Craig Mautnerdc548482014-02-05 13:35:24 -0800602 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700603 pw.println(" Application tokens in top down Z order:");
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700604 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800605 final TaskStack stack = mStacks.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800606 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700607 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800608
Craig Mautnerdc548482014-02-05 13:35:24 -0800609 pw.println();
610 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700611 pw.println();
612 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800613 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700614 WindowToken token = mExitingTokens.get(i);
615 pw.print(" Exiting #"); pw.print(i);
616 pw.print(' '); pw.print(token);
617 pw.println(':');
618 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800619 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700620 }
Craig Mautner59c00972012-07-30 12:10:24 -0700621 pw.println();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800622 mDimLayerController.dump(prefix + " ", pw);
Jorim Jaggi31f71702016-05-04 16:43:04 -0700623 pw.println();
624 mDividerControllerLocked.dump(prefix + " ", pw);
Craig Mautner59c00972012-07-30 12:10:24 -0700625 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800626
627 @Override
628 public String toString() {
629 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
630 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700631
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800632 /**
633 * @return The docked stack, but only if it is visible, and {@code null} otherwise.
634 */
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700635 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700636 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
637 return (stack != null && stack.isVisibleLocked()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700638 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800639
640 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800641 * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not
642 * visible, as long as it's not hidden because the current user doesn't have any tasks there.
643 */
644 TaskStack getDockedStackVisibleForUserLocked() {
645 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Jorim Jaggi160a3c52016-08-25 15:57:41 -0700646 return (stack != null && stack.isVisibleLocked(true /* ignoreKeyguard */)) ? stack : null;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800647 }
648
649 /**
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800650 * Find the visible, touch-deliverable window under the given point
651 */
652 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
653 WindowState touchedWin = null;
654 final int x = (int) xf;
655 final int y = (int) yf;
656
657 for (int i = mWindows.size() - 1; i >= 0; i--) {
658 WindowState window = mWindows.get(i);
659 final int flags = window.mAttrs.flags;
660 if (!window.isVisibleLw()) {
661 continue;
662 }
663 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
664 continue;
665 }
666
667 window.getVisibleBounds(mTmpRect);
668 if (!mTmpRect.contains(x, y)) {
669 continue;
670 }
671
672 window.getTouchableRegion(mTmpRegion);
673
674 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
675 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
676 touchedWin = window;
677 break;
678 }
679 }
680
681 return touchedWin;
682 }
Jorim Jaggi6626f542016-08-22 13:08:44 -0700683
684 /**
685 * See {@link WindowManagerService#overridePlayingAppAnimationsLw}.
686 */
687 void overridePlayingAppAnimationsLw(Animation a) {
688 for (int i = mStacks.size() - 1; i >= 0; i--) {
689 mStacks.get(i).overridePlayingAppAnimations(a);
690 }
691 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700692
693 boolean canAddToastWindowForUid(int uid) {
694 // We allow one toast window per UID being shown at a time.
695 WindowList windows = getWindowList();
696 final int windowCount = windows.size();
697 for (int i = 0; i < windowCount; i++) {
698 WindowState window = windows.get(i);
699 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == uid
Svet Ganov62a40f82016-09-29 00:43:51 -0700700 && !window.mPermanentlyHidden && !window.mAnimatingExit
701 && !window.mRemoveOnExit) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700702 return false;
703 }
704 }
705 return true;
706 }
707
708 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus,
709 WindowState newFocus) {
710 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
711 return;
712 }
713 final int lostFocusUid = oldFocus.mOwnerUid;
714 WindowList windows = getWindowList();
715 final int windowCount = windows.size();
716 for (int i = 0; i < windowCount; i++) {
717 WindowState window = windows.get(i);
718 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == lostFocusUid) {
719 if (!mService.mH.hasMessages(WindowManagerService.H.WINDOW_HIDE_TIMEOUT, window)) {
720 mService.mH.sendMessageDelayed(
721 mService.mH.obtainMessage(
722 WindowManagerService.H.WINDOW_HIDE_TIMEOUT, window),
723 window.mAttrs.hideTimeoutMilliseconds);
724 }
725 }
726 }
727 }
Craig Mautner59c00972012-07-30 12:10:24 -0700728}