blob: 65f2906547520e23d78a3bf08624e02a3df1f070 [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;
Wale Ogunwale51362492016-09-08 17:49:17 -070020import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -070021import static android.app.ActivityManager.StackId.HOME_STACK_ID;
22import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Wale Ogunwalea77e1462016-09-28 10:09:46 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
25import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070026import static android.view.Display.DEFAULT_DISPLAY;
27import static android.view.Display.FLAG_PRIVATE;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070028import static android.view.Surface.ROTATION_0;
29import static android.view.Surface.ROTATION_180;
30import static android.view.Surface.ROTATION_270;
31import static android.view.Surface.ROTATION_90;
Wale Ogunwale10124582016-09-15 20:25:50 -070032import static android.view.WindowManager.DOCKED_BOTTOM;
33import static android.view.WindowManager.DOCKED_INVALID;
34import static android.view.WindowManager.DOCKED_TOP;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080035import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
36import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
37import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070038import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwaleec731152016-09-08 20:18:57 -070039import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070041import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale10124582016-09-15 20:25:50 -070044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070045import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
46import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070047import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwaleec731152016-09-08 20:18:57 -070048import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080049import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Wale Ogunwale51362492016-09-08 17:49:17 -070050import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080051import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070052import static com.android.server.wm.WindowManagerService.dipToPixel;
53import static com.android.server.wm.WindowManagerService.localLOGV;
Wale Ogunwale231b06e2015-09-16 12:03:09 -070054import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -070055
Andrii Kulian3a507b52016-09-19 18:14:12 -070056import android.annotation.NonNull;
Wale Ogunwale3797c222015-10-27 14:21:58 -070057import android.app.ActivityManager.StackId;
Andrii Kulian441e4492016-09-29 15:25:00 -070058import android.content.res.Configuration;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070059import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -080060import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070061import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -070062import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +010063import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070064import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -070065import android.os.Debug;
Wale Ogunwale02319a62016-09-26 15:21:22 -070066import android.os.IBinder;
Chong Zhang8e89b312015-09-09 15:09:30 -070067import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -070068import android.util.Slog;
Craig Mautnerb47bbc32012-08-22 17:41:48 -070069import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070070import android.view.DisplayInfo;
Wale Ogunwaleec731152016-09-08 20:18:57 -070071import android.view.IWindow;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070072
Wale Ogunwale9adfe572016-09-08 20:43:58 -070073import com.android.internal.util.FastPrintWriter;
Craig Mautner59c00972012-07-30 12:10:24 -070074
Robert Carr3b716242016-08-16 16:02:21 -070075import java.io.FileDescriptor;
Craig Mautner59c00972012-07-30 12:10:24 -070076import java.io.PrintWriter;
Wale Ogunwale9adfe572016-09-08 20:43:58 -070077import java.io.StringWriter;
Craig Mautner59c00972012-07-30 12:10:24 -070078import java.util.ArrayList;
Wale Ogunwale9adfe572016-09-08 20:43:58 -070079import java.util.Arrays;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070080import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -070081import java.util.HashMap;
82import java.util.Iterator;
Andrii Kulian3a507b52016-09-19 18:14:12 -070083import java.util.List;
Craig Mautner59c00972012-07-30 12:10:24 -070084
Craig Mautner59c00972012-07-30 12:10:24 -070085/**
86 * Utility class for keeping track of the WindowStates and other pertinent contents of a
87 * particular Display.
88 *
89 * IMPORTANT: No method from this class should ever be used without holding
90 * WindowManagerService.mWindowMap.
91 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -070092class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Craig Mautner59c00972012-07-30 12:10:24 -070093
94 /** Unique identifier of this stack. */
95 private final int mDisplayId;
96
Wale Ogunwale19e452e2016-10-12 12:36:29 -070097 // The display only has 2 child window containers. mTaskStackContainers which contains all
98 // window containers that are related to apps (Activities) and mNonAppWindowContainers which
99 // contains all window containers not related to apps (e.g. Status bar).
100 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers();
101 private final NonAppWindowContainers mNonAppWindowContainers = new NonAppWindowContainers();
102
Craig Mautner59c00972012-07-30 12:10:24 -0700103 /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
104 * from mDisplayWindows; */
Craig Mautnerdc548482014-02-05 13:35:24 -0800105 private final WindowList mWindows = new WindowList();
Craig Mautner59c00972012-07-30 12:10:24 -0700106
Wale Ogunwale02319a62016-09-26 15:21:22 -0700107 // Mapping from a token IBinder to a WindowToken object on this display.
108 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
109
Craig Mautner59c00972012-07-30 12:10:24 -0700110 int mInitialDisplayWidth = 0;
111 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700112 int mInitialDisplayDensity = 0;
Craig Mautner59c00972012-07-30 12:10:24 -0700113 int mBaseDisplayWidth = 0;
114 int mBaseDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700115 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700116 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700117 private final DisplayInfo mDisplayInfo = new DisplayInfo();
118 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700119 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Craig Mautner59c00972012-07-30 12:10:24 -0700120
Craig Mautner6601b7b2013-04-29 10:29:11 -0700121 Rect mBaseDisplayRect = new Rect();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700122 private Rect mContentRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700123
Craig Mautner39834192012-09-02 07:47:24 -0700124 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700125 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700126 int pendingLayoutChanges;
Craig Mautner69b08182012-09-05 13:07:13 -0700127 final boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700128
Craig Mautnerdc548482014-02-05 13:35:24 -0800129 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700130 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800131
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800132 /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
133 * (except a future lockscreen TaskStack) moves to the top. */
Craig Mautnerde4ef022013-04-07 19:01:33 -0700134 private TaskStack mHomeStack = null;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700135
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700136 /** Detect user tapping outside of current focused task bounds .*/
137 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700138
Craig Mautner6601b7b2013-04-29 10:29:11 -0700139 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700140 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700141
Craig Mautner6601b7b2013-04-29 10:29:11 -0700142 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800143 private final Rect mTmpRect = new Rect();
144 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700145 private final RectF mTmpRectF = new RectF();
146 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800147 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700148
Craig Mautner9d808b12013-08-06 18:00:25 -0700149 final WindowManagerService mService;
150
Craig Mautner95da1082014-02-24 17:54:35 -0800151 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700152 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800153
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700154 final DockedStackDividerController mDividerControllerLocked;
155
Chong Zhang112eb8c2015-11-02 11:17:00 -0800156 final DimLayerController mDimLayerController;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700157
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800158 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
159
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700160 /** Used when rebuilding window list to keep track of windows that have been removed. */
161 private WindowState[] mRebuildTmp = new WindowState[20];
162
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700163 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
164 new TaskForResizePointSearchResult();
165 private final GetWindowOnDisplaySearchResult mTmpGetWindowOnDisplaySearchResult =
166 new GetWindowOnDisplaySearchResult();
167
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700168 // True if this display is in the process of being removed. Used to determine if the removal of
169 // the display's direct children should be allowed.
170 private boolean mRemovingDisplay = false;
171
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800172 /**
Craig Mautner2d5618c2012-10-18 13:55:47 -0700173 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800174 * @param service You know.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700175 */
Craig Mautner9d808b12013-08-06 18:00:25 -0700176 DisplayContent(Display display, WindowManagerService service) {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700177 mDisplay = display;
178 mDisplayId = display.getDisplayId();
179 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700180 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700181 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Craig Mautner9d808b12013-08-06 18:00:25 -0700182 mService = service;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700183 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800184 mDividerControllerLocked = new DockedStackDividerController(service, this);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800185 mDimLayerController = new DimLayerController(this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700186
187 // These are the only direct children we should ever have and they are permanent.
188 super.addChild(mTaskStackContainers, null);
189 super.addChild(mNonAppWindowContainers, null);
Craig Mautner59c00972012-07-30 12:10:24 -0700190 }
191
192 int getDisplayId() {
193 return mDisplayId;
194 }
195
196 WindowList getWindowList() {
197 return mWindows;
198 }
199
Wale Ogunwale02319a62016-09-26 15:21:22 -0700200 WindowToken getWindowToken(IBinder binder) {
201 return mTokenMap.get(binder);
202 }
203
204 AppWindowToken getAppWindowToken(IBinder binder) {
205 final WindowToken token = getWindowToken(binder);
206 if (token == null) {
207 return null;
208 }
209 return token.asAppWindowToken();
210 }
211
212 void setWindowToken(IBinder binder, WindowToken token) {
213 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
214 if (dc != null) {
215 // We currently don't support adding a window token to the display if the display
216 // already has the binder mapped to another token. If there is a use case for supporting
217 // this moving forward we will either need to merge the WindowTokens some how or have
218 // the binder map to a list of window tokens.
219 throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this
220 + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
221 }
222 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700223
224 if (token.asAppWindowToken() == null) {
225 // Add non-app token to container hierarchy on the display. App tokens are added through
226 // the parent container managing them (e.g. Tasks).
227 mNonAppWindowContainers.addChild(token, null);
228 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700229 }
230
231 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700232 final WindowToken token = mTokenMap.remove(binder);
233 if (token != null && token.asAppWindowToken() == null) {
234 mNonAppWindowContainers.removeChild(token);
235 }
236 return token;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700237 }
238
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700239 Display getDisplay() {
240 return mDisplay;
241 }
242
Craig Mautner59c00972012-07-30 12:10:24 -0700243 DisplayInfo getDisplayInfo() {
244 return mDisplayInfo;
245 }
246
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700247 DisplayMetrics getDisplayMetrics() {
248 return mDisplayMetrics;
249 }
250
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100251 DockedStackDividerController getDockedDividerController() {
252 return mDividerControllerLocked;
253 }
254
Jeff Browna506a6e2013-06-04 00:02:38 -0700255 /**
256 * Returns true if the specified UID has access to this display.
257 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700258 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -0700259 return mDisplay.hasAccess(uid);
260 }
261
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700262 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700263 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -0700264 }
265
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700266 TaskStack getHomeStack() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700267 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800268 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
Craig Mautnere0a38842013-12-16 16:14:02 -0800269 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700270 return mHomeStack;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700271 }
272
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700273 TaskStack getStackById(int stackId) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700274 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
275 final TaskStack stack = mTaskStackContainers.get(i);
Chong Zhangd9d35bd2016-08-04 17:55:21 -0700276 if (stack.mStackId == stackId) {
277 return stack;
278 }
279 }
280 return null;
281 }
282
Andrii Kulian441e4492016-09-29 15:25:00 -0700283 @Override
284 void onConfigurationChanged(Configuration newParentConfig) {
285 super.onConfigurationChanged(newParentConfig);
286
Andrii Kulian3a507b52016-09-19 18:14:12 -0700287 // The display size information is heavily dependent on the resources in the current
288 // configuration, so we need to reconfigure it every time the configuration changes.
289 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
290 mService.reconfigureDisplayLocked(this);
291
292 getDockedDividerController().onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700293 }
Andrii Kulian3a507b52016-09-19 18:14:12 -0700294
Andrii Kulian441e4492016-09-29 15:25:00 -0700295 /**
296 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
297 * bounds were updated.
298 */
299 void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700300 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
301 final TaskStack stack = mTaskStackContainers.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700302 if (stack.updateBoundsAfterConfigChange()) {
Andrii Kulian3a507b52016-09-19 18:14:12 -0700303 changedStackList.add(stack.mStackId);
304 }
305 }
306 }
307
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700308 void checkAppWindowsReadyToShow() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700309 super.checkAppWindowsReadyToShow(mDisplayId);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700310 }
311
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700312 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale10124582016-09-15 20:25:50 -0700313 super.stepAppWindowsAnimation(currentTime, mDisplayId);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700314 }
315
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700316 @Override
317 boolean fillsParent() {
318 return true;
319 }
320
321 @Override
322 boolean isVisible() {
323 return true;
324 }
325
326 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700327 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700328 super.onAppTransitionDone();
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700329 rebuildAppWindowList();
330 }
331
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700332 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -0700333 int getOrientation() {
Wale Ogunwale51362492016-09-08 17:49:17 -0700334 if (mService.isStackVisibleLocked(DOCKED_STACK_ID)
335 || mService.isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID)) {
336 // Apps and their containers are not allowed to specify an orientation while the docked
337 // or freeform stack is visible...except for the home stack/task if the docked stack is
338 // minimized and it actually set something.
Andrii Kulian8072d112016-09-16 11:11:01 -0700339 if (mHomeStack != null && mHomeStack.isVisible()
340 && mDividerControllerLocked.isMinimizedDock()) {
Wale Ogunwale51362492016-09-08 17:49:17 -0700341 final int orientation = mHomeStack.getOrientation();
342 if (orientation != SCREEN_ORIENTATION_UNSET) {
343 return orientation;
344 }
345 }
346 return SCREEN_ORIENTATION_UNSPECIFIED;
347 }
348
Wale Ogunwale10124582016-09-15 20:25:50 -0700349 final int orientation = super.getOrientation();
Wale Ogunwalea77e1462016-09-28 10:09:46 -0700350 if (orientation != SCREEN_ORIENTATION_UNSET && orientation != SCREEN_ORIENTATION_BEHIND) {
Wale Ogunwale10124582016-09-15 20:25:50 -0700351 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
352 "App is requesting an orientation, return " + orientation);
353 return orientation;
Wale Ogunwale51362492016-09-08 17:49:17 -0700354 }
355
356 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
357 "No app is requesting an orientation, return " + mService.mLastOrientation);
358 // The next app has not been requested to be visible, so we keep the current orientation
359 // to prevent freezing/unfreezing the display too early.
360 return mService.mLastOrientation;
361 }
362
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700363 void updateDisplayInfo() {
Craig Mautner722285e2012-09-07 13:55:58 -0700364 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700365 mDisplay.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700366 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
367 mTaskStackContainers.get(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800368 }
Craig Mautner722285e2012-09-07 13:55:58 -0700369 }
370
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700371 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700372 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
373 if (displayManagerInternal != null) {
374 // Bootstrap the default logical display from the display manager.
375 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
376 if (newDisplayInfo != null) {
377 mDisplayInfo.copyFrom(newDisplayInfo);
378 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700379 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700380
Filip Gruszczynski608797e2015-11-12 19:08:20 -0800381 mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
382 mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
383 mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
384 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700385 }
386
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700387 void getLogicalDisplayRect(Rect out) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700388 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Craig Mautner4a1cb222013-12-04 16:14:06 -0800389 final int orientation = mDisplayInfo.rotation;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700390 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
Craig Mautner4a1cb222013-12-04 16:14:06 -0800391 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
392 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700393 int width = mDisplayInfo.logicalWidth;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800394 int left = (physWidth - width) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700395 int height = mDisplayInfo.logicalHeight;
Craig Mautner4a1cb222013-12-04 16:14:06 -0800396 int top = (physHeight - height) / 2;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700397 out.set(left, top, left + width, top + height);
398 }
399
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700400 private void getLogicalDisplayRect(Rect out, int orientation) {
401 getLogicalDisplayRect(out);
402
403 // Rotate the Rect if needed.
404 final int currentRotation = mDisplayInfo.rotation;
405 final int rotationDelta = deltaRotation(currentRotation, orientation);
406 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
407 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
408 mTmpRectF.set(out);
409 mTmpMatrix.mapRect(mTmpRectF);
410 mTmpRectF.round(out);
411 }
412 }
413
Chong Zhangf66db432016-01-13 10:39:51 -0800414 void getContentRect(Rect out) {
415 out.set(mContentRect);
416 }
417
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700418 /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
419 void attachStack(TaskStack stack, boolean onTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700420 mTaskStackContainers.attachStack(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -0800421 }
422
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800423 void moveStack(TaskStack stack, boolean toTop) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700424 mTaskStackContainers.moveStack(stack, toTop);
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700425 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700426
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700427 @Override
428 protected void addChild(DisplayChildWindowContainer child,
429 Comparator<DisplayChildWindowContainer> comparator) {
430 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
431 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -0700432
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700433 @Override
434 protected void addChild(DisplayChildWindowContainer child, int index) {
435 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
436 }
437
438 @Override
439 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700440 // Only allow removal of direct children from this display if the display is in the process
441 // of been removed.
442 if (mRemovingDisplay) {
443 super.removeChild(child);
444 return;
445 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700446 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800447 }
448
449 /**
450 * Propagate the new bounds to all child stacks.
451 * @param contentRect The bounds to apply at the top level.
452 */
453 void resize(Rect contentRect) {
454 mContentRect.set(contentRect);
455 }
456
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700457 int taskIdFromPoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700458 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
459 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700460 final int taskId = stack.taskIdFromPoint(x, y);
461 if (taskId != -1) {
462 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -0700463 }
464 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800465 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -0700466 }
467
Chong Zhang8e89b312015-09-09 15:09:30 -0700468 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -0800469 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -0700470 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -0700471 */
Wale Ogunwale15ead902016-09-02 14:30:11 -0700472 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700473 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700474 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700475 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
476 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3797c222015-10-27 14:21:58 -0700477 if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700478 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700479 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700480
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700481 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
482 if (mTmpTaskForResizePointSearchResult.searchDone) {
483 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -0700484 }
485 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700486 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -0700487 }
488
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700489 void setTouchExcludeRegion(Task focusedTask) {
Craig Mautner6601b7b2013-04-29 10:29:11 -0700490 mTouchExcludeRegion.set(mBaseDisplayRect);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700491 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700492 mTmpRect2.setEmpty();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700493 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
494 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700495 stack.setTouchExcludeRegion(
496 focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2);
Craig Mautner6601b7b2013-04-29 10:29:11 -0700497 }
Chong Zhangd8ceb852015-11-11 14:53:41 -0800498 // If we removed the focused task above, add it back and only leave its
499 // outside touch area in the exclusion. TapDectector is not interested in
500 // any touch inside the focused task itself.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700501 if (!mTmpRect2.isEmpty()) {
Chong Zhangd8ceb852015-11-11 14:53:41 -0800502 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
503 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800504 final WindowState inputMethod = mService.mInputMethodWindow;
505 if (inputMethod != null && inputMethod.isVisibleLw()) {
506 // If the input method is visible and the user is typing, we don't want these touch
507 // events to be intercepted and used to change focus. This would likely cause a
508 // disappearance of the input method.
509 inputMethod.getTouchableRegion(mTmpRegion);
510 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
511 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800512 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
513 WindowState win = mTapExcludedWindows.get(i);
514 win.getTouchableRegion(mTmpRegion);
515 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
516 }
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100517 if (getDockedStackVisibleForUserLocked() != null) {
518 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -0700519 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100520 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
521 }
Craig Mautner1bef3892015-02-17 15:09:47 -0800522 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700523 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -0800524 }
Craig Mautner6601b7b2013-04-29 10:29:11 -0700525 }
526
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700527 void switchUser() {
Craig Mautner858d8a62013-04-23 17:08:34 -0700528 final WindowList windows = getWindowList();
529 for (int i = 0; i < windows.size(); i++) {
530 final WindowState win = windows.get(i);
531 if (win.isHiddenFromUserLocked()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800532 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + win
Wale Ogunwale498e8c92015-02-13 09:42:46 -0800533 + ", attrs=" + win.mAttrs.type + ", belonging to " + win.mOwnerUid);
Craig Mautner858d8a62013-04-23 17:08:34 -0700534 win.hideLw(false);
535 }
536 }
Craig Mautnerac6f8432013-07-17 13:24:59 -0700537
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700538 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
539 mTaskStackContainers.get(stackNdx).switchUser();
Craig Mautner858d8a62013-04-23 17:08:34 -0700540 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700541
542 rebuildAppWindowList();
Craig Mautner858d8a62013-04-23 17:08:34 -0700543 }
544
Craig Mautner05d29032013-05-03 13:40:13 -0700545 void resetAnimationBackgroundAnimator() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700546 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
547 mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -0700548 }
549 }
550
551 boolean animateDimLayers() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800552 return mDimLayerController.animateDimLayers();
Craig Mautner05d29032013-05-03 13:40:13 -0700553 }
554
555 void resetDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800556 mDimLayerController.resetDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700557 }
558
559 boolean isDimming() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800560 return mDimLayerController.isDimming();
Craig Mautner05d29032013-05-03 13:40:13 -0700561 }
562
563 void stopDimmingIfNeeded() {
Chong Zhang112eb8c2015-11-02 11:17:00 -0800564 mDimLayerController.stopDimmingIfNeeded();
Craig Mautner05d29032013-05-03 13:40:13 -0700565 }
566
Wale Ogunwale10124582016-09-15 20:25:50 -0700567 @Override
568 void removeIfPossible() {
569 if (isAnimating()) {
570 mDeferredRemoval = true;
571 return;
Craig Mautner2eb15342013-08-07 13:13:35 -0700572 }
Wale Ogunwale10124582016-09-15 20:25:50 -0700573 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -0700574 }
575
Wale Ogunwale10124582016-09-15 20:25:50 -0700576 @Override
577 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700578 mRemovingDisplay = true;
579 try {
580 super.removeImmediately();
581 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
582 mDimLayerController.close();
583 if (mDisplayId == DEFAULT_DISPLAY) {
584 mService.unregisterPointerEventListener(mTapDetector);
585 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
586 }
587 } finally {
588 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -0800589 }
Craig Mautner95da1082014-02-24 17:54:35 -0800590 }
591
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700592 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -0700593 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700594 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -0700595 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
596
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700597 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -0700598 removeImmediately();
Craig Mautner95da1082014-02-24 17:54:35 -0800599 mService.onDisplayRemoved(mDisplayId);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700600 return false;
Craig Mautner95da1082014-02-24 17:54:35 -0800601 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700602 return true;
Craig Mautner95da1082014-02-24 17:54:35 -0800603 }
604
Wale Ogunwale10124582016-09-15 20:25:50 -0700605 boolean animateForIme(float interpolatedValue, float animationTarget,
606 float dividerAnimationTarget) {
607 boolean updated = false;
608
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700609 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
610 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700611 if (stack == null || !stack.isAdjustedForIme()) {
612 continue;
613 }
614
615 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
616 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
617 updated = true;
618 } else {
619 mDividerControllerLocked.mLastAnimationProgress =
620 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
621 mDividerControllerLocked.mLastDividerProgress =
622 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
623 updated |= stack.updateAdjustForIme(
624 mDividerControllerLocked.mLastAnimationProgress,
625 mDividerControllerLocked.mLastDividerProgress,
626 false /* force */);
627 }
628 if (interpolatedValue >= 1f) {
629 stack.endImeAdjustAnimation();
630 }
631 }
632
633 return updated;
634 }
635
636 boolean clearImeAdjustAnimation() {
637 boolean changed = false;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700638 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
639 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700640 if (stack != null && stack.isAdjustedForIme()) {
641 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
642 changed = true;
643 }
644 }
645 return changed;
646 }
647
648 void beginImeAdjustAnimation() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700649 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
650 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700651 if (stack.isVisible() && stack.isAdjustedForIme()) {
652 stack.beginImeAdjustAnimation();
653 }
654 }
655 }
656
657 void adjustForImeIfNeeded() {
658 final WindowState imeWin = mService.mInputMethodWindow;
659 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
660 && !mDividerControllerLocked.isImeHideRequested();
661 final boolean dockVisible = mService.isStackVisibleLocked(DOCKED_STACK_ID);
662 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
663 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
664 imeTargetStack.getDockSide() : DOCKED_INVALID;
665 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
666 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
667 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
668 final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw();
669 final boolean imeHeightChanged = imeVisible &&
670 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
671
672 // The divider could be adjusted for IME position, or be thinner than usual,
673 // or both. There are three possible cases:
674 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
675 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
676 // - If IME is not visible, divider is not moved and is normal width.
677
678 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700679 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
680 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700681 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
682 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)) {
683 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
684 } else {
685 stack.resetAdjustedForIme(false);
686 }
687 }
688 mDividerControllerLocked.setAdjustedForIme(
689 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
690 } else {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700691 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
692 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale10124582016-09-15 20:25:50 -0700693 stack.resetAdjustedForIme(!dockVisible);
694 }
695 mDividerControllerLocked.setAdjustedForIme(
696 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
697 }
698 }
699
700 void prepareFreezingTaskBounds() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700701 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
702 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -0700703 stack.prepareFreezingTaskBounds();
704 }
705 }
706
Wale Ogunwale94744212015-09-21 19:01:47 -0700707 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700708 getLogicalDisplayRect(mTmpRect, newRotation);
709
710 // Compute a transform matrix to undo the coordinate space transformation,
711 // and present the window at the same physical position it previously occupied.
712 final int deltaRotation = deltaRotation(newRotation, oldRotation);
713 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
714
715 mTmpRectF.set(bounds);
716 mTmpMatrix.mapRect(mTmpRectF);
717 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -0700718 }
719
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800720 static int deltaRotation(int oldRotation, int newRotation) {
721 int delta = newRotation - oldRotation;
722 if (delta < 0) delta += 4;
723 return delta;
724 }
725
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700726 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700727 Matrix outMatrix) {
728 // For rotations without Z-ordering we don't need the target rectangle's position.
729 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
730 displayHeight, outMatrix);
731 }
732
733 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
734 float displayWidth, float displayHeight, Matrix outMatrix) {
735 switch (rotation) {
736 case ROTATION_0:
737 outMatrix.reset();
738 break;
739 case ROTATION_270:
740 outMatrix.setRotate(270, 0, 0);
741 outMatrix.postTranslate(0, displayHeight);
742 outMatrix.postTranslate(rectTop, 0);
743 break;
744 case ROTATION_180:
745 outMatrix.reset();
746 break;
747 case ROTATION_90:
748 outMatrix.setRotate(90, 0, 0);
749 outMatrix.postTranslate(displayWidth, 0);
750 outMatrix.postTranslate(-rectTop, rectLeft);
751 break;
752 }
753 }
754
Craig Mautnera91f9e22012-09-14 16:22:08 -0700755 public void dump(String prefix, PrintWriter pw) {
756 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
757 final String subPrefix = " " + prefix;
758 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
759 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
760 pw.print("dpi");
761 if (mInitialDisplayWidth != mBaseDisplayWidth
762 || mInitialDisplayHeight != mBaseDisplayHeight
763 || mInitialDisplayDensity != mBaseDisplayDensity) {
764 pw.print(" base=");
765 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
766 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
767 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700768 if (mDisplayScalingDisabled) {
769 pw.println(" noscale");
770 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700771 pw.print(" cur=");
772 pw.print(mDisplayInfo.logicalWidth);
773 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
774 pw.print(" app=");
775 pw.print(mDisplayInfo.appWidth);
776 pw.print("x"); pw.print(mDisplayInfo.appHeight);
777 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
778 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
779 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
780 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700781 pw.println(subPrefix + "deferred=" + mDeferredRemoval
782 + " mLayoutNeeded=" + mLayoutNeeded);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800783
Craig Mautnerdc548482014-02-05 13:35:24 -0800784 pw.println();
Craig Mautnere8b85fd2014-10-22 09:23:25 -0700785 pw.println(" Application tokens in top down Z order:");
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700786 for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
787 final TaskStack stack = mTaskStackContainers.get(stackNdx);
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800788 stack.dump(prefix + " ", pw);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700789 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800790
Craig Mautnerdc548482014-02-05 13:35:24 -0800791 pw.println();
792 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -0700793 pw.println();
794 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -0800795 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700796 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -0700797 pw.print(" Exiting #"); pw.print(i);
798 pw.print(' '); pw.print(token);
799 pw.println(':');
800 token.dump(pw, " ");
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800801 }
Craig Mautnerde4ef022013-04-07 19:01:33 -0700802 }
Craig Mautner59c00972012-07-30 12:10:24 -0700803 pw.println();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800804 mDimLayerController.dump(prefix + " ", pw);
Jorim Jaggi31f71702016-05-04 16:43:04 -0700805 pw.println();
806 mDividerControllerLocked.dump(prefix + " ", pw);
Craig Mautner59c00972012-07-30 12:10:24 -0700807 }
Craig Mautnere0a38842013-12-16 16:14:02 -0800808
809 @Override
810 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700811 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700812 }
813
814 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700815 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -0800816 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700817
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800818 /**
819 * @return The docked stack, but only if it is visible, and {@code null} otherwise.
820 */
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700821 TaskStack getDockedStackLocked() {
Wale Ogunwalee45899a2015-10-01 11:30:34 -0700822 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700823 return (stack != null && stack.isVisible()) ? stack : null;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700824 }
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800825
826 /**
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800827 * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not
828 * visible, as long as it's not hidden because the current user doesn't have any tasks there.
829 */
830 TaskStack getDockedStackVisibleForUserLocked() {
831 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700832 return (stack != null && stack.isVisible(true /* ignoreKeyguard */)) ? stack : null;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800833 }
834
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700835 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -0800836 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
837 WindowState touchedWin = null;
838 final int x = (int) xf;
839 final int y = (int) yf;
840
841 for (int i = mWindows.size() - 1; i >= 0; i--) {
842 WindowState window = mWindows.get(i);
843 final int flags = window.mAttrs.flags;
844 if (!window.isVisibleLw()) {
845 continue;
846 }
847 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
848 continue;
849 }
850
851 window.getVisibleBounds(mTmpRect);
852 if (!mTmpRect.contains(x, y)) {
853 continue;
854 }
855
856 window.getTouchableRegion(mTmpRegion);
857
858 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
859 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
860 touchedWin = window;
861 break;
862 }
863 }
864
865 return touchedWin;
866 }
Jorim Jaggi6626f542016-08-22 13:08:44 -0700867
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700868 boolean canAddToastWindowForUid(int uid) {
869 // We allow one toast window per UID being shown at a time.
870 WindowList windows = getWindowList();
871 final int windowCount = windows.size();
872 for (int i = 0; i < windowCount; i++) {
873 WindowState window = windows.get(i);
874 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == uid
Svet Ganov62a40f82016-09-29 00:43:51 -0700875 && !window.mPermanentlyHidden && !window.mAnimatingExit
876 && !window.mRemoveOnExit) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700877 return false;
878 }
879 }
880 return true;
881 }
882
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700883 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700884 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
885 return;
886 }
887 final int lostFocusUid = oldFocus.mOwnerUid;
888 WindowList windows = getWindowList();
889 final int windowCount = windows.size();
890 for (int i = 0; i < windowCount; i++) {
891 WindowState window = windows.get(i);
892 if (window.mAttrs.type == TYPE_TOAST && window.mOwnerUid == lostFocusUid) {
893 if (!mService.mH.hasMessages(WindowManagerService.H.WINDOW_HIDE_TIMEOUT, window)) {
894 mService.mH.sendMessageDelayed(
895 mService.mH.obtainMessage(
896 WindowManagerService.H.WINDOW_HIDE_TIMEOUT, window),
897 window.mAttrs.hideTimeoutMilliseconds);
898 }
899 }
900 }
901 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -0700902
903 WindowState findFocusedWindow() {
904 final AppWindowToken focusedApp = mService.mFocusedApp;
905
906 for (int i = mWindows.size() - 1; i >= 0; i--) {
907 final WindowState win = mWindows.get(i);
908
909 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + i + " = " + win
910 + ", flags=" + win.mAttrs.flags + ", canReceive=" + win.canReceiveKeys());
911
912 if (!win.canReceiveKeys()) {
913 continue;
914 }
915
916 final AppWindowToken wtoken = win.mAppToken;
917
918 // If this window's application has been removed, just skip it.
919 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
920 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
921 + (wtoken.removed ? "removed" : "sendingToBottom"));
922 continue;
923 }
924
925 if (focusedApp == null) {
926 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
927 + " using new focus @ " + i + " = " + win);
928 return win;
929 }
930
931 if (!focusedApp.windowsAreFocusable()) {
932 // Current focused app windows aren't focusable...
933 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
934 + " focusable using new focus @ " + i + " = " + win);
935 return win;
936 }
937
938 // Descend through all of the app tokens and find the first that either matches
939 // win.mAppToken (return win) or mFocusedApp (return null).
940 if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
Wale Ogunwale10124582016-09-15 20:25:50 -0700941 if (focusedApp.compareTo(wtoken) > 0) {
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -0700942 // App stack below focused app stack. No focus for you!!!
943 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
944 "findFocusedWindow: Reached focused app=" + focusedApp);
945 return null;
946 }
947 }
948
949 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ "
950 + i + " = " + win);
951 return win;
952 }
953
954 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
955 return null;
956 }
Wale Ogunwaleec731152016-09-08 20:18:57 -0700957
958 int addAppWindowToWindowList(final WindowState win) {
959 final IWindow client = win.mClient;
960
961 WindowList tokenWindowList = getTokenWindowsOnDisplay(win.mToken);
962 if (!tokenWindowList.isEmpty()) {
963 return addAppWindowExisting(win, tokenWindowList);
964 }
965
966 // No windows from this token on this display
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700967 if (localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window "
Wale Ogunwaleec731152016-09-08 20:18:57 -0700968 + client.asBinder() + " (token=" + this + ")");
969
970 final WindowToken wToken = win.mToken;
971
972 // Figure out where the window should go, based on the order of applications.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700973 mTmpGetWindowOnDisplaySearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700974 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
975 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700976 stack.getWindowOnDisplayBeforeToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
977 if (mTmpGetWindowOnDisplaySearchResult.reachedToken) {
Wale Ogunwaleec731152016-09-08 20:18:57 -0700978 // We have reach the token we are interested in. End search.
979 break;
980 }
981 }
982
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700983 WindowState pos = mTmpGetWindowOnDisplaySearchResult.foundWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -0700984
985 // We now know the index into the apps. If we found an app window above, that gives us the
986 // position; else we need to look some more.
987 if (pos != null) {
988 // Move behind any windows attached to this one.
Wale Ogunwale02319a62016-09-26 15:21:22 -0700989 final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
Wale Ogunwaleec731152016-09-08 20:18:57 -0700990 if (atoken != null) {
991 tokenWindowList = getTokenWindowsOnDisplay(atoken);
992 final int NC = tokenWindowList.size();
993 if (NC > 0) {
994 WindowState bottom = tokenWindowList.get(0);
995 if (bottom.mSubLayer < 0) {
996 pos = bottom;
997 }
998 }
999 }
1000 addWindowToListBefore(win, pos);
1001 return 0;
1002 }
1003
1004 // Continue looking down until we find the first token that has windows on this display.
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001005 mTmpGetWindowOnDisplaySearchResult.reset();
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001006 for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
1007 final TaskStack stack = mTaskStackContainers.get(i);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001008 stack.getWindowOnDisplayAfterToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
1009 if (mTmpGetWindowOnDisplaySearchResult.foundWindow != null) {
Wale Ogunwaleec731152016-09-08 20:18:57 -07001010 // We have found a window after the token. End search.
1011 break;
1012 }
1013 }
1014
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001015 pos = mTmpGetWindowOnDisplaySearchResult.foundWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07001016
1017 if (pos != null) {
1018 // Move in front of any windows attached to this one.
Wale Ogunwale02319a62016-09-26 15:21:22 -07001019 final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
Wale Ogunwaleec731152016-09-08 20:18:57 -07001020 if (atoken != null) {
1021 final WindowState top = atoken.getTopWindow();
1022 if (top != null && top.mSubLayer >= 0) {
1023 pos = top;
1024 }
1025 }
1026 addWindowToListAfter(win, pos);
1027 return 0;
1028 }
1029
1030 // Just search for the start of this layer.
1031 final int myLayer = win.mBaseLayer;
1032 int i;
1033 for (i = mWindows.size() - 1; i >= 0; --i) {
1034 final WindowState w = mWindows.get(i);
1035 // Dock divider shares the base layer with application windows, but we want to always
1036 // keep it above the application windows. The sharing of the base layer is intended
1037 // for window animations, which need to be above the dock divider for the duration
1038 // of the animation.
1039 if (w.mBaseLayer <= myLayer && w.mAttrs.type != TYPE_DOCK_DIVIDER) {
1040 break;
1041 }
1042 }
1043 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1044 "Based on layer: Adding window " + win + " at " + (i + 1) + " of "
1045 + mWindows.size());
1046 mWindows.add(i + 1, win);
1047 mService.mWindowsChanged = true;
1048 return 0;
1049 }
1050
1051 /** Adds this non-app window to the window list. */
1052 void addNonAppWindowToWindowList(WindowState win) {
1053 // Figure out where window should go, based on layer.
1054 int i;
1055 for (i = mWindows.size() - 1; i >= 0; i--) {
1056 final WindowState otherWin = mWindows.get(i);
1057 if (otherWin.getBaseType() != TYPE_WALLPAPER && otherWin.mBaseLayer <= win.mBaseLayer) {
1058 // Wallpaper wanders through the window list, for example to position itself
1059 // directly behind keyguard. Because of this it will break the ordering based on
1060 // WindowState.mBaseLayer. There might windows with higher mBaseLayer behind it and
1061 // we don't want the new window to appear above them. An example of this is adding
1062 // of the docked stack divider. Consider a scenario with the following ordering (top
1063 // to bottom): keyguard, wallpaper, assist preview, apps. We want the dock divider
1064 // to land below the assist preview, so the dock divider must ignore the wallpaper,
1065 // with which it shares the base layer.
1066 break;
1067 }
1068 }
1069
1070 i++;
1071 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1072 "Free window: Adding window " + this + " at " + i + " of " + mWindows.size());
1073 mWindows.add(i, win);
1074 mService.mWindowsChanged = true;
1075 }
1076
Wale Ogunwaleb9a07c32016-10-12 14:55:56 -07001077 void addToWindowList(WindowState win, int index) {
1078 mWindows.add(index, win);
1079 }
1080
Wale Ogunwaleec731152016-09-08 20:18:57 -07001081 void addChildWindowToWindowList(WindowState win) {
1082 final WindowState parentWindow = win.getParentWindow();
1083
1084 WindowList windowsOnSameDisplay = getTokenWindowsOnDisplay(win.mToken);
1085
1086 // Figure out this window's ordering relative to the parent window.
1087 final int wCount = windowsOnSameDisplay.size();
1088 final int sublayer = win.mSubLayer;
1089 int largestSublayer = Integer.MIN_VALUE;
1090 WindowState windowWithLargestSublayer = null;
1091 int i;
1092 for (i = 0; i < wCount; i++) {
1093 WindowState w = windowsOnSameDisplay.get(i);
1094 final int wSublayer = w.mSubLayer;
1095 if (wSublayer >= largestSublayer) {
1096 largestSublayer = wSublayer;
1097 windowWithLargestSublayer = w;
1098 }
1099 if (sublayer < 0) {
1100 // For negative sublayers, we go below all windows in the same sublayer.
1101 if (wSublayer >= sublayer) {
1102 addWindowToListBefore(win, wSublayer >= 0 ? parentWindow : w);
1103 break;
1104 }
1105 } else {
1106 // For positive sublayers, we go above all windows in the same sublayer.
1107 if (wSublayer > sublayer) {
1108 addWindowToListBefore(win, w);
1109 break;
1110 }
1111 }
1112 }
1113 if (i >= wCount) {
1114 if (sublayer < 0) {
1115 addWindowToListBefore(win, parentWindow);
1116 } else {
1117 addWindowToListAfter(win,
1118 largestSublayer >= 0 ? windowWithLargestSublayer : parentWindow);
1119 }
1120 }
1121 }
1122
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001123 /**
1124 * Z-orders the display window list so that:
1125 * <ul>
1126 * <li>Any windows that are currently below the wallpaper window stay below the wallpaper
1127 * window.
1128 * <li>Exiting application windows are at the bottom, but above the wallpaper window.
1129 * <li>All other application windows are above the exiting application windows and ordered based
1130 * on the ordering of their stacks and tasks on the display.
1131 * <li>Non-application windows are at the very top.
1132 * </ul>
1133 * <p>
1134 * NOTE: This isn't a complete picture of what the user see. Further manipulation of the window
1135 * surface layering is done in {@link WindowLayersController}.
1136 */
1137 void rebuildAppWindowList() {
1138 int count = mWindows.size();
1139 int i;
1140 int lastBelow = -1;
1141 int numRemoved = 0;
1142
1143 if (mRebuildTmp.length < count) {
1144 mRebuildTmp = new WindowState[count + 10];
1145 }
1146
1147 // First remove all existing app windows.
1148 i = 0;
1149 while (i < count) {
1150 final WindowState w = mWindows.get(i);
1151 if (w.mAppToken != null) {
1152 final WindowState win = mWindows.remove(i);
1153 win.mRebuilding = true;
1154 mRebuildTmp[numRemoved] = win;
1155 mService.mWindowsChanged = true;
1156 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Rebuild removing window: " + win);
1157 count--;
1158 numRemoved++;
1159 continue;
1160 } else if (lastBelow == i-1) {
1161 if (w.mAttrs.type == TYPE_WALLPAPER) {
1162 lastBelow = i;
1163 }
1164 }
1165 i++;
1166 }
1167
1168 // Keep whatever windows were below the app windows still below, by skipping them.
1169 lastBelow++;
1170 i = lastBelow;
1171
1172 // First add all of the exiting app tokens... these are no longer in the main app list,
1173 // but still have windows shown. We put them in the back because now that the animation is
1174 // over we no longer will care about them.
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001175 final int numStacks = mTaskStackContainers.size();
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001176 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001177 AppTokenList exitingAppTokens = mTaskStackContainers.get(stackNdx).mExitingAppTokens;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001178 int NT = exitingAppTokens.size();
1179 for (int j = 0; j < NT; j++) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001180 i = exitingAppTokens.get(j).rebuildWindowListUnchecked(i);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001181 }
1182 }
1183
1184 // And add in the still active app tokens in Z order.
1185 for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001186 i = mTaskStackContainers.get(stackNdx).rebuildWindowList(i);
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001187 }
1188
1189 i -= lastBelow;
1190 if (i != numRemoved) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001191 setLayoutNeeded();
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001192 Slog.w(TAG_WM, "On display=" + mDisplayId + " Rebuild removed " + numRemoved
1193 + " windows but added " + i + " rebuildAppWindowListLocked() "
1194 + " callers=" + Debug.getCallers(10));
1195 for (i = 0; i < numRemoved; i++) {
1196 WindowState ws = mRebuildTmp[i];
1197 if (ws.mRebuilding) {
1198 StringWriter sw = new StringWriter();
1199 PrintWriter pw = new FastPrintWriter(sw, false, 1024);
1200 ws.dump(pw, "", true);
1201 pw.flush();
1202 Slog.w(TAG_WM, "This window was lost: " + ws);
1203 Slog.w(TAG_WM, sw.toString());
1204 ws.mWinAnimator.destroySurfaceLocked();
1205 }
1206 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001207 Slog.w(TAG_WM, "Current window hierarchy:");
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001208 dumpChildrenNames();
1209 Slog.w(TAG_WM, "Final window list:");
1210 dumpWindows();
1211 }
1212 Arrays.fill(mRebuildTmp, null);
1213 }
1214
Wale Ogunwaleec731152016-09-08 20:18:57 -07001215 /** Return the list of Windows on this display associated with the input token. */
1216 WindowList getTokenWindowsOnDisplay(WindowToken token) {
1217 final WindowList windowList = new WindowList();
1218 final int count = mWindows.size();
1219 for (int i = 0; i < count; i++) {
1220 final WindowState win = mWindows.get(i);
1221 if (win.mToken == token) {
1222 windowList.add(win);
1223 }
1224 }
1225 return windowList;
1226 }
1227
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001228 void setLayoutNeeded() {
1229 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
1230 mLayoutNeeded = true;
1231 }
1232
1233 void clearLayoutNeeded() {
1234 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
1235 mLayoutNeeded = false;
1236 }
1237
1238 boolean isLayoutNeeded() {
1239 return mLayoutNeeded;
1240 }
1241
Wale Ogunwaleec731152016-09-08 20:18:57 -07001242 private int addAppWindowExisting(WindowState win, WindowList tokenWindowList) {
1243
1244 int tokenWindowsPos;
1245 // If this application has existing windows, we simply place the new window on top of
1246 // them... but keep the starting window on top.
1247 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1248 // Base windows go behind everything else.
1249 final WindowState lowestWindow = tokenWindowList.get(0);
1250 addWindowToListBefore(win, lowestWindow);
1251 tokenWindowsPos = win.mToken.getWindowIndex(lowestWindow);
1252 } else {
1253 final AppWindowToken atoken = win.mAppToken;
1254 final int windowListPos = tokenWindowList.size();
1255 final WindowState lastWindow = tokenWindowList.get(windowListPos - 1);
1256 if (atoken != null && lastWindow == atoken.startingWindow) {
1257 addWindowToListBefore(win, lastWindow);
1258 tokenWindowsPos = win.mToken.getWindowIndex(lastWindow);
1259 } else {
1260 int newIdx = findIdxBasedOnAppTokens(win);
1261 // There is a window above this one associated with the same apptoken note that the
1262 // window could be a floating window that was created later or a window at the top
1263 // of the list of windows associated with this token.
1264 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1265 "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of "
1266 + mWindows.size());
1267 mWindows.add(newIdx + 1, win);
1268 if (newIdx < 0) {
1269 // No window from token found on win's display.
1270 tokenWindowsPos = 0;
1271 } else {
1272 tokenWindowsPos = win.mToken.getWindowIndex(mWindows.get(newIdx)) + 1;
1273 }
1274 mService.mWindowsChanged = true;
1275 }
1276 }
1277 return tokenWindowsPos;
1278 }
1279
1280 /** Places the first input window after the second input window in the window list. */
1281 private void addWindowToListAfter(WindowState first, WindowState second) {
1282 final int i = mWindows.indexOf(second);
1283 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1284 "Adding window " + this + " at " + (i + 1) + " of " + mWindows.size()
1285 + " (after " + second + ")");
1286 mWindows.add(i + 1, first);
1287 mService.mWindowsChanged = true;
1288 }
1289
1290 /** Places the first input window before the second input window in the window list. */
1291 private void addWindowToListBefore(WindowState first, WindowState second) {
1292 int i = mWindows.indexOf(second);
1293 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1294 "Adding window " + this + " at " + i + " of " + mWindows.size()
1295 + " (before " + second + ")");
1296 if (i < 0) {
1297 Slog.w(TAG_WM, "addWindowToListBefore: Unable to find " + second + " in " + mWindows);
1298 i = 0;
1299 }
1300 mWindows.add(i, first);
1301 mService.mWindowsChanged = true;
1302 }
1303
1304 /**
1305 * This method finds out the index of a window that has the same app token as win. used for z
1306 * ordering the windows in mWindows
1307 */
1308 private int findIdxBasedOnAppTokens(WindowState win) {
1309 for(int j = mWindows.size() - 1; j >= 0; j--) {
1310 final WindowState wentry = mWindows.get(j);
1311 if(wentry.mAppToken == win.mAppToken) {
1312 return j;
1313 }
1314 }
1315 return -1;
1316 }
1317
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001318 private void dumpChildrenNames() {
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001319 StringBuilder output = new StringBuilder();
1320 dumpChildrenNames(output, " ");
1321 Slog.v(TAG_WM, output.toString());
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001322 }
1323
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001324 private void dumpWindows() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001325 Slog.v(TAG_WM, " Display #" + mDisplayId);
1326 final WindowList windows = getWindowList();
1327 for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
1328 Slog.v(TAG_WM, " #" + winNdx + ": " + windows.get(winNdx));
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001329 }
1330 }
1331
Wale Ogunwale02319a62016-09-26 15:21:22 -07001332 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1333 if (mTokenMap.isEmpty()) {
1334 return;
1335 }
1336 pw.println(" Display #" + mDisplayId);
1337 final Iterator<WindowToken> it = mTokenMap.values().iterator();
1338 while (it.hasNext()) {
1339 final WindowToken token = it.next();
1340 pw.print(" ");
1341 pw.print(token);
1342 if (dumpAll) {
1343 pw.println(':');
1344 token.dump(pw, " ");
1345 } else {
1346 pw.println();
1347 }
1348 }
1349 }
1350
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001351 void enableSurfaceTrace(FileDescriptor fd) {
1352 for (int i = mWindows.size() - 1; i >= 0; i--) {
1353 final WindowState win = mWindows.get(i);
1354 win.mWinAnimator.enableSurfaceTrace(fd);
1355 }
1356 }
1357
1358 void disableSurfaceTrace() {
1359 for (int i = mWindows.size() - 1; i >= 0; i--) {
1360 final WindowState win = mWindows.get(i);
1361 win.mWinAnimator.disableSurfaceTrace();
1362 }
1363 }
1364
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001365 static final class GetWindowOnDisplaySearchResult {
Wale Ogunwaleec731152016-09-08 20:18:57 -07001366 boolean reachedToken;
1367 WindowState foundWindow;
1368
1369 void reset() {
1370 reachedToken = false;
1371 foundWindow = null;
1372 }
1373 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001374
1375 static final class TaskForResizePointSearchResult {
1376 boolean searchDone;
1377 Task taskForResize;
1378
1379 void reset() {
1380 searchDone = false;
1381 taskForResize = null;
1382 }
1383 }
Robert Carr3b716242016-08-16 16:02:21 -07001384
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001385 /**
1386 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
1387 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
1388 * homogeneous children type which is currently required by sub-classes of
1389 * {@link WindowContainer} class.
1390 */
1391 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
1392
1393 int size() {
1394 return mChildren.size();
1395 }
1396
1397 E get(int index) {
1398 return mChildren.get(index);
1399 }
1400
1401 @Override
1402 boolean fillsParent() {
1403 return true;
1404 }
1405
1406 @Override
1407 boolean isVisible() {
1408 return true;
Robert Carr3b716242016-08-16 16:02:21 -07001409 }
1410 }
1411
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001412 /**
1413 * Window container class that contains all containers on this display relating to Apps.
1414 * I.e Activities.
1415 */
1416 private class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
1417
1418 void attachStack(TaskStack stack, boolean onTop) {
1419 if (stack.mStackId == HOME_STACK_ID) {
1420 if (mHomeStack != null) {
1421 throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
1422 }
1423 mHomeStack = stack;
1424 }
1425 addChild(stack, onTop);
1426 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07001427 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001428
1429 void moveStack(TaskStack stack, boolean toTop) {
1430 if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
1431 // This stack is always-on-top silly...
1432 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
1433 return;
1434 }
1435
1436 if (!mChildren.contains(stack)) {
1437 Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
1438 }
1439 removeChild(stack);
1440 addChild(stack, toTop);
1441 }
1442
1443 private void addChild(TaskStack stack, boolean toTop) {
1444 int addIndex = toTop ? mChildren.size() : 0;
1445
1446 if (toTop
1447 && mService.isStackVisibleLocked(PINNED_STACK_ID)
1448 && stack.mStackId != PINNED_STACK_ID) {
1449 // The pinned stack is always the top most stack (always-on-top) when it is visible.
1450 // So, stack is moved just below the pinned stack.
1451 addIndex--;
1452 TaskStack topStack = mChildren.get(addIndex);
1453 if (topStack.mStackId != PINNED_STACK_ID) {
1454 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
1455 }
1456 }
1457 addChild(stack, addIndex);
1458 setLayoutNeeded();
1459 }
1460
1461 }
1462
1463 /**
1464 * Window container class that contains all containers on this display that are not related to
1465 * Apps. E.g. status bar.
1466 */
1467 private static class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
1468
Robert Carr3b716242016-08-16 16:02:21 -07001469 }
Craig Mautner59c00972012-07-30 12:10:24 -07001470}