blob: 438658ee40e4d17fea4e0884cc6c8bd7e2523f66 [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
Filip Gruszczynski466f3212015-09-21 17:57:57 -070019import static android.app.ActivityManager.DOCKED_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -070020import static android.app.ActivityManager.HOME_STACK_ID;
21
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;
Chong Zhang9184ec62015-09-24 12:32:21 -070025import static com.android.server.wm.WindowState.BOUNDS_FOR_TOUCH;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070026
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 // This protects the following display size properties, so that
58 // getDisplaySize() doesn't need to acquire the global lock. This is
59 // needed because the window manager sometimes needs to use ActivityThread
60 // while it has its global state locked (for example to load animation
61 // resources), but the ActivityThread also needs get the current display
62 // size sometimes when it has its package lock held.
63 //
64 // These will only be modified with both mWindowMap and mDisplaySizeLock
65 // held (in that order) so the window manager doesn't need to acquire this
66 // lock when needing these values in its normal operation.
67 final Object mDisplaySizeLock = new Object();
68 int mInitialDisplayWidth = 0;
69 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070070 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -070071 int mBaseDisplayWidth = 0;
72 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070073 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -070074 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -070075 private final DisplayInfo mDisplayInfo = new DisplayInfo();
76 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070077 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -070078
Craig Mautner6601b7b2013-04-29 10:29:11 -070079 Rect mBaseDisplayRect = new Rect();
Craig Mautnerbdc748af2013-12-02 14:08:25 -080080 Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -070081
Craig Mautner39834192012-09-02 07:47:24 -070082 // Accessed directly by all users.
83 boolean layoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -070084 int pendingLayoutChanges;
Craig Mautner69b08182012-09-05 13:07:13 -070085 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -070086
Craig Mautnerdc548482014-02-05 13:35:24 -080087 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070088 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080089
Craig Mautnerbdc748af2013-12-02 14:08:25 -080090 /** Array containing all TaskStacks on this display. Array
Craig Mautnercf910b02013-04-23 11:23:27 -070091 * is stored in display order with the current bottom stack at 0. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070092 private final ArrayList<TaskStack> mStacks = new ArrayList<>();
Craig Mautnerc00204b2013-03-05 15:02:14 -080093
Craig Mautnerbdc748af2013-12-02 14:08:25 -080094 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
95 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -070096 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070097
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070098 /** Detect user tapping outside of current focused task bounds .*/
99 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700100
Craig Mautner6601b7b2013-04-29 10:29:11 -0700101 /** Detect user tapping outside of current focused stack bounds .*/
102 Region mTouchExcludeRegion = new Region();
103
Craig Mautner6601b7b2013-04-29 10:29:11 -0700104 /** Save allocating when calculating rects */
Wale Ogunwale94744212015-09-21 19:01:47 -0700105 private Rect mTmpRect = new Rect();
106 private Rect mTmpRect2 = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700107
Craig Mautnerdc548482014-02-05 13:35:24 -0800108 /** For gathering Task objects in order. */
109 final ArrayList<Task> mTmpTaskHistory = new ArrayList<Task>();
110
Craig Mautner9d808b12013-08-06 18:00:25 -0700111 final WindowManagerService mService;
112
Craig Mautner95da1082014-02-24 17:54:35 -0800113 /** Remove this display when animation on it has completed. */
114 boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800115
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700116 final DockedStackDividerController mDividerControllerLocked;
117
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700118 final DimBehindController mDimBehindController;
119
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800120 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700121 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800122 * @param service You know.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700123 */
Craig Mautner9d808b12013-08-06 18:00:25 -0700124 DisplayContent(Display display, WindowManagerService service) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700125 mDisplay = display;
126 mDisplayId = display.getDisplayId();
127 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700128 display.getMetrics(mDisplayMetrics);
Craig Mautner69b08182012-09-05 13:07:13 -0700129 isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700130 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700131 initializeDisplayBaseInfo();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700132 mDividerControllerLocked = new DockedStackDividerController(service.mContext, this);
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700133 mDimBehindController = new DimBehindController(this);
Craig Mautner59c00972012-07-30 12:10:24 -0700134 }
135
136 int getDisplayId() {
137 return mDisplayId;
138 }
139
140 WindowList getWindowList() {
141 return mWindows;
142 }
143
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700144 Display getDisplay() {
145 return mDisplay;
146 }
147
Craig Mautner59c00972012-07-30 12:10:24 -0700148 DisplayInfo getDisplayInfo() {
149 return mDisplayInfo;
150 }
151
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700152 DisplayMetrics getDisplayMetrics() {
153 return mDisplayMetrics;
154 }
155
Jeff Browna506a6e2013-06-04 00:02:38 -0700156 /**
157 * Returns true if the specified UID has access to this display.
158 */
159 public boolean hasAccess(int uid) {
160 return mDisplay.hasAccess(uid);
161 }
162
keunyounga446bf02013-06-21 19:07:57 -0700163 public boolean isPrivate() {
164 return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
165 }
166
Craig Mautnerdc548482014-02-05 13:35:24 -0800167 ArrayList<TaskStack> getStacks() {
168 return mStacks;
169 }
170
Craig Mautner00af9fe2013-03-25 09:13:41 -0700171 /**
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700172 * Retrieve the tasks on this display in stack order from the bottommost TaskStack up.
Craig Mautner00af9fe2013-03-25 09:13:41 -0700173 * @return All the Tasks, in order, on this display.
174 */
Craig Mautnerc00204b2013-03-05 15:02:14 -0800175 ArrayList<Task> getTasks() {
Craig Mautnerdc548482014-02-05 13:35:24 -0800176 mTmpTaskHistory.clear();
177 final int numStacks = mStacks.size();
178 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
179 mTmpTaskHistory.addAll(mStacks.get(stackNdx).getTasks());
Craig Mautnerd9a22882013-03-16 15:00:36 -0700180 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800181 return mTmpTaskHistory;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800182 }
183
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700184 TaskStack getHomeStack() {
Craig Mautner333c2ec2014-10-02 12:24:02 -0700185 if (mHomeStack == null && mDisplayId == Display.DEFAULT_DISPLAY) {
Craig Mautnere0a38842013-12-16 16:14:02 -0800186 Slog.e(TAG, "getHomeStack: Returning null from this=" + this);
187 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700188 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700189 }
190
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700191 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700192 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700193 mDisplay.getMetrics(mDisplayMetrics);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800194 for (int i = mStacks.size() - 1; i >= 0; --i) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700195 mStacks.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800196 }
Craig Mautner722285e2012-09-07 13:55:58 -0700197 }
198
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700199 void initializeDisplayBaseInfo() {
200 synchronized(mDisplaySizeLock) {
201 // Bootstrap the default logical display from the display manager.
202 final DisplayInfo newDisplayInfo =
203 mService.mDisplayManagerInternal.getDisplayInfo(mDisplayId);
204 if (newDisplayInfo != null) {
205 mDisplayInfo.copyFrom(newDisplayInfo);
206 }
207 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
208 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
209 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
210 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
211 }
212 }
213
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700214 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700215 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800216 final int orientation = mDisplayInfo.rotation;
217 boolean rotated = (orientation == Surface.ROTATION_90
218 || orientation == Surface.ROTATION_270);
219 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
220 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700221 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800222 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700223 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800224 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700225 out.set(left, top, left + width, top + height);
226 }
227
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700228 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
229 void attachStack(TaskStack stack, boolean onTop) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800230 if (stack.mStackId == HOME_STACK_ID) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800231 if (mHomeStack != null) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800232 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700233 }
Craig Mautnerdf88d732014-01-27 09:21:32 -0800234 mHomeStack = stack;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800235 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700236 if (onTop) {
237 mStacks.add(stack);
238 } else {
239 mStacks.add(0, stack);
240 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800241 layoutNeeded = true;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800242 }
243
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800244 void moveStack(TaskStack stack, boolean toTop) {
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700245 if (!mStacks.remove(stack)) {
246 Slog.wtf(TAG, "moving stack that was not added: " + stack, new Throwable());
247 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800248 mStacks.add(toTop ? mStacks.size() : 0, stack);
249 }
250
Craig Mautnerdf88d732014-01-27 09:21:32 -0800251 void detachStack(TaskStack stack) {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700252 mDimBehindController.removeDimLayerUser(stack);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800253 mStacks.remove(stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800254 }
255
256 /**
257 * Propagate the new bounds to all child stacks.
258 * @param contentRect The bounds to apply at the top level.
259 */
260 void resize(Rect contentRect) {
261 mContentRect.set(contentRect);
262 }
263
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700264 int taskIdFromPoint(int x, int y) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800265 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700266 final ArrayList<Task> tasks = mStacks.get(stackNdx).getTasks();
267 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
268 final Task task = tasks.get(taskNdx);
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700269 // We need to use the visible frame on the window for any touch-related tests.
270 // Can't use the task's bounds because the original task bounds might be adjusted
271 // to fit the content frame. For example, the presence of the IME adjusting the
272 // windows frames when the app window is the IME target.
273 final WindowState win = task.getTopAppMainWindow();
274 if (win != null) {
275 win.getVisibleBounds(mTmpRect, !BOUNDS_FOR_TOUCH);
276 if (mTmpRect.contains(x, y)) {
277 return task.mTaskId;
278 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700279 }
Craig Mautner967212c2013-04-13 21:10:58 -0700280 }
281 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800282 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700283 }
284
Chong Zhang8e89b312015-09-09 15:09:30 -0700285 /**
Chong Zhang9184ec62015-09-24 12:32:21 -0700286 * Find the window whose outside touch area (for resizing) (x, y) falls within.
287 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700288 */
Chong Zhang9184ec62015-09-24 12:32:21 -0700289 WindowState findWindowForControlPoint(int x, int y) {
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700290 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhang8e89b312015-09-09 15:09:30 -0700291 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
292 TaskStack stack = mStacks.get(stackNdx);
293 if (!stack.allowTaskResize()) {
294 break;
295 }
296 final ArrayList<Task> tasks = stack.getTasks();
297 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
298 final Task task = tasks.get(taskNdx);
299 if (task.isFullscreen()) {
Chong Zhang9184ec62015-09-24 12:32:21 -0700300 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700301 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700302
303 // We need to use the visible frame on the window for any touch-related
304 // tests. Can't use the task's bounds because the original task bounds
305 // might be adjusted to fit the content frame. (One example is when the
306 // task is put to top-left quadrant, the actual visible frame would not
307 // start at (0,0) after it's adjusted for the status bar.)
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700308 final WindowState win = task.getTopAppMainWindow();
Chong Zhang9184ec62015-09-24 12:32:21 -0700309 if (win != null) {
310 win.getVisibleBounds(mTmpRect, !BOUNDS_FOR_TOUCH);
311 mTmpRect.inset(-delta, -delta);
312 if (mTmpRect.contains(x, y)) {
313 mTmpRect.inset(delta, delta);
314 if (!mTmpRect.contains(x, y)) {
315 return win;
316 }
317 // User touched inside the task. No need to look further,
318 // focus transfer will be handled in ACTION_UP.
319 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700320 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700321 }
322 }
323 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700324 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700325 }
326
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700327 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700328 mTouchExcludeRegion.set(mBaseDisplayRect);
329 WindowList windows = getWindowList();
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700330 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Craig Mautner6601b7b2013-04-29 10:29:11 -0700331 for (int i = windows.size() - 1; i >= 0; --i) {
332 final WindowState win = windows.get(i);
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700333 final Task task = win.getTask();
Chong Zhang8e89b312015-09-09 15:09:30 -0700334 if (win.isVisibleLw() && task != null) {
335 /**
336 * Exclusion region is the region that TapDetector doesn't care about.
337 * Here we want to remove all non-focused tasks from the exclusion region.
338 * We also remove the outside touch area for resizing for all freeform
339 * tasks (including the focused).
340 *
341 * (For freeform focused task, the below logic will first remove the enlarged
342 * area, then add back the inner area.)
343 */
Chong Zhang09b21ef2015-09-14 10:20:21 -0700344 final boolean isFreeformed = task.inFreeformWorkspace();
Chong Zhang8e89b312015-09-09 15:09:30 -0700345 if (task != focusedTask || isFreeformed) {
346 mTmpRect.set(win.mVisibleFrame);
347 mTmpRect.intersect(win.mVisibleInsets);
348 /**
349 * If the task is freeformed, enlarge the area to account for outside
350 * touch area for resize.
351 */
352 if (isFreeformed) {
353 mTmpRect.inset(-delta, -delta);
354 }
355 mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
356 }
357 /**
358 * If we removed the focused task above, add it back and only leave its
359 * outside touch area in the exclusion. TapDectector is not interested in
360 * any touch inside the focused task itself.
361 */
362 if (task == focusedTask && isFreeformed) {
363 mTmpRect.inset(delta, delta);
364 mTouchExcludeRegion.op(mTmpRect, Region.Op.UNION);
365 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700366 }
367 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800368 if (mTapDetector != null) {
369 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
370 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700371 }
372
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800373 void switchUserStacks() {
Craig Mautner858d8a62013-04-23 17:08:34 -0700374 final WindowList windows = getWindowList();
375 for (int i = 0; i < windows.size(); i++) {
376 final WindowState win = windows.get(i);
377 if (win.isHiddenFromUserLocked()) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800378 if (DEBUG_VISIBILITY) Slog.w(TAG, "user changing, hiding " + win
379 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700380 win.hideLw(false);
381 }
382 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700383
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800384 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800385 mStacks.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700386 }
387 }
388
Craig Mautner05d29032013-05-03 13:40:13 -0700389 void resetAnimationBackgroundAnimator() {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800390 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
391 mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700392 }
393 }
394
395 boolean animateDimLayers() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700396 return mDimBehindController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700397 }
398
399 void resetDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700400 mDimBehindController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700401 }
402
403 boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700404 return mDimBehindController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700405 }
406
407 void stopDimmingIfNeeded() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700408 mDimBehindController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700409 }
410
Craig Mautner2eb15342013-08-07 13:13:35 -0700411 void close() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700412 mDimBehindController.close();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800413 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
414 mStacks.get(stackNdx).close();
Craig Mautner2eb15342013-08-07 13:13:35 -0700415 }
416 }
417
Craig Mautner95da1082014-02-24 17:54:35 -0800418 boolean isAnimating() {
419 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
420 final TaskStack stack = mStacks.get(stackNdx);
421 if (stack.isAnimating()) {
422 return true;
423 }
424 }
425 return false;
426 }
427
428 void checkForDeferredActions() {
429 boolean animating = false;
430 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
431 final TaskStack stack = mStacks.get(stackNdx);
432 if (stack.isAnimating()) {
433 animating = true;
434 } else {
435 if (stack.mDeferDetach) {
436 mService.detachStackLocked(this, stack);
437 }
438 final ArrayList<Task> tasks = stack.getTasks();
439 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
440 final Task task = tasks.get(taskNdx);
441 AppTokenList tokens = task.mAppTokens;
442 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
443 AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800444 if (wtoken.mIsExiting) {
Craig Mautnere3119b72015-01-20 15:02:36 -0800445 wtoken.removeAppFromTaskLocked();
Craig Mautner95da1082014-02-24 17:54:35 -0800446 }
447 }
Craig Mautner95da1082014-02-24 17:54:35 -0800448 }
449 }
450 }
451 if (!animating && mDeferredRemoval) {
452 mService.onDisplayRemoved(mDisplayId);
453 }
454 }
455
Wale Ogunwale94744212015-09-21 19:01:47 -0700456 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
457 final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation);
458 getLogicalDisplayRect(mTmpRect);
459 switch (rotationDelta) {
460 case Surface.ROTATION_0:
461 mTmpRect2.set(bounds);
462 break;
463 case Surface.ROTATION_90:
464 mTmpRect2.top = mTmpRect.bottom - bounds.right;
465 mTmpRect2.left = bounds.top;
466 mTmpRect2.right = mTmpRect2.left + bounds.height();
467 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
468 break;
469 case Surface.ROTATION_180:
470 mTmpRect2.top = mTmpRect.bottom - bounds.bottom;
471 mTmpRect2.left = mTmpRect.right - bounds.right;
472 mTmpRect2.right = mTmpRect2.left + bounds.width();
473 mTmpRect2.bottom = mTmpRect2.top + bounds.height();
474 break;
475 case Surface.ROTATION_270:
476 mTmpRect2.top = bounds.left;
477 mTmpRect2.left = mTmpRect.right - bounds.bottom;
478 mTmpRect2.right = mTmpRect2.left + bounds.height();
479 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
480 break;
481 }
482 bounds.set(mTmpRect2);
483 }
484
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800485 static int deltaRotation(int oldRotation, int newRotation) {
486 int delta = newRotation - oldRotation;
487 if (delta < 0) delta += 4;
488 return delta;
489 }
490
Craig Mautnera91f9e22012-09-14 16:22:08 -0700491 public void dump(String prefix, PrintWriter pw) {
492 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
493 final String subPrefix = " " + prefix;
494 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
495 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
496 pw.print("dpi");
497 if (mInitialDisplayWidth != mBaseDisplayWidth
498 || mInitialDisplayHeight != mBaseDisplayHeight
499 || mInitialDisplayDensity != mBaseDisplayDensity) {
500 pw.print(" base=");
501 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
502 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
503 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700504 if (mDisplayScalingDisabled) {
505 pw.println(" noscale");
506 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700507 pw.print(" cur=");
508 pw.print(mDisplayInfo.logicalWidth);
509 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
510 pw.print(" app=");
511 pw.print(mDisplayInfo.appWidth);
512 pw.print("x"); pw.print(mDisplayInfo.appHeight);
513 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
514 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
515 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
516 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Craig Mautner95da1082014-02-24 17:54:35 -0800517 pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval);
518 pw.print(" layoutNeeded="); pw.println(layoutNeeded);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800519 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
520 final TaskStack stack = mStacks.get(stackNdx);
521 pw.print(prefix); pw.print("mStacks[" + stackNdx + "]"); pw.println(stack.mStackId);
522 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700523 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800524 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700525 pw.println(" Application tokens in top down Z order:");
Craig Mautnerdc548482014-02-05 13:35:24 -0800526 int ndx = 0;
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700527 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800528 final TaskStack stack = mStacks.get(stackNdx);
529 pw.print(" mStackId="); pw.println(stack.mStackId);
530 ArrayList<Task> tasks = stack.getTasks();
Craig Mautnerdc548482014-02-05 13:35:24 -0800531 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800532 final Task task = tasks.get(taskNdx);
Craig Mautner83162a92015-01-26 14:43:30 -0800533 pw.print(" mTaskId="); pw.println(task.mTaskId);
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800534 AppTokenList tokens = task.mAppTokens;
535 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx, ++ndx) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700536 final AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800537 pw.print(" Activity #"); pw.print(tokenNdx);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700538 pw.print(' '); pw.print(wtoken); pw.println(":");
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800539 wtoken.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800540 }
541 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700542 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800543 if (ndx == 0) {
544 pw.println(" None");
545 }
546 pw.println();
547 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700548 pw.println();
549 pw.println(" Exiting tokens:");
550 for (int i=mExitingTokens.size()-1; i>=0; i--) {
551 WindowToken token = mExitingTokens.get(i);
552 pw.print(" Exiting #"); pw.print(i);
553 pw.print(' '); pw.print(token);
554 pw.println(':');
555 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800556 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700557 }
Craig Mautner59c00972012-07-30 12:10:24 -0700558 pw.println();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700559 mDimBehindController.dump(prefix + " ", pw);
Craig Mautner59c00972012-07-30 12:10:24 -0700560 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800561
562 @Override
563 public String toString() {
564 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
565 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700566
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700567 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700568 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
569 return (stack != null && stack.isVisibleLocked()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700570 }
Craig Mautner59c00972012-07-30 12:10:24 -0700571}