blob: 53f8bbd9084b3f33ec6485156d7770c719f03c32 [file] [log] [blame]
Craig Mautner59c00972012-07-30 12:10:24 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale3797c222015-10-27 14:21:58 -070019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
20import static android.app.ActivityManager.StackId.HOME_STACK_ID;
21import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Craig Mautner858d8a62013-04-23 17:08:34 -070022import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
Craig Mautnerde4ef022013-04-07 19:01:33 -070023import static com.android.server.wm.WindowManagerService.TAG;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070024import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
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
Wale Ogunwale3797c222015-10-27 14:21:58 -070027import android.app.ActivityManager.StackId;
Craig Mautnerc00204b2013-03-05 15:02:14 -080028import android.graphics.Rect;
Craig Mautner6601b7b2013-04-29 10:29:11 -070029import android.graphics.Region;
Chong Zhang8e89b312015-09-09 15:09:30 -070030import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -070031import android.util.Slog;
Craig Mautnerb47bbc32012-08-22 17:41:48 -070032import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070033import android.view.DisplayInfo;
Craig Mautner4a1cb222013-12-04 16:14:06 -080034import android.view.Surface;
Craig Mautner59c00972012-07-30 12:10:24 -070035
36import java.io.PrintWriter;
37import java.util.ArrayList;
38
39class DisplayContentList extends ArrayList<DisplayContent> {
40}
41
42/**
43 * Utility class for keeping track of the WindowStates and other pertinent contents of a
44 * particular Display.
45 *
46 * IMPORTANT: No method from this class should ever be used without holding
47 * WindowManagerService.mWindowMap.
48 */
49class DisplayContent {
50
51 /** Unique identifier of this stack. */
52 private final int mDisplayId;
53
54 /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
55 * from mDisplayWindows; */
Craig Mautnerdc548482014-02-05 13:35:24 -080056 private final WindowList mWindows = new WindowList();
Craig Mautner59c00972012-07-30 12:10:24 -070057
Craig Mautner59c00972012-07-30 12:10:24 -070058 // This protects the following display size properties, so that
59 // getDisplaySize() doesn't need to acquire the global lock. This is
60 // needed because the window manager sometimes needs to use ActivityThread
61 // while it has its global state locked (for example to load animation
62 // resources), but the ActivityThread also needs get the current display
63 // size sometimes when it has its package lock held.
64 //
65 // These will only be modified with both mWindowMap and mDisplaySizeLock
66 // held (in that order) so the window manager doesn't need to acquire this
67 // lock when needing these values in its normal operation.
68 final Object mDisplaySizeLock = new Object();
69 int mInitialDisplayWidth = 0;
70 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070071 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -070072 int mBaseDisplayWidth = 0;
73 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -070074 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -070075 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -070076 private final DisplayInfo mDisplayInfo = new DisplayInfo();
77 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070078 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -070079
Craig Mautner6601b7b2013-04-29 10:29:11 -070080 Rect mBaseDisplayRect = new Rect();
Craig Mautnerbdc748af2013-12-02 14:08:25 -080081 Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -070082
Craig Mautner39834192012-09-02 07:47:24 -070083 // Accessed directly by all users.
84 boolean layoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -070085 int pendingLayoutChanges;
Craig Mautner69b08182012-09-05 13:07:13 -070086 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -070087
Craig Mautnerdc548482014-02-05 13:35:24 -080088 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070089 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080090
Craig Mautnerbdc748af2013-12-02 14:08:25 -080091 /** Array containing all TaskStacks on this display. Array
Craig Mautnercf910b02013-04-23 11:23:27 -070092 * is stored in display order with the current bottom stack at 0. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -070093 private final ArrayList<TaskStack> mStacks = new ArrayList<>();
Craig Mautnerc00204b2013-03-05 15:02:14 -080094
Craig Mautnerbdc748af2013-12-02 14:08:25 -080095 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
96 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -070097 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070098
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070099 /** Detect user tapping outside of current focused task bounds .*/
100 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700101
Craig Mautner6601b7b2013-04-29 10:29:11 -0700102 /** Detect user tapping outside of current focused stack bounds .*/
103 Region mTouchExcludeRegion = new Region();
104
Craig Mautner6601b7b2013-04-29 10:29:11 -0700105 /** Save allocating when calculating rects */
Wale Ogunwale94744212015-09-21 19:01:47 -0700106 private Rect mTmpRect = new Rect();
107 private Rect mTmpRect2 = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700108
Craig Mautnerdc548482014-02-05 13:35:24 -0800109 /** For gathering Task objects in order. */
110 final ArrayList<Task> mTmpTaskHistory = new ArrayList<Task>();
111
Craig Mautner9d808b12013-08-06 18:00:25 -0700112 final WindowManagerService mService;
113
Craig Mautner95da1082014-02-24 17:54:35 -0800114 /** Remove this display when animation on it has completed. */
115 boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800116
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700117 final DockedStackDividerController mDividerControllerLocked;
118
Chong Zhang112eb8c2015-11-02 11:17:00 -0800119 final DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700120
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800121 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700122 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800123 * @param service You know.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700124 */
Craig Mautner9d808b12013-08-06 18:00:25 -0700125 DisplayContent(Display display, WindowManagerService service) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700126 mDisplay = display;
127 mDisplayId = display.getDisplayId();
128 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700129 display.getMetrics(mDisplayMetrics);
Craig Mautner69b08182012-09-05 13:07:13 -0700130 isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700131 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700132 initializeDisplayBaseInfo();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700133 mDividerControllerLocked = new DockedStackDividerController(service.mContext, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800134 mDimLayerController = new DimLayerController(this);
Craig Mautner59c00972012-07-30 12:10:24 -0700135 }
136
137 int getDisplayId() {
138 return mDisplayId;
139 }
140
141 WindowList getWindowList() {
142 return mWindows;
143 }
144
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700145 Display getDisplay() {
146 return mDisplay;
147 }
148
Craig Mautner59c00972012-07-30 12:10:24 -0700149 DisplayInfo getDisplayInfo() {
150 return mDisplayInfo;
151 }
152
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700153 DisplayMetrics getDisplayMetrics() {
154 return mDisplayMetrics;
155 }
156
Jeff Browna506a6e2013-06-04 00:02:38 -0700157 /**
158 * Returns true if the specified UID has access to this display.
159 */
160 public boolean hasAccess(int uid) {
161 return mDisplay.hasAccess(uid);
162 }
163
keunyounga446bf02013-06-21 19:07:57 -0700164 public boolean isPrivate() {
165 return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
166 }
167
Craig Mautnerdc548482014-02-05 13:35:24 -0800168 ArrayList<TaskStack> getStacks() {
169 return mStacks;
170 }
171
Craig Mautner00af9fe2013-03-25 09:13:41 -0700172 /**
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700173 * Retrieve the tasks on this display in stack order from the bottommost TaskStack up.
Craig Mautner00af9fe2013-03-25 09:13:41 -0700174 * @return All the Tasks, in order, on this display.
175 */
Craig Mautnerc00204b2013-03-05 15:02:14 -0800176 ArrayList<Task> getTasks() {
Craig Mautnerdc548482014-02-05 13:35:24 -0800177 mTmpTaskHistory.clear();
178 final int numStacks = mStacks.size();
179 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
180 mTmpTaskHistory.addAll(mStacks.get(stackNdx).getTasks());
Craig Mautnerd9a22882013-03-16 15:00:36 -0700181 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800182 return mTmpTaskHistory;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800183 }
184
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700185 TaskStack getHomeStack() {
Craig Mautner333c2ec2014-10-02 12:24:02 -0700186 if (mHomeStack == null && mDisplayId == Display.DEFAULT_DISPLAY) {
Craig Mautnere0a38842013-12-16 16:14:02 -0800187 Slog.e(TAG, "getHomeStack: Returning null from this=" + this);
188 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700189 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700190 }
191
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700192 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700193 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700194 mDisplay.getMetrics(mDisplayMetrics);
Wale Ogunwale58fa9de2015-10-08 22:01:06 -0700195 mDividerControllerLocked.updateDisplayInfo();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800196 for (int i = mStacks.size() - 1; i >= 0; --i) {
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700197 mStacks.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800198 }
Craig Mautner722285e2012-09-07 13:55:58 -0700199 }
200
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700201 void initializeDisplayBaseInfo() {
202 synchronized(mDisplaySizeLock) {
203 // Bootstrap the default logical display from the display manager.
204 final DisplayInfo newDisplayInfo =
205 mService.mDisplayManagerInternal.getDisplayInfo(mDisplayId);
206 if (newDisplayInfo != null) {
207 mDisplayInfo.copyFrom(newDisplayInfo);
208 }
209 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
210 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
211 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
212 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
213 }
214 }
215
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700216 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700217 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800218 final int orientation = mDisplayInfo.rotation;
219 boolean rotated = (orientation == Surface.ROTATION_90
220 || orientation == Surface.ROTATION_270);
221 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
222 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700223 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800224 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700225 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800226 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700227 out.set(left, top, left + width, top + height);
228 }
229
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700230 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
231 void attachStack(TaskStack stack, boolean onTop) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800232 if (stack.mStackId == HOME_STACK_ID) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800233 if (mHomeStack != null) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800234 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
Craig Mautnerde4ef022013-04-07 19:01:33 -0700235 }
Craig Mautnerdf88d732014-01-27 09:21:32 -0800236 mHomeStack = stack;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800237 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700238 if (onTop) {
239 mStacks.add(stack);
240 } else {
241 mStacks.add(0, stack);
242 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800243 layoutNeeded = true;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800244 }
245
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800246 void moveStack(TaskStack stack, boolean toTop) {
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700247 if (stack.mStackId == PINNED_STACK_ID && !toTop) {
248 // Pinned stack is always-on-top silly...
249 Slog.w(TAG, "Ignoring move of always-on-top stack=" + stack + " to bottom");
250 return;
251 }
252
Filip Gruszczynski26ed2652015-08-10 11:02:53 -0700253 if (!mStacks.remove(stack)) {
254 Slog.wtf(TAG, "moving stack that was not added: " + stack, new Throwable());
255 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700256
257 int addIndex = toTop ? mStacks.size() : 0;
258
259 if (toTop
260 && mService.isStackVisibleLocked(PINNED_STACK_ID)
261 && stack.mStackId != PINNED_STACK_ID) {
262 // The pinned stack is always the top most stack (always-on-top) when it is visible.
263 // So, stack is moved just below the pinned stack.
264 addIndex--;
265 TaskStack topStack = mStacks.get(addIndex);
266 if (topStack.mStackId != PINNED_STACK_ID) {
267 throw new IllegalStateException("Pinned stack isn't top stack??? " + mStacks);
268 }
269 }
270 mStacks.add(addIndex, stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800271 }
272
Craig Mautnerdf88d732014-01-27 09:21:32 -0800273 void detachStack(TaskStack stack) {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800274 mDimLayerController.removeDimLayerUser(stack);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800275 mStacks.remove(stack);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800276 }
277
278 /**
279 * Propagate the new bounds to all child stacks.
280 * @param contentRect The bounds to apply at the top level.
281 */
282 void resize(Rect contentRect) {
283 mContentRect.set(contentRect);
284 }
285
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700286 int taskIdFromPoint(int x, int y) {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800287 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700288 final ArrayList<Task> tasks = mStacks.get(stackNdx).getTasks();
289 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
290 final Task task = tasks.get(taskNdx);
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700291 // We need to use the visible frame on the window for any touch-related tests.
292 // Can't use the task's bounds because the original task bounds might be adjusted
293 // to fit the content frame. For example, the presence of the IME adjusting the
294 // windows frames when the app window is the IME target.
295 final WindowState win = task.getTopAppMainWindow();
296 if (win != null) {
297 win.getVisibleBounds(mTmpRect, !BOUNDS_FOR_TOUCH);
298 if (mTmpRect.contains(x, y)) {
299 return task.mTaskId;
300 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700301 }
Craig Mautner967212c2013-04-13 21:10:58 -0700302 }
303 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800304 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700305 }
306
Chong Zhang8e89b312015-09-09 15:09:30 -0700307 /**
Chong Zhang9184ec62015-09-24 12:32:21 -0700308 * Find the window whose outside touch area (for resizing) (x, y) falls within.
309 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700310 */
Chong Zhang9184ec62015-09-24 12:32:21 -0700311 WindowState findWindowForControlPoint(int x, int y) {
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700312 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Chong Zhang8e89b312015-09-09 15:09:30 -0700313 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
314 TaskStack stack = mStacks.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700315 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Chong Zhang8e89b312015-09-09 15:09:30 -0700316 break;
317 }
318 final ArrayList<Task> tasks = stack.getTasks();
319 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
320 final Task task = tasks.get(taskNdx);
321 if (task.isFullscreen()) {
Chong Zhang9184ec62015-09-24 12:32:21 -0700322 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700323 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700324
325 // We need to use the visible frame on the window for any touch-related
326 // tests. Can't use the task's bounds because the original task bounds
327 // might be adjusted to fit the content frame. (One example is when the
328 // task is put to top-left quadrant, the actual visible frame would not
329 // start at (0,0) after it's adjusted for the status bar.)
Wale Ogunwale12cbd922015-10-06 11:08:28 -0700330 final WindowState win = task.getTopAppMainWindow();
Chong Zhang9184ec62015-09-24 12:32:21 -0700331 if (win != null) {
332 win.getVisibleBounds(mTmpRect, !BOUNDS_FOR_TOUCH);
333 mTmpRect.inset(-delta, -delta);
334 if (mTmpRect.contains(x, y)) {
335 mTmpRect.inset(delta, delta);
336 if (!mTmpRect.contains(x, y)) {
337 return win;
338 }
339 // User touched inside the task. No need to look further,
340 // focus transfer will be handled in ACTION_UP.
341 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700342 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700343 }
344 }
345 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700346 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700347 }
348
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700349 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700350 mTouchExcludeRegion.set(mBaseDisplayRect);
351 WindowList windows = getWindowList();
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700352 final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Craig Mautner6601b7b2013-04-29 10:29:11 -0700353 for (int i = windows.size() - 1; i >= 0; --i) {
354 final WindowState win = windows.get(i);
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700355 final Task task = win.getTask();
Chong Zhang8e89b312015-09-09 15:09:30 -0700356 if (win.isVisibleLw() && task != null) {
357 /**
358 * Exclusion region is the region that TapDetector doesn't care about.
359 * Here we want to remove all non-focused tasks from the exclusion region.
360 * We also remove the outside touch area for resizing for all freeform
361 * tasks (including the focused).
362 *
363 * (For freeform focused task, the below logic will first remove the enlarged
364 * area, then add back the inner area.)
365 */
Chong Zhang09b21ef2015-09-14 10:20:21 -0700366 final boolean isFreeformed = task.inFreeformWorkspace();
Chong Zhang8e89b312015-09-09 15:09:30 -0700367 if (task != focusedTask || isFreeformed) {
368 mTmpRect.set(win.mVisibleFrame);
369 mTmpRect.intersect(win.mVisibleInsets);
370 /**
371 * If the task is freeformed, enlarge the area to account for outside
372 * touch area for resize.
373 */
374 if (isFreeformed) {
375 mTmpRect.inset(-delta, -delta);
376 }
377 mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
378 }
379 /**
380 * If we removed the focused task above, add it back and only leave its
381 * outside touch area in the exclusion. TapDectector is not interested in
382 * any touch inside the focused task itself.
383 */
384 if (task == focusedTask && isFreeformed) {
385 mTmpRect.inset(delta, delta);
386 mTouchExcludeRegion.op(mTmpRect, Region.Op.UNION);
387 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700388 }
389 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800390 if (mTapDetector != null) {
391 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
392 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700393 }
394
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800395 void switchUserStacks() {
Craig Mautner858d8a62013-04-23 17:08:34 -0700396 final WindowList windows = getWindowList();
397 for (int i = 0; i < windows.size(); i++) {
398 final WindowState win = windows.get(i);
399 if (win.isHiddenFromUserLocked()) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800400 if (DEBUG_VISIBILITY) Slog.w(TAG, "user changing, hiding " + win
401 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700402 win.hideLw(false);
403 }
404 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700405
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800406 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800407 mStacks.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700408 }
409 }
410
Craig Mautner05d29032013-05-03 13:40:13 -0700411 void resetAnimationBackgroundAnimator() {
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800412 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
413 mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700414 }
415 }
416
417 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800418 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700419 }
420
421 void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800422 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700423 }
424
425 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800426 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700427 }
428
429 void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800430 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700431 }
432
Craig Mautner2eb15342013-08-07 13:13:35 -0700433 void close() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800434 mDimLayerController.close();
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800435 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
436 mStacks.get(stackNdx).close();
Craig Mautner2eb15342013-08-07 13:13:35 -0700437 }
438 }
439
Craig Mautner95da1082014-02-24 17:54:35 -0800440 boolean isAnimating() {
441 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
442 final TaskStack stack = mStacks.get(stackNdx);
443 if (stack.isAnimating()) {
444 return true;
445 }
446 }
447 return false;
448 }
449
450 void checkForDeferredActions() {
451 boolean animating = false;
452 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
453 final TaskStack stack = mStacks.get(stackNdx);
454 if (stack.isAnimating()) {
455 animating = true;
456 } else {
457 if (stack.mDeferDetach) {
458 mService.detachStackLocked(this, stack);
459 }
460 final ArrayList<Task> tasks = stack.getTasks();
461 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
462 final Task task = tasks.get(taskNdx);
463 AppTokenList tokens = task.mAppTokens;
464 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
465 AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautner799bc1d2015-01-14 10:33:48 -0800466 if (wtoken.mIsExiting) {
Craig Mautnere3119b72015-01-20 15:02:36 -0800467 wtoken.removeAppFromTaskLocked();
Craig Mautner95da1082014-02-24 17:54:35 -0800468 }
469 }
Craig Mautner95da1082014-02-24 17:54:35 -0800470 }
471 }
472 }
473 if (!animating && mDeferredRemoval) {
474 mService.onDisplayRemoved(mDisplayId);
475 }
476 }
477
Wale Ogunwale94744212015-09-21 19:01:47 -0700478 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
479 final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation);
480 getLogicalDisplayRect(mTmpRect);
481 switch (rotationDelta) {
482 case Surface.ROTATION_0:
483 mTmpRect2.set(bounds);
484 break;
485 case Surface.ROTATION_90:
486 mTmpRect2.top = mTmpRect.bottom - bounds.right;
487 mTmpRect2.left = bounds.top;
488 mTmpRect2.right = mTmpRect2.left + bounds.height();
489 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
490 break;
491 case Surface.ROTATION_180:
492 mTmpRect2.top = mTmpRect.bottom - bounds.bottom;
493 mTmpRect2.left = mTmpRect.right - bounds.right;
494 mTmpRect2.right = mTmpRect2.left + bounds.width();
495 mTmpRect2.bottom = mTmpRect2.top + bounds.height();
496 break;
497 case Surface.ROTATION_270:
498 mTmpRect2.top = bounds.left;
499 mTmpRect2.left = mTmpRect.right - bounds.bottom;
500 mTmpRect2.right = mTmpRect2.left + bounds.height();
501 mTmpRect2.bottom = mTmpRect2.top + bounds.width();
502 break;
503 }
504 bounds.set(mTmpRect2);
505 }
506
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800507 static int deltaRotation(int oldRotation, int newRotation) {
508 int delta = newRotation - oldRotation;
509 if (delta < 0) delta += 4;
510 return delta;
511 }
512
Craig Mautnera91f9e22012-09-14 16:22:08 -0700513 public void dump(String prefix, PrintWriter pw) {
514 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
515 final String subPrefix = " " + prefix;
516 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
517 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
518 pw.print("dpi");
519 if (mInitialDisplayWidth != mBaseDisplayWidth
520 || mInitialDisplayHeight != mBaseDisplayHeight
521 || mInitialDisplayDensity != mBaseDisplayDensity) {
522 pw.print(" base=");
523 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
524 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
525 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700526 if (mDisplayScalingDisabled) {
527 pw.println(" noscale");
528 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700529 pw.print(" cur=");
530 pw.print(mDisplayInfo.logicalWidth);
531 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
532 pw.print(" app=");
533 pw.print(mDisplayInfo.appWidth);
534 pw.print("x"); pw.print(mDisplayInfo.appHeight);
535 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
536 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
537 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
538 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Craig Mautner95da1082014-02-24 17:54:35 -0800539 pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval);
540 pw.print(" layoutNeeded="); pw.println(layoutNeeded);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800541 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
542 final TaskStack stack = mStacks.get(stackNdx);
543 pw.print(prefix); pw.print("mStacks[" + stackNdx + "]"); pw.println(stack.mStackId);
544 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700545 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800546 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700547 pw.println(" Application tokens in top down Z order:");
Craig Mautnerdc548482014-02-05 13:35:24 -0800548 int ndx = 0;
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700549 for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800550 final TaskStack stack = mStacks.get(stackNdx);
551 pw.print(" mStackId="); pw.println(stack.mStackId);
552 ArrayList<Task> tasks = stack.getTasks();
Craig Mautnerdc548482014-02-05 13:35:24 -0800553 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800554 final Task task = tasks.get(taskNdx);
Craig Mautner83162a92015-01-26 14:43:30 -0800555 pw.print(" mTaskId="); pw.println(task.mTaskId);
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800556 AppTokenList tokens = task.mAppTokens;
557 for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx, ++ndx) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700558 final AppWindowToken wtoken = tokens.get(tokenNdx);
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800559 pw.print(" Activity #"); pw.print(tokenNdx);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700560 pw.print(' '); pw.print(wtoken); pw.println(":");
Craig Mautnerbcb6eb92015-01-13 13:09:22 -0800561 wtoken.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800562 }
563 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700564 }
Craig Mautnerdc548482014-02-05 13:35:24 -0800565 if (ndx == 0) {
566 pw.println(" None");
567 }
568 pw.println();
569 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700570 pw.println();
571 pw.println(" Exiting tokens:");
572 for (int i=mExitingTokens.size()-1; i>=0; i--) {
573 WindowToken token = mExitingTokens.get(i);
574 pw.print(" Exiting #"); pw.print(i);
575 pw.print(' '); pw.print(token);
576 pw.println(':');
577 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800578 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700579 }
Craig Mautner59c00972012-07-30 12:10:24 -0700580 pw.println();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800581 mDimLayerController.dump(prefix + " ", pw);
Craig Mautner59c00972012-07-30 12:10:24 -0700582 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800583
584 @Override
585 public String toString() {
586 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
587 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700588
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700589 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700590 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
591 return (stack != null && stack.isVisibleLocked()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700592 }
Craig Mautner59c00972012-07-30 12:10:24 -0700593}