blob: f13f350cc9d4f1f3ec75c6023b3c497e3935026d [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);
269 task.getBounds(mTmpRect);
Wale Ogunwale54eb12c2015-09-28 15:16:22 -0700270 if (mTmpRect.contains(x, y)) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700271 return task.mTaskId;
272 }
Craig Mautner967212c2013-04-13 21:10:58 -0700273 }
274 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800275 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700276 }
277
Chong Zhang8e89b312015-09-09 15:09:30 -0700278 /**
Chong Zhang9184ec62015-09-24 12:32:21 -0700279 * Find the window whose outside touch area (for resizing) (x, y) falls within.
280 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700281 */
Chong Zhang9184ec62015-09-24 12:32:21 -0700282 WindowState findWindowForControlPoint(int x, int y) {
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700283 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhang8e89b312015-09-09 15:09:30 -0700284 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
285 TaskStack stack = mStacks.get(stackNdx);
286 if (!stack.allowTaskResize()) {
287 break;
288 }
289 final ArrayList<Task> tasks = stack.getTasks();
290 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
291 final Task task = tasks.get(taskNdx);
292 if (task.isFullscreen()) {
Chong Zhang9184ec62015-09-24 12:32:21 -0700293 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700294 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700295
296 // We need to use the visible frame on the window for any touch-related
297 // tests. Can't use the task's bounds because the original task bounds
298 // might be adjusted to fit the content frame. (One example is when the
299 // task is put to top-left quadrant, the actual visible frame would not
300 // start at (0,0) after it's adjusted for the status bar.)
301 WindowState win = task.getTopAppMainWindow();
302 if (win != null) {
303 win.getVisibleBounds(mTmpRect, !BOUNDS_FOR_TOUCH);
304 mTmpRect.inset(-delta, -delta);
305 if (mTmpRect.contains(x, y)) {
306 mTmpRect.inset(delta, delta);
307 if (!mTmpRect.contains(x, y)) {
308 return win;
309 }
310 // User touched inside the task. No need to look further,
311 // focus transfer will be handled in ACTION_UP.
312 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700313 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700314 }
315 }
316 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700317 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700318 }
319
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700320 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700321 mTouchExcludeRegion.set(mBaseDisplayRect);
322 WindowList windows = getWindowList();
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700323 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Craig Mautner6601b7b2013-04-29 10:29:11 -0700324 for (int i = windows.size() - 1; i >= 0; --i) {
325 final WindowState win = windows.get(i);
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700326 final Task task = win.getTask();
Chong Zhang8e89b312015-09-09 15:09:30 -0700327 if (win.isVisibleLw() && task != null) {
328 /**
329 * Exclusion region is the region that TapDetector doesn't care about.
330 * Here we want to remove all non-focused tasks from the exclusion region.
331 * We also remove the outside touch area for resizing for all freeform
332 * tasks (including the focused).
333 *
334 * (For freeform focused task, the below logic will first remove the enlarged
335 * area, then add back the inner area.)
336 */
Chong Zhang09b21ef2015-09-14 10:20:21 -0700337 final boolean isFreeformed = task.inFreeformWorkspace();
Chong Zhang8e89b312015-09-09 15:09:30 -0700338 if (task != focusedTask || isFreeformed) {
339 mTmpRect.set(win.mVisibleFrame);
340 mTmpRect.intersect(win.mVisibleInsets);
341 /**
342 * If the task is freeformed, enlarge the area to account for outside
343 * touch area for resize.
344 */
345 if (isFreeformed) {
346 mTmpRect.inset(-delta, -delta);
347 }
348 mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
349 }
350 /**
351 * If we removed the focused task above, add it back and only leave its
352 * outside touch area in the exclusion. TapDectector is not interested in
353 * any touch inside the focused task itself.
354 */
355 if (task == focusedTask && isFreeformed) {
356 mTmpRect.inset(delta, delta);
357 mTouchExcludeRegion.op(mTmpRect, Region.Op.UNION);
358 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700359 }
360 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800361 if (mTapDetector != null) {
362 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
363 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700364 }
365
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800366 void switchUserStacks() {
Craig Mautner858d8a62013-04-23 17:08:34 -0700367 final WindowList windows = getWindowList();
368 for (int i = 0; i < windows.size(); i++) {
369 final WindowState win = windows.get(i);
370 if (win.isHiddenFromUserLocked()) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800371 if (DEBUG_VISIBILITY) Slog.w(TAG, "user changing, hiding " + win
372 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700373 win.hideLw(false);
374 }
375 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700376
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800377 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800378 mStacks.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700379 }
380 }
381
Craig Mautner05d29032013-05-03 13:40:13 -0700382 void resetAnimationBackgroundAnimator() {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800383 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
384 mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700385 }
386 }
387
388 boolean animateDimLayers() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700389 return mDimBehindController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700390 }
391
392 void resetDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700393 mDimBehindController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700394 }
395
396 boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700397 return mDimBehindController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700398 }
399
400 void stopDimmingIfNeeded() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700401 mDimBehindController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700402 }
403
Craig Mautner2eb15342013-08-07 13:13:35 -0700404 void close() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700405 mDimBehindController.close();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800406 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
407 mStacks.get(stackNdx).close();
Craig Mautner2eb15342013-08-07 13:13:35 -0700408 }
409 }
410
Craig Mautner95da1082014-02-24 17:54:35 -0800411 boolean isAnimating() {
412 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
413 final TaskStack stack = mStacks.get(stackNdx);
414 if (stack.isAnimating()) {
415 return true;
416 }
417 }
418 return false;
419 }
420
421 void checkForDeferredActions() {
422 boolean animating = false;
423 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
424 final TaskStack stack = mStacks.get(stackNdx);
425 if (stack.isAnimating()) {
426 animating = true;
427 } else {
428 if (stack.mDeferDetach) {
429 mService.detachStackLocked(this, stack);
430 }
431 final ArrayList<Task> tasks = stack.getTasks();
432 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
433 final Task task = tasks.get(taskNdx);
434 AppTokenList tokens = task.mAppTokens;
435 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
436 AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800437 if (wtoken.mIsExiting) {
Craig Mautnere3119b72015-01-20 15:02:36 -0800438 wtoken.removeAppFromTaskLocked();
Craig Mautner95da1082014-02-24 17:54:35 -0800439 }
440 }
Craig Mautner95da1082014-02-24 17:54:35 -0800441 }
442 }
443 }
444 if (!animating && mDeferredRemoval) {
445 mService.onDisplayRemoved(mDisplayId);
446 }
447 }
448
Wale Ogunwale94744212015-09-21 19:01:47 -0700449 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
450 final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation);
451 getLogicalDisplayRect(mTmpRect);
452 switch (rotationDelta) {
453 case Surface.ROTATION_0:
454 mTmpRect2.set(bounds);
455 break;
456 case Surface.ROTATION_90:
457 mTmpRect2.top = mTmpRect.bottom - bounds.right;
458 mTmpRect2.left = bounds.top;
459 mTmpRect2.right = mTmpRect2.left + bounds.height();
460 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
461 break;
462 case Surface.ROTATION_180:
463 mTmpRect2.top = mTmpRect.bottom - bounds.bottom;
464 mTmpRect2.left = mTmpRect.right - bounds.right;
465 mTmpRect2.right = mTmpRect2.left + bounds.width();
466 mTmpRect2.bottom = mTmpRect2.top + bounds.height();
467 break;
468 case Surface.ROTATION_270:
469 mTmpRect2.top = bounds.left;
470 mTmpRect2.left = mTmpRect.right - bounds.bottom;
471 mTmpRect2.right = mTmpRect2.left + bounds.height();
472 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
473 break;
474 }
475 bounds.set(mTmpRect2);
476 }
477
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800478 static int deltaRotation(int oldRotation, int newRotation) {
479 int delta = newRotation - oldRotation;
480 if (delta < 0) delta += 4;
481 return delta;
482 }
483
Craig Mautnera91f9e22012-09-14 16:22:08 -0700484 public void dump(String prefix, PrintWriter pw) {
485 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
486 final String subPrefix = " " + prefix;
487 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
488 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
489 pw.print("dpi");
490 if (mInitialDisplayWidth != mBaseDisplayWidth
491 || mInitialDisplayHeight != mBaseDisplayHeight
492 || mInitialDisplayDensity != mBaseDisplayDensity) {
493 pw.print(" base=");
494 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
495 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
496 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700497 if (mDisplayScalingDisabled) {
498 pw.println(" noscale");
499 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700500 pw.print(" cur=");
501 pw.print(mDisplayInfo.logicalWidth);
502 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
503 pw.print(" app=");
504 pw.print(mDisplayInfo.appWidth);
505 pw.print("x"); pw.print(mDisplayInfo.appHeight);
506 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
507 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
508 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
509 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Craig Mautner95da1082014-02-24 17:54:35 -0800510 pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval);
511 pw.print(" layoutNeeded="); pw.println(layoutNeeded);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800512 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
513 final TaskStack stack = mStacks.get(stackNdx);
514 pw.print(prefix); pw.print("mStacks[" + stackNdx + "]"); pw.println(stack.mStackId);
515 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700516 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800517 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700518 pw.println(" Application tokens in top down Z order:");
Craig Mautnerdc548482014-02-05 13:35:24 -0800519 int ndx = 0;
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700520 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800521 final TaskStack stack = mStacks.get(stackNdx);
522 pw.print(" mStackId="); pw.println(stack.mStackId);
523 ArrayList<Task> tasks = stack.getTasks();
Craig Mautnerdc548482014-02-05 13:35:24 -0800524 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800525 final Task task = tasks.get(taskNdx);
Craig Mautner83162a92015-01-26 14:43:30 -0800526 pw.print(" mTaskId="); pw.println(task.mTaskId);
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800527 AppTokenList tokens = task.mAppTokens;
528 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx, ++ndx) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700529 final AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800530 pw.print(" Activity #"); pw.print(tokenNdx);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700531 pw.print(' '); pw.print(wtoken); pw.println(":");
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800532 wtoken.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800533 }
534 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700535 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800536 if (ndx == 0) {
537 pw.println(" None");
538 }
539 pw.println();
540 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700541 pw.println();
542 pw.println(" Exiting tokens:");
543 for (int i=mExitingTokens.size()-1; i>=0; i--) {
544 WindowToken token = mExitingTokens.get(i);
545 pw.print(" Exiting #"); pw.print(i);
546 pw.print(' '); pw.print(token);
547 pw.println(':');
548 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800549 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700550 }
Craig Mautner59c00972012-07-30 12:10:24 -0700551 pw.println();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700552 mDimBehindController.dump(prefix + " ", pw);
Craig Mautner59c00972012-07-30 12:10:24 -0700553 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800554
555 @Override
556 public String toString() {
557 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
558 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700559
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700560 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700561 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
562 return (stack != null && stack.isVisibleLocked()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700563 }
Craig Mautner59c00972012-07-30 12:10:24 -0700564}