blob: 39479c1a96813ebf06b03bf95cf2214ede616df8 [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);
Wale Ogunwale58fa9de2015-10-08 22:01:06 -0700194 mDividerControllerLocked.updateDisplayInfo();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800195 for (int i = mStacks.size() - 1; i >= 0; --i) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700196 mStacks.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800197 }
Craig Mautner722285e2012-09-07 13:55:58 -0700198 }
199
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700200 void initializeDisplayBaseInfo() {
201 synchronized(mDisplaySizeLock) {
202 // Bootstrap the default logical display from the display manager.
203 final DisplayInfo newDisplayInfo =
204 mService.mDisplayManagerInternal.getDisplayInfo(mDisplayId);
205 if (newDisplayInfo != null) {
206 mDisplayInfo.copyFrom(newDisplayInfo);
207 }
208 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
209 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
210 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
211 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
212 }
213 }
214
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700215 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700216 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800217 final int orientation = mDisplayInfo.rotation;
218 boolean rotated = (orientation == Surface.ROTATION_90
219 || orientation == Surface.ROTATION_270);
220 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
221 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700222 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800223 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700224 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800225 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700226 out.set(left, top, left + width, top + height);
227 }
228
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700229 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
230 void attachStack(TaskStack stack, boolean onTop) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800231 if (stack.mStackId == HOME_STACK_ID) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800232 if (mHomeStack != null) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800233 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700234 }
Craig Mautnerdf88d732014-01-27 09:21:32 -0800235 mHomeStack = stack;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800236 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700237 if (onTop) {
238 mStacks.add(stack);
239 } else {
240 mStacks.add(0, stack);
241 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800242 layoutNeeded = true;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800243 }
244
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800245 void moveStack(TaskStack stack, boolean toTop) {
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 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800249 mStacks.add(toTop ? mStacks.size() : 0, stack);
250 }
251
Craig Mautnerdf88d732014-01-27 09:21:32 -0800252 void detachStack(TaskStack stack) {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700253 mDimBehindController.removeDimLayerUser(stack);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800254 mStacks.remove(stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800255 }
256
257 /**
258 * Propagate the new bounds to all child stacks.
259 * @param contentRect The bounds to apply at the top level.
260 */
261 void resize(Rect contentRect) {
262 mContentRect.set(contentRect);
263 }
264
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700265 int taskIdFromPoint(int x, int y) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800266 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700267 final ArrayList<Task> tasks = mStacks.get(stackNdx).getTasks();
268 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
269 final Task task = tasks.get(taskNdx);
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700270 // We need to use the visible frame on the window for any touch-related tests.
271 // Can't use the task's bounds because the original task bounds might be adjusted
272 // to fit the content frame. For example, the presence of the IME adjusting the
273 // windows frames when the app window is the IME target.
274 final WindowState win = task.getTopAppMainWindow();
275 if (win != null) {
276 win.getVisibleBounds(mTmpRect, !BOUNDS_FOR_TOUCH);
277 if (mTmpRect.contains(x, y)) {
278 return task.mTaskId;
279 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700280 }
Craig Mautner967212c2013-04-13 21:10:58 -0700281 }
282 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800283 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700284 }
285
Chong Zhang8e89b312015-09-09 15:09:30 -0700286 /**
Chong Zhang9184ec62015-09-24 12:32:21 -0700287 * Find the window whose outside touch area (for resizing) (x, y) falls within.
288 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700289 */
Chong Zhang9184ec62015-09-24 12:32:21 -0700290 WindowState findWindowForControlPoint(int x, int y) {
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700291 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhang8e89b312015-09-09 15:09:30 -0700292 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
293 TaskStack stack = mStacks.get(stackNdx);
294 if (!stack.allowTaskResize()) {
295 break;
296 }
297 final ArrayList<Task> tasks = stack.getTasks();
298 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
299 final Task task = tasks.get(taskNdx);
300 if (task.isFullscreen()) {
Chong Zhang9184ec62015-09-24 12:32:21 -0700301 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700302 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700303
304 // We need to use the visible frame on the window for any touch-related
305 // tests. Can't use the task's bounds because the original task bounds
306 // might be adjusted to fit the content frame. (One example is when the
307 // task is put to top-left quadrant, the actual visible frame would not
308 // start at (0,0) after it's adjusted for the status bar.)
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700309 final WindowState win = task.getTopAppMainWindow();
Chong Zhang9184ec62015-09-24 12:32:21 -0700310 if (win != null) {
311 win.getVisibleBounds(mTmpRect, !BOUNDS_FOR_TOUCH);
312 mTmpRect.inset(-delta, -delta);
313 if (mTmpRect.contains(x, y)) {
314 mTmpRect.inset(delta, delta);
315 if (!mTmpRect.contains(x, y)) {
316 return win;
317 }
318 // User touched inside the task. No need to look further,
319 // focus transfer will be handled in ACTION_UP.
320 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700321 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700322 }
323 }
324 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700325 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700326 }
327
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700328 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700329 mTouchExcludeRegion.set(mBaseDisplayRect);
330 WindowList windows = getWindowList();
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700331 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Craig Mautner6601b7b2013-04-29 10:29:11 -0700332 for (int i = windows.size() - 1; i >= 0; --i) {
333 final WindowState win = windows.get(i);
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700334 final Task task = win.getTask();
Chong Zhang8e89b312015-09-09 15:09:30 -0700335 if (win.isVisibleLw() && task != null) {
336 /**
337 * Exclusion region is the region that TapDetector doesn't care about.
338 * Here we want to remove all non-focused tasks from the exclusion region.
339 * We also remove the outside touch area for resizing for all freeform
340 * tasks (including the focused).
341 *
342 * (For freeform focused task, the below logic will first remove the enlarged
343 * area, then add back the inner area.)
344 */
Chong Zhang09b21ef2015-09-14 10:20:21 -0700345 final boolean isFreeformed = task.inFreeformWorkspace();
Chong Zhang8e89b312015-09-09 15:09:30 -0700346 if (task != focusedTask || isFreeformed) {
347 mTmpRect.set(win.mVisibleFrame);
348 mTmpRect.intersect(win.mVisibleInsets);
349 /**
350 * If the task is freeformed, enlarge the area to account for outside
351 * touch area for resize.
352 */
353 if (isFreeformed) {
354 mTmpRect.inset(-delta, -delta);
355 }
356 mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
357 }
358 /**
359 * If we removed the focused task above, add it back and only leave its
360 * outside touch area in the exclusion. TapDectector is not interested in
361 * any touch inside the focused task itself.
362 */
363 if (task == focusedTask && isFreeformed) {
364 mTmpRect.inset(delta, delta);
365 mTouchExcludeRegion.op(mTmpRect, Region.Op.UNION);
366 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700367 }
368 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800369 if (mTapDetector != null) {
370 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
371 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700372 }
373
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800374 void switchUserStacks() {
Craig Mautner858d8a62013-04-23 17:08:34 -0700375 final WindowList windows = getWindowList();
376 for (int i = 0; i < windows.size(); i++) {
377 final WindowState win = windows.get(i);
378 if (win.isHiddenFromUserLocked()) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800379 if (DEBUG_VISIBILITY) Slog.w(TAG, "user changing, hiding " + win
380 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700381 win.hideLw(false);
382 }
383 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700384
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800385 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800386 mStacks.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700387 }
388 }
389
Craig Mautner05d29032013-05-03 13:40:13 -0700390 void resetAnimationBackgroundAnimator() {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800391 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
392 mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700393 }
394 }
395
396 boolean animateDimLayers() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700397 return mDimBehindController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700398 }
399
400 void resetDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700401 mDimBehindController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700402 }
403
404 boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700405 return mDimBehindController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700406 }
407
408 void stopDimmingIfNeeded() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700409 mDimBehindController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700410 }
411
Craig Mautner2eb15342013-08-07 13:13:35 -0700412 void close() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700413 mDimBehindController.close();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800414 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
415 mStacks.get(stackNdx).close();
Craig Mautner2eb15342013-08-07 13:13:35 -0700416 }
417 }
418
Craig Mautner95da1082014-02-24 17:54:35 -0800419 boolean isAnimating() {
420 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
421 final TaskStack stack = mStacks.get(stackNdx);
422 if (stack.isAnimating()) {
423 return true;
424 }
425 }
426 return false;
427 }
428
429 void checkForDeferredActions() {
430 boolean animating = false;
431 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
432 final TaskStack stack = mStacks.get(stackNdx);
433 if (stack.isAnimating()) {
434 animating = true;
435 } else {
436 if (stack.mDeferDetach) {
437 mService.detachStackLocked(this, stack);
438 }
439 final ArrayList<Task> tasks = stack.getTasks();
440 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
441 final Task task = tasks.get(taskNdx);
442 AppTokenList tokens = task.mAppTokens;
443 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
444 AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800445 if (wtoken.mIsExiting) {
Craig Mautnere3119b72015-01-20 15:02:36 -0800446 wtoken.removeAppFromTaskLocked();
Craig Mautner95da1082014-02-24 17:54:35 -0800447 }
448 }
Craig Mautner95da1082014-02-24 17:54:35 -0800449 }
450 }
451 }
452 if (!animating && mDeferredRemoval) {
453 mService.onDisplayRemoved(mDisplayId);
454 }
455 }
456
Wale Ogunwale94744212015-09-21 19:01:47 -0700457 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
458 final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation);
459 getLogicalDisplayRect(mTmpRect);
460 switch (rotationDelta) {
461 case Surface.ROTATION_0:
462 mTmpRect2.set(bounds);
463 break;
464 case Surface.ROTATION_90:
465 mTmpRect2.top = mTmpRect.bottom - bounds.right;
466 mTmpRect2.left = bounds.top;
467 mTmpRect2.right = mTmpRect2.left + bounds.height();
468 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
469 break;
470 case Surface.ROTATION_180:
471 mTmpRect2.top = mTmpRect.bottom - bounds.bottom;
472 mTmpRect2.left = mTmpRect.right - bounds.right;
473 mTmpRect2.right = mTmpRect2.left + bounds.width();
474 mTmpRect2.bottom = mTmpRect2.top + bounds.height();
475 break;
476 case Surface.ROTATION_270:
477 mTmpRect2.top = bounds.left;
478 mTmpRect2.left = mTmpRect.right - bounds.bottom;
479 mTmpRect2.right = mTmpRect2.left + bounds.height();
480 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
481 break;
482 }
483 bounds.set(mTmpRect2);
484 }
485
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800486 static int deltaRotation(int oldRotation, int newRotation) {
487 int delta = newRotation - oldRotation;
488 if (delta < 0) delta += 4;
489 return delta;
490 }
491
Craig Mautnera91f9e22012-09-14 16:22:08 -0700492 public void dump(String prefix, PrintWriter pw) {
493 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
494 final String subPrefix = " " + prefix;
495 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
496 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
497 pw.print("dpi");
498 if (mInitialDisplayWidth != mBaseDisplayWidth
499 || mInitialDisplayHeight != mBaseDisplayHeight
500 || mInitialDisplayDensity != mBaseDisplayDensity) {
501 pw.print(" base=");
502 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
503 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
504 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700505 if (mDisplayScalingDisabled) {
506 pw.println(" noscale");
507 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700508 pw.print(" cur=");
509 pw.print(mDisplayInfo.logicalWidth);
510 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
511 pw.print(" app=");
512 pw.print(mDisplayInfo.appWidth);
513 pw.print("x"); pw.print(mDisplayInfo.appHeight);
514 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
515 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
516 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
517 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Craig Mautner95da1082014-02-24 17:54:35 -0800518 pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval);
519 pw.print(" layoutNeeded="); pw.println(layoutNeeded);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800520 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
521 final TaskStack stack = mStacks.get(stackNdx);
522 pw.print(prefix); pw.print("mStacks[" + stackNdx + "]"); pw.println(stack.mStackId);
523 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700524 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800525 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700526 pw.println(" Application tokens in top down Z order:");
Craig Mautnerdc548482014-02-05 13:35:24 -0800527 int ndx = 0;
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700528 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800529 final TaskStack stack = mStacks.get(stackNdx);
530 pw.print(" mStackId="); pw.println(stack.mStackId);
531 ArrayList<Task> tasks = stack.getTasks();
Craig Mautnerdc548482014-02-05 13:35:24 -0800532 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800533 final Task task = tasks.get(taskNdx);
Craig Mautner83162a92015-01-26 14:43:30 -0800534 pw.print(" mTaskId="); pw.println(task.mTaskId);
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800535 AppTokenList tokens = task.mAppTokens;
536 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx, ++ndx) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700537 final AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800538 pw.print(" Activity #"); pw.print(tokenNdx);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700539 pw.print(' '); pw.print(wtoken); pw.println(":");
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800540 wtoken.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800541 }
542 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700543 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800544 if (ndx == 0) {
545 pw.println(" None");
546 }
547 pw.println();
548 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700549 pw.println();
550 pw.println(" Exiting tokens:");
551 for (int i=mExitingTokens.size()-1; i>=0; i--) {
552 WindowToken token = mExitingTokens.get(i);
553 pw.print(" Exiting #"); pw.print(i);
554 pw.print(' '); pw.print(token);
555 pw.println(':');
556 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800557 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700558 }
Craig Mautner59c00972012-07-30 12:10:24 -0700559 pw.println();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700560 mDimBehindController.dump(prefix + " ", pw);
Craig Mautner59c00972012-07-30 12:10:24 -0700561 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800562
563 @Override
564 public String toString() {
565 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
566 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700567
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700568 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700569 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
570 return (stack != null && stack.isVisibleLocked()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700571 }
Craig Mautner59c00972012-07-30 12:10:24 -0700572}