blob: a28dc10df08880cac10559712f24ac6705ccbada [file] [log] [blame]
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001/*
2 * Copyright (C) 2016 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 Ogunwalee05f5012016-09-16 16:27:29 -070019import android.content.res.Configuration;
20import android.graphics.Rect;
Ruchi Kandoi0d434042016-10-03 09:12:02 -070021import android.hardware.power.V1_0.PowerHint;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070022import android.os.Binder;
23import android.os.Debug;
Wale Ogunwale02319a62016-09-26 15:21:22 -070024import android.os.IBinder;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070025import android.os.ParcelFileDescriptor;
26import android.os.PowerManager;
27import android.os.RemoteException;
28import android.os.SystemClock;
29import android.os.UserHandle;
30import android.provider.Settings;
31import android.util.EventLog;
32import android.util.Slog;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070033import android.util.SparseIntArray;
34import android.view.Display;
35import android.view.DisplayInfo;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070036import android.view.WindowManager;
37import com.android.internal.util.ArrayUtils;
38import com.android.server.EventLogTags;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070039
40import java.io.FileDescriptor;
41import java.io.PrintWriter;
42import java.util.ArrayList;
Wale Ogunwale02319a62016-09-26 15:21:22 -070043import java.util.HashMap;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070044
45import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070046import static android.app.AppOpsManager.MODE_ALLOWED;
47import static android.app.AppOpsManager.MODE_DEFAULT;
48import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwale02319a62016-09-26 15:21:22 -070049import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070050import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070051import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070052import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
53import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
54import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070055import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070056import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
57import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
58import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale02319a62016-09-26 15:21:22 -070059import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070060import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale02319a62016-09-26 15:21:22 -070061import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070062import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale02319a62016-09-26 15:21:22 -070063import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070064import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070065import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
66import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
67import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
68import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070069import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
70import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
71import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
72import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
73import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
74import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
75import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
76import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
77import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
78import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070079import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
80import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwale02319a62016-09-26 15:21:22 -070081import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070082import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
83import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
84import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
85import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
86import static com.android.server.wm.WindowManagerService.logSurface;
87import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
88import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
89import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
90import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
91import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
92import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
93
94/** Root {@link WindowContainer} for the device. */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -070095class RootWindowContainer extends WindowContainer<DisplayContent> {
Wale Ogunwalee05f5012016-09-16 16:27:29 -070096 private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM;
97
98 WindowManagerService mService;
99
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700100 private boolean mWallpaperForceHidingChanged = false;
101 private Object mLastWindowFreezeSource = null;
102 private Session mHoldScreen = null;
103 private float mScreenBrightness = -1;
104 private float mButtonBrightness = -1;
105 private long mUserActivityTimeout = -1;
106 private boolean mUpdateRotation = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700107 // Following variables are for debugging screen wakelock only.
108 // Last window that requires screen wakelock
109 WindowState mHoldScreenWindow = null;
110 // Last window that obscures all windows below
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700111 WindowState mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700112 // Only set while traversing the default display based on its content.
113 // Affects the behavior of mirroring on secondary displays.
114 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
115
116 private boolean mSustainedPerformanceModeEnabled = false;
117 private boolean mSustainedPerformanceModeCurrent = false;
118
119 boolean mWallpaperMayChange = false;
Robert Carr11c26c22016-09-23 12:40:27 -0700120 // During an orientation change, we track whether all windows have rendered
121 // at the new orientation, and this will be false from changing orientation until that occurs.
122 // For seamless rotation cases this always stays true, as the windows complete their orientation
123 // changes 1 by 1 without disturbing global state.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700124 boolean mOrientationChangeComplete = true;
125 boolean mWallpaperActionPending = false;
126
127 private final ArrayList<Integer> mChangedStackList = new ArrayList();
128
Wale Ogunwale02319a62016-09-26 15:21:22 -0700129 private final ArrayList<WindowToken> mTmpTokensList = new ArrayList();
130
131 // Collection of binder tokens mapped to their window type we are allowed to create window
132 // tokens for but that are not current attached to any display. We need to track this here
133 // because a binder token can be added through {@link WindowManagerService#addWindowToken},
134 // but we don't know what display windows for the token will be added to until
135 // {@link WindowManagerService#addWindow} is called.
136 private final HashMap<IBinder, Integer> mUnattachedBinderTokens = new HashMap();
137
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700138 // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
139 // instances will be replaced with an instance that writes a binary representation of all
140 // commands to mSurfaceTraceFd.
141 boolean mSurfaceTraceEnabled;
142 ParcelFileDescriptor mSurfaceTraceFd;
143 RemoteEventTrace mRemoteEventTrace;
144
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700145 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700146 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700147
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700148 RootWindowContainer(WindowManagerService service) {
149 mService = service;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700150 mLayersController = new WindowLayersController(mService);
Wale Ogunwale0303c572016-10-20 10:16:29 -0700151 mWallpaperController = new WallpaperController(mService);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700152 }
153
154 WindowState computeFocusedWindow() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700155 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700156 for (int i = 0; i < count; i++) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700157 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700158 final WindowState win = dc.findFocusedWindow();
159 if (win != null) {
160 return win;
161 }
162 }
163 return null;
164 }
165
166 /**
167 * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
168 * there is a Display for the displayId.
169 *
170 * @param displayId The display the caller is interested in.
171 * @return The DisplayContent associated with displayId or null if there is no Display for it.
172 */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700173 DisplayContent getDisplayContentOrCreate(int displayId) {
174 DisplayContent dc = getDisplayContent(displayId);
175
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700176 if (dc == null) {
177 final Display display = mService.mDisplayManager.getDisplay(displayId);
178 if (display != null) {
179 dc = createDisplayContent(display);
180 }
181 }
182 return dc;
183 }
184
Wale Ogunwale02319a62016-09-26 15:21:22 -0700185 DisplayContent getDisplayContent(int displayId) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700186 for (int i = mChildren.size() - 1; i >= 0; --i) {
187 final DisplayContent current = mChildren.get(i);
188 if (current.getDisplayId() == displayId) {
189 return current;
190 }
191 }
192 return null;
193 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700194
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700195 private DisplayContent createDisplayContent(final Display display) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700196 final DisplayContent dc = new DisplayContent(display, mService, mLayersController,
197 mWallpaperController);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700198 final int displayId = display.getDisplayId();
199
200 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
201 addChild(dc, null);
202
203 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700204 final Rect rect = new Rect();
205 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
206 displayInfo.overscanLeft = rect.left;
207 displayInfo.overscanTop = rect.top;
208 displayInfo.overscanRight = rect.right;
209 displayInfo.overscanBottom = rect.bottom;
210 if (mService.mDisplayManagerInternal != null) {
211 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
212 displayId, displayInfo);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700213 mService.configureDisplayPolicyLocked(dc);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700214
215 // TODO(multi-display): Create an input channel for each display with touch capability.
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700216 if (displayId == DEFAULT_DISPLAY) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700217 dc.mTapDetector = new TaskTapPointerEventListener(
218 mService, dc);
219 mService.registerPointerEventListener(dc.mTapDetector);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700220 mService.registerPointerEventListener(mService.mMousePositionTracker);
221 }
222 }
223
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700224 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700225 }
226
227 /** Adds the input stack id to the input display id and returns the bounds of the added stack.*/
228 Rect addStackToDisplay(int stackId, int displayId, boolean onTop) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700229 final DisplayContent dc = getDisplayContent(displayId);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700230 if (dc == null) {
231 Slog.w(TAG_WM, "addStackToDisplay: Trying to add stackId=" + stackId
232 + " to unknown displayId=" + displayId + " callers=" + Debug.getCallers(6));
233 return null;
234 }
235
236 boolean attachedToDisplay = false;
237 TaskStack stack = mService.mStackIdToStack.get(stackId);
238 if (stack == null) {
239 if (DEBUG_STACK) Slog.d(TAG_WM, "attachStack: stackId=" + stackId);
240
241 stack = dc.getStackById(stackId);
242 if (stack != null) {
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700243 // It's already attached to the display...clear mDeferRemoval and move stack to
244 // appropriate z-order on display as needed.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700245 stack.mDeferRemoval = false;
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700246 dc.moveStack(stack, onTop);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700247 attachedToDisplay = true;
248 } else {
249 stack = new TaskStack(mService, stackId);
250 }
251
252 mService.mStackIdToStack.put(stackId, stack);
253 if (stackId == DOCKED_STACK_ID) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700254 dc.mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700255 }
256 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700257
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700258 if (!attachedToDisplay) {
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700259 dc.attachStack(stack, onTop);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700260 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700261
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700262 if (stack.getRawFullscreen()) {
263 return null;
264 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700265 final Rect bounds = new Rect();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700266 stack.getRawBounds(bounds);
267 return bounds;
268 }
269
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700270 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700271 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700272 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700273 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700274 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700275 return true;
276 }
277 }
278 return false;
279 }
280
281 void getWindows(WindowList output) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700282 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700283 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700284 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700285 dc.getWindows(output);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700286 }
287 }
288
289 void getWindows(WindowList output, boolean visibleOnly, boolean appsOnly) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700290 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700291 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700292 final ReadOnlyWindowList windowList = mChildren.get(displayNdx).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700293 for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
294 final WindowState w = windowList.get(winNdx);
295 if ((!visibleOnly || w.mWinAnimator.getShown())
296 && (!appsOnly || w.mAppToken != null)) {
297 output.add(w);
298 }
299 }
300 }
301 }
302
303 void getWindowsByName(WindowList output, String name) {
304 int objectId = 0;
305 // See if this is an object ID.
306 try {
307 objectId = Integer.parseInt(name, 16);
308 name = null;
309 } catch (RuntimeException e) {
310 }
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700311 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700312 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700313 final ReadOnlyWindowList windowList = mChildren.get(displayNdx).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700314 for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
315 final WindowState w = windowList.get(winNdx);
316 if (name != null) {
317 if (w.mAttrs.getTitle().toString().contains(name)) {
318 output.add(w);
319 }
320 } else if (System.identityHashCode(w) == objectId) {
321 output.add(w);
322 }
323 }
324 }
325 }
326
327 WindowState findWindow(int hashCode) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700328 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700329 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700330 final ReadOnlyWindowList windows = mChildren.get(displayNdx).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700331 final int numWindows = windows.size();
332 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
333 final WindowState w = windows.get(winNdx);
334 if (System.identityHashCode(w) == hashCode) {
335 return w;
336 }
337 }
338 }
339
340 return null;
341 }
342
Wale Ogunwale02319a62016-09-26 15:21:22 -0700343 /** Return the window token associated with the input binder token on the input display */
344 WindowToken getWindowToken(IBinder binder, DisplayContent dc) {
345 final WindowToken token = dc.getWindowToken(binder);
346 if (token != null) {
347 return token;
348 }
349
350 // There is no window token mapped to the binder on the display. Create and map a window
351 // token if it is currently allowed.
352 if (!mUnattachedBinderTokens.containsKey(binder)) {
353 return null;
354 }
355
356 final int type = mUnattachedBinderTokens.get(binder);
357 return new WindowToken(mService, binder, type, true, dc);
358 }
359
360 /** Returns all window tokens mapped to the input binder. */
361 ArrayList<WindowToken> getWindowTokens(IBinder binder) {
362 mTmpTokensList.clear();
363 for (int i = mChildren.size() - 1; i >= 0; --i) {
364 final DisplayContent dc = mChildren.get(i);
365 final WindowToken token = dc.getWindowToken(binder);
366 if (token != null) {
367 mTmpTokensList.add(token);
368 }
369 }
370 return mTmpTokensList;
371 }
372
373 /**
374 * Returns the app window token for the input binder if it exist in the system.
375 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
376 * AppWindowToken represents an activity which can only exist on one display.
377 */
378 AppWindowToken getAppWindowToken(IBinder binder) {
379 for (int i = mChildren.size() - 1; i >= 0; --i) {
380 final DisplayContent dc = mChildren.get(i);
381 final AppWindowToken atoken = dc.getAppWindowToken(binder);
382 if (atoken != null) {
383 return atoken;
384 }
385 }
386 return null;
387 }
388
389 /** Returns the display object the input window token is currently mapped on. */
390 DisplayContent getWindowTokenDisplay(WindowToken token) {
391 if (token == null) {
392 return null;
393 }
394
395 for (int i = mChildren.size() - 1; i >= 0; --i) {
396 final DisplayContent dc = mChildren.get(i);
397 final WindowToken current = dc.getWindowToken(token.token);
398 if (current == token) {
399 return dc;
400 }
401 }
402
403 return null;
404 }
405
406 void addWindowToken(IBinder binder, int type) {
407 if (mUnattachedBinderTokens.containsKey(binder)) {
408 Slog.w(TAG_WM, "addWindowToken: Attempted to add existing binder token: " + binder);
409 return;
410 }
411
412 final ArrayList<WindowToken> tokens = getWindowTokens(binder);
413
414 if (!tokens.isEmpty()) {
415 Slog.w(TAG_WM, "addWindowToken: Attempted to add binder token: " + binder
416 + " for already created window tokens: " + tokens);
417 return;
418 }
419
420 mUnattachedBinderTokens.put(binder, type);
421
422 // TODO(multi-display): By default we add this to the default display, but maybe we
423 // should provide an API for a token to be added to any display?
Wale Ogunwale0303c572016-10-20 10:16:29 -0700424 final DisplayContent dc = getDisplayContent(DEFAULT_DISPLAY);
425 final WindowToken token = new WindowToken(mService, binder, type, true, dc);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700426 if (type == TYPE_WALLPAPER) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700427 dc.mWallpaperController.addWallpaperToken(token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700428 }
429 }
430
431 ArrayList<WindowToken> removeWindowToken(IBinder binder) {
432 mUnattachedBinderTokens.remove(binder);
433
434 mTmpTokensList.clear();
435 for (int i = mChildren.size() - 1; i >= 0; --i) {
436 final DisplayContent dc = mChildren.get(i);
437 final WindowToken token = dc.removeWindowToken(binder);
438 if (token != null) {
439 mTmpTokensList.add(token);
440 }
441 }
442 return mTmpTokensList;
443 }
444
445 /**
446 * Removed the mapping to the input binder for the system if it no longer as a window token
447 * associated with it on any display.
448 */
449 void removeWindowTokenIfPossible(IBinder binder) {
450 for (int i = mChildren.size() - 1; i >= 0; --i) {
451 final DisplayContent dc = mChildren.get(i);
452 final WindowToken token = dc.getWindowToken(binder);
453 if (token != null) {
454 return;
455 }
456 }
457
458 mUnattachedBinderTokens.remove(binder);
459 }
460
461 void removeAppToken(IBinder binder) {
462 final ArrayList<WindowToken> removedTokens = removeWindowToken(binder);
463 if (removedTokens == null || removedTokens.isEmpty()) {
464 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
465 return;
466 }
467
468 for (int i = removedTokens.size() - 1; i >= 0; --i) {
469 WindowToken wtoken = removedTokens.get(i);
470 AppWindowToken appToken = wtoken.asAppWindowToken();
471
472 if (appToken == null) {
473 Slog.w(TAG_WM,
474 "Attempted to remove non-App token: " + binder + " wtoken=" + wtoken);
475 continue;
476 }
477
478 AppWindowToken startingToken = null;
479
480 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + appToken);
481
482 boolean delayed = appToken.setVisibility(null, false, TRANSIT_UNSET, true,
483 appToken.voiceInteraction);
484
485 mService.mOpeningApps.remove(appToken);
486 appToken.waitingToShow = false;
487 if (mService.mClosingApps.contains(appToken)) {
488 delayed = true;
489 } else if (mService.mAppTransition.isTransitionSet()) {
490 mService.mClosingApps.add(appToken);
491 delayed = true;
492 }
493
494 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + appToken
495 + " delayed=" + delayed
496 + " animation=" + appToken.mAppAnimator.animation
497 + " animating=" + appToken.mAppAnimator.animating);
498
499 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
500 + appToken + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
501
502 final TaskStack stack = appToken.mTask.mStack;
503 if (delayed && !appToken.isEmpty()) {
504 // set the token aside because it has an active animation to be finished
505 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
506 "removeAppToken make exiting: " + appToken);
507 stack.mExitingAppTokens.add(appToken);
508 appToken.mIsExiting = true;
509 } else {
510 // Make sure there is no animation running on this token, so any windows associated
511 // with it will be removed as soon as their animations are complete
512 appToken.mAppAnimator.clearAnimation();
513 appToken.mAppAnimator.animating = false;
514 appToken.removeIfPossible();
515 }
516
517 appToken.removed = true;
518 if (appToken.startingData != null) {
519 startingToken = appToken;
520 }
521 appToken.stopFreezingScreen(true, true);
522 if (mService.mFocusedApp == appToken) {
523 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + appToken);
524 mService.mFocusedApp = null;
525 mService.updateFocusedWindowLocked(
526 UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
527 mService.mInputMonitor.setFocusedAppLw(null);
528 }
529
530 if (!delayed) {
531 appToken.updateReportedVisibilityLocked();
532 }
533
534 // Will only remove if startingToken non null.
535 mService.scheduleRemoveStartingWindowLocked(startingToken);
536 }
537 }
538
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700539 // TODO: Users would have their own window containers under the display container?
540 void switchUser() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700541 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700542 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700543 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700544 dc.switchUser();
545 }
546 }
547
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700548 /**
549 * Set new display override config and return array of ids of stacks that were changed during
550 * update. If called for the default display, global configuration will also be updated.
551 */
552 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
553 final DisplayContent displayContent = getDisplayContent(displayId);
554 if (displayContent == null) {
555 throw new IllegalArgumentException("Display not found for id: " + displayId);
556 }
557
558 final Configuration currentConfig = displayContent.getOverrideConfiguration();
559 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
560 if (!configChanged) {
561 return null;
562 }
563 displayContent.onOverrideConfigurationChanged(currentConfig);
564
565 if (displayId == DEFAULT_DISPLAY) {
566 // Override configuration of the default display duplicates global config. In this case
567 // we also want to update the global config.
568 return setGlobalConfigurationIfNeeded(newConfiguration);
569 } else {
570 return updateStackBoundsAfterConfigChange(displayId);
571 }
572 }
573
574 private int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700575 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
576 if (!configChanged) {
577 return null;
578 }
579 onConfigurationChanged(newConfiguration);
580 return updateStackBoundsAfterConfigChange();
581 }
582
583 @Override
584 void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700585 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700586 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700587
588 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700589 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700590
Andrii Kulian441e4492016-09-29 15:25:00 -0700591 /**
592 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
593 * bounds were updated.
594 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700595 private int[] updateStackBoundsAfterConfigChange() {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700596 mChangedStackList.clear();
597
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700598 final int numDisplays = mChildren.size();
599 for (int i = 0; i < numDisplays; ++i) {
600 final DisplayContent dc = mChildren.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700601 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700602 }
603
604 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
605 }
606
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700607 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
608 private int[] updateStackBoundsAfterConfigChange(int displayId) {
609 mChangedStackList.clear();
610
611 final DisplayContent dc = getDisplayContent(displayId);
612 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
613
614 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
615 }
616
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700617 private void prepareFreezingTaskBounds() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700618 for (int i = mChildren.size() - 1; i >= 0; i--) {
619 mChildren.get(i).prepareFreezingTaskBounds();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700620 }
621 }
622
623 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700624 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700625 final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700626 for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
627 final WindowState win = windows.get(winNdx);
628 if (win.mHasSurface && userId == UserHandle.getUserId(win.mOwnerUid)) {
629 win.mWinAnimator.setSecureLocked(disabled);
630 }
631 }
632 }
633 }
634
635 void updateAppOpsState() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700636 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700637 for (int i = 0; i < count; ++i) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700638 final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700639 final int numWindows = windows.size();
640 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
641 final WindowState win = windows.get(winNdx);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700642 if (win.mAppOp == OP_NONE) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700643 continue;
644 }
645 final int mode = mService.mAppOps.checkOpNoThrow(win.mAppOp, win.getOwningUid(),
646 win.getOwningPackage());
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700647 win.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700648 }
649 }
650 }
651
652 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700653 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700654 for (int i = 0; i < count; ++i) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700655 final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700656 final int numWindows = windows.size();
657 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
658 final WindowState ws = windows.get(winNdx);
659 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
660 return true;
661 }
662 }
663 }
664 return false;
665 }
666
667 void closeSystemDialogs(String reason) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700668 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700669 for (int i = 0; i < count; ++i) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700670 final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700671 final int numWindows = windows.size();
672 for (int j = 0; j < numWindows; ++j) {
673 final WindowState w = windows.get(j);
674 if (w.mHasSurface) {
675 try {
676 w.mClient.closeSystemDialogs(reason);
677 } catch (RemoteException e) {
678 }
679 }
680 }
681 }
682 }
683
684 void removeReplacedWindows() {
685 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
686 mService.openSurfaceTransaction();
687 try {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700688 for (int i = mChildren.size() - 1; i >= 0; i--) {
689 DisplayContent dc = mChildren.get(i);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700690 final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700691 for (int j = windows.size() - 1; j >= 0; j--) {
692 final WindowState win = windows.get(j);
693 final AppWindowToken aToken = win.mAppToken;
694 if (aToken != null) {
695 aToken.removeReplacedWindowIfNeeded(win);
696 }
697 }
698 }
699 } finally {
700 mService.closeSurfaceTransaction();
701 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
702 }
703 }
704
705 boolean hasPendingLayoutChanges(WindowAnimator animator) {
706 boolean hasChanges = false;
707
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700708 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700709 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700710 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700711 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
712 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
713 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
714 }
715 if (pendingChanges != 0) {
716 hasChanges = true;
717 }
718 }
719
720 return hasChanges;
721 }
722
723 void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700724 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700725 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700726 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700727 dc.updateInputWindows(inputMonitor, inputFocus, inDrag);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700728 }
729 }
730
731 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
732 boolean secure) {
733 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
734 boolean leakedSurface = false;
735 boolean killedApps = false;
736
737 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
738 winAnimator.mSession.mPid, operation);
739
740 final long callingIdentity = Binder.clearCallingIdentity();
741 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700742 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700743 // we haven't left any dangling surfaces around.
744
745 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700746 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700747 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700748 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700749 }
750
751 if (!leakedSurface) {
752 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700753 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700754 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700755 final ReadOnlyWindowList windows =
756 mChildren.get(displayNdx).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700757 final int numWindows = windows.size();
758 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
759 final WindowState ws = windows.get(winNdx);
760 if (mService.mForceRemoves.contains(ws)) {
761 continue;
762 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700763 final WindowStateAnimator wsa = ws.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700764 if (wsa.mSurfaceController != null) {
765 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
766 }
767 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700768
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700769 if (pidCandidates.size() > 0) {
770 int[] pids = new int[pidCandidates.size()];
771 for (int i = 0; i < pids.length; i++) {
772 pids[i] = pidCandidates.keyAt(i);
773 }
774 try {
775 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
776 killedApps = true;
777 }
778 } catch (RemoteException e) {
779 }
780 }
781 }
782 }
783
784 if (leakedSurface || killedApps) {
785 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
786 // app to request another one.
787 Slog.w(TAG_WM,
788 "Looks like we have reclaimed some memory, clearing surface for retry.");
789 if (surfaceController != null) {
790 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
791 "RECOVER DESTROY", false);
792 winAnimator.destroySurface();
793 mService.scheduleRemoveStartingWindowLocked(winAnimator.mWin.mAppToken);
794 }
795
796 try {
797 winAnimator.mWin.mClient.dispatchGetNewSurface();
798 } catch (RemoteException e) {
799 }
800 }
801 } finally {
802 Binder.restoreCallingIdentity(callingIdentity);
803 }
804
805 return leakedSurface || killedApps;
806 }
807
808 // "Something has changed! Let's make it correct now."
809 // TODO: Super crazy long method that should be broken down...
810 void performSurfacePlacement(boolean recoveringMemory) {
811 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
812 + Debug.getCallers(3));
813
814 int i;
815 boolean updateInputWindowsNeeded = false;
816
817 if (mService.mFocusMayChange) {
818 mService.mFocusMayChange = false;
819 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
820 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
821 }
822
823 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700824 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700825 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700826 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700827 for (i = displayContent.mExitingTokens.size() - 1; i >= 0; i--) {
828 displayContent.mExitingTokens.get(i).hasVisible = false;
829 }
830 }
831
832 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
833 // Initialize state of exiting applications.
834 final AppTokenList exitingAppTokens =
835 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
836 for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
837 exitingAppTokens.get(tokenNdx).hasVisible = false;
838 }
839 }
840
841 mHoldScreen = null;
842 mScreenBrightness = -1;
843 mButtonBrightness = -1;
844 mUserActivityTimeout = -1;
845 mObscureApplicationContentOnSecondaryDisplays = false;
846 mSustainedPerformanceModeCurrent = false;
847 mService.mTransactionSequence++;
848
849 // TODO(multi-display):
850 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
851 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
852 final int defaultDw = defaultInfo.logicalWidth;
853 final int defaultDh = defaultInfo.logicalHeight;
854
855 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
856 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
857 mService.openSurfaceTransaction();
858 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700859 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700860 } catch (RuntimeException e) {
861 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
862 } finally {
863 mService.closeSurfaceTransaction();
864 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
865 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
866 }
867
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700868 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
869
870 // If we are ready to perform an app transition, check through all of the app tokens to be
871 // shown and see if they are ready to go.
872 if (mService.mAppTransition.isReady()) {
873 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700874 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700875 if (DEBUG_LAYOUT_REPEATS)
876 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
877 defaultDisplay.pendingLayoutChanges);
878 }
879
880 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
881 // We have finished the animation of an app transition. To do this, we have delayed a
882 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
883 // token list reflects the correct Z-order, but the window list may now be out of sync
884 // with it. So here we will just rebuild the entire app window list. Fun!
885 defaultDisplay.pendingLayoutChanges |=
886 mService.handleAnimatingStoppedAndTransitionLocked();
887 if (DEBUG_LAYOUT_REPEATS)
888 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
889 defaultDisplay.pendingLayoutChanges);
890 }
891
892 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
893 && !mService.mAppTransition.isReady()) {
894 // At this point, there was a window with a wallpaper that was force hiding other
895 // windows behind it, but now it is going away. This may be simple -- just animate away
896 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
897 // shown behind something that was hidden.
898 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
899 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
900 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
901 }
902 mWallpaperForceHidingChanged = false;
903
904 if (mWallpaperMayChange) {
905 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
906 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
907 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
908 defaultDisplay.pendingLayoutChanges);
909 }
910
911 if (mService.mFocusMayChange) {
912 mService.mFocusMayChange = false;
913 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
914 false /*updateInputWindows*/)) {
915 updateInputWindowsNeeded = true;
916 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
917 }
918 }
919
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700920 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700921 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
922 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
923 defaultDisplay.pendingLayoutChanges);
924 }
925
926 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
927 WindowState win = mService.mResizingWindows.get(i);
928 if (win.mAppFreezing) {
929 // Don't remove this window until rotation has completed.
930 continue;
931 }
932 // Discard the saved surface if window size is changed, it can't be reused.
933 if (win.mAppToken != null) {
934 win.mAppToken.destroySavedSurfaces();
935 }
936 win.reportResized();
937 mService.mResizingWindows.remove(i);
938 }
939
940 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
941 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
942 if (mOrientationChangeComplete) {
943 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
944 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
945 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
946 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
947 }
948 mService.stopFreezingDisplayLocked();
949 }
950
951 // Destroy the surface of any windows that are no longer visible.
952 boolean wallpaperDestroyed = false;
953 i = mService.mDestroySurface.size();
954 if (i > 0) {
955 do {
956 i--;
957 WindowState win = mService.mDestroySurface.get(i);
958 win.mDestroying = false;
959 if (mService.mInputMethodWindow == win) {
960 mService.mInputMethodWindow = null;
961 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700962 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700963 wallpaperDestroyed = true;
964 }
965 win.destroyOrSaveSurface();
966 } while (i > 0);
967 mService.mDestroySurface.clear();
968 }
969
970 // Time to remove any exiting tokens?
971 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700972 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700973 ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens;
974 for (i = exitingTokens.size() - 1; i >= 0; i--) {
975 WindowToken token = exitingTokens.get(i);
976 if (!token.hasVisible) {
977 exitingTokens.remove(i);
978 if (token.windowType == TYPE_WALLPAPER) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700979 displayContent.mWallpaperController.removeWallpaperToken(token);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700980 }
981 }
982 }
983 }
984
985 // Time to remove any exiting applications?
986 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
987 // Initialize state of exiting applications.
988 final AppTokenList exitingAppTokens =
989 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
990 for (i = exitingAppTokens.size() - 1; i >= 0; i--) {
991 final AppWindowToken token = exitingAppTokens.get(i);
992 if (!token.hasVisible && !mService.mClosingApps.contains(token) &&
993 (!token.mIsExiting || token.isEmpty())) {
994 // Make sure there is no animation running on this token, so any windows
995 // associated with it will be removed as soon as their animations are complete
996 token.mAppAnimator.clearAnimation();
997 token.mAppAnimator.animating = false;
998 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
999 "performLayout: App token exiting now removed" + token);
1000 token.removeIfPossible();
1001 }
1002 }
1003 }
1004
1005 if (wallpaperDestroyed) {
1006 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001007 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001008 }
1009
1010 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001011 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001012 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001013 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001014 }
1015 }
1016
1017 // Finally update all input windows now that the window changes have stabilized.
1018 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1019
1020 mService.setHoldScreenLocked(mHoldScreen);
1021 if (!mService.mDisplayFrozen) {
1022 if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) {
1023 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
1024 } else {
1025 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
1026 toBrightnessOverride(mScreenBrightness));
1027 }
1028 if (mButtonBrightness < 0 || mButtonBrightness > 1.0f) {
1029 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
1030 } else {
1031 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
1032 toBrightnessOverride(mButtonBrightness));
1033 }
1034 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
1035 mUserActivityTimeout);
1036 }
1037
1038 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
1039 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
1040 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -07001041 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001042 (mSustainedPerformanceModeEnabled ? 1 : 0));
1043 }
1044
1045 if (mService.mTurnOnScreen) {
1046 if (mService.mAllowTheaterModeWakeFromLayout
1047 || Settings.Global.getInt(mService.mContext.getContentResolver(),
1048 Settings.Global.THEATER_MODE_ON, 0) == 0) {
1049 if (DEBUG_VISIBILITY || DEBUG_POWER) {
1050 Slog.v(TAG, "Turning screen on after layout!");
1051 }
1052 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
1053 "android.server.wm:TURN_ON");
1054 }
1055 mService.mTurnOnScreen = false;
1056 }
1057
1058 if (mUpdateRotation) {
1059 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001060 // TODO(multi-display): Update rotation for different displays separately.
1061 final int displayId = defaultDisplay.getDisplayId();
1062 if (mService.updateRotationUncheckedLocked(false, displayId)) {
1063 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001064 } else {
1065 mUpdateRotation = false;
1066 }
1067 }
1068
1069 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001070 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
1071 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001072 mService.checkDrawnWindowsLocked();
1073 }
1074
1075 final int N = mService.mPendingRemove.size();
1076 if (N > 0) {
1077 if (mService.mPendingRemoveTmp.length < N) {
1078 mService.mPendingRemoveTmp = new WindowState[N+10];
1079 }
1080 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
1081 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001082 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001083 for (i = 0; i < N; i++) {
1084 final WindowState w = mService.mPendingRemoveTmp[i];
1085 w.removeImmediately();
1086 final DisplayContent displayContent = w.getDisplayContent();
1087 if (displayContent != null && !displayList.contains(displayContent)) {
1088 displayList.add(displayContent);
1089 }
1090 }
1091
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001092 for (int j = displayList.size() - 1; j >= 0; --j) {
1093 final DisplayContent dc = displayList.get(j);
1094 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001095 }
1096 }
1097
1098 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001099 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
1100 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001101 }
1102
1103 if (updateInputWindowsNeeded) {
1104 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1105 }
1106 mService.setFocusTaskRegionLocked();
1107
1108 // Check to see if we are now in a state where the screen should
1109 // be enabled, because the window obscured flags have changed.
1110 mService.enableScreenIfNeededLocked();
1111
1112 mService.scheduleAnimationLocked();
1113 mService.mWindowPlacerLocked.destroyPendingSurfaces();
1114
1115 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
1116 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
1117 }
1118
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001119 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
1120 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001121 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -07001122 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001123
1124 if (mService.mWatermark != null) {
1125 mService.mWatermark.positionSurface(defaultDw, defaultDh);
1126 }
1127 if (mService.mStrictModeFlash != null) {
1128 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
1129 }
1130 if (mService.mCircularDisplayMask != null) {
1131 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh, mService.mRotation);
1132 }
1133 if (mService.mEmulatorDisplayOverlay != null) {
1134 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
1135 mService.mRotation);
1136 }
1137
1138 boolean focusDisplayed = false;
1139
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001140 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001141 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001142 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001143 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001144 }
1145
1146 if (focusDisplayed) {
1147 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
1148 }
1149
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001150 // Give the display manager a chance to adjust properties like display rotation if it needs
1151 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001152 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
1153 }
1154
1155 /**
1156 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001157 * @param obscured True if there is a window on top of this obscuring the display.
1158 * @param syswin System window?
1159 * @return True when the display contains content to show the user. When false, the display
1160 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001161 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001162 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001163 final WindowManager.LayoutParams attrs = w.mAttrs;
1164 final int attrFlags = attrs.flags;
1165 final boolean canBeSeen = w.isDisplayedLw();
1166 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001167 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001168
1169 if (w.mHasSurface && canBeSeen) {
1170 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
1171 mHoldScreen = w.mSession;
1172 mHoldScreenWindow = w;
1173 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
1174 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
1175 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
1176 + Debug.getCallers(10));
1177 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001178 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001179 mScreenBrightness = w.mAttrs.screenBrightness;
1180 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001181 if (!syswin && w.mAttrs.buttonBrightness >= 0 && mButtonBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001182 mButtonBrightness = w.mAttrs.buttonBrightness;
1183 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001184 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001185 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
1186 }
1187
1188 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001189 // This function assumes that the contents of the default display are processed first
1190 // before secondary displays.
1191 final DisplayContent displayContent = w.getDisplayContent();
1192 if (displayContent != null && displayContent.isDefaultDisplay) {
1193 // While a dream or keyguard is showing, obscure ordinary application content on
1194 // secondary displays (by forcibly enabling mirroring unless there is other content
1195 // we want to show) but still allow opaque keyguard dialogs to be shown.
1196 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
1197 mObscureApplicationContentOnSecondaryDisplays = true;
1198 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001199 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001200 } else if (displayContent != null &&
1201 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001202 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001203 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001204 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001205 }
1206 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
1207 mSustainedPerformanceModeCurrent = true;
1208 }
1209 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001210
1211 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001212 }
1213
1214 boolean copyAnimToLayoutParams() {
1215 boolean doRequest = false;
1216
1217 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
1218 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
1219 mUpdateRotation = true;
1220 doRequest = true;
1221 }
1222 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
1223 mWallpaperMayChange = true;
1224 doRequest = true;
1225 }
1226 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
1227 mWallpaperForceHidingChanged = true;
1228 doRequest = true;
1229 }
1230 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
1231 mOrientationChangeComplete = false;
1232 } else {
1233 mOrientationChangeComplete = true;
1234 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
1235 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
1236 doRequest = true;
1237 }
1238 }
1239 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
1240 mService.mTurnOnScreen = true;
1241 }
1242 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
1243 mWallpaperActionPending = true;
1244 }
1245
1246 return doRequest;
1247 }
1248
1249 private static int toBrightnessOverride(float value) {
1250 return (int)(value * PowerManager.BRIGHTNESS_ON);
1251 }
1252
1253 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
1254 final FileDescriptor fd = pfd.getFileDescriptor();
1255 if (mSurfaceTraceEnabled) {
1256 disableSurfaceTrace();
1257 }
1258 mSurfaceTraceEnabled = true;
1259 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
1260 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001261 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
1262 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001263 dc.enableSurfaceTrace(fd);
1264 }
1265 }
1266
1267 void disableSurfaceTrace() {
1268 mSurfaceTraceEnabled = false;
1269 mRemoteEventTrace = null;
1270 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001271 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
1272 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001273 dc.disableSurfaceTrace();
1274 }
1275 }
1276
1277 void dumpDisplayContents(PrintWriter pw) {
1278 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
1279 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001280 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001281 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001282 final DisplayContent displayContent = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001283 displayContent.dump(" ", pw);
1284 }
1285 } else {
1286 pw.println(" NO DISPLAY");
1287 }
1288 }
1289
1290 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001291 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001292 return;
1293 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001294 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001295 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001296 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001297 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001298 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001299 pw.print(displayContent.getDisplayId());
1300 }
1301 }
1302 pw.println();
1303 }
1304
1305 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001306 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001307 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001308 final ReadOnlyWindowList windowList = mChildren.get(displayNdx).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001309 for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
1310 final WindowState w = windowList.get(winNdx);
1311 if (windows == null || windows.contains(w)) {
1312 pw.println(" Window #" + winNdx + " " + w + ":");
1313 w.dump(pw, " ", dumpAll || windows != null);
1314 }
1315 }
1316 }
1317 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001318
Wale Ogunwale02319a62016-09-26 15:21:22 -07001319 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1320 pw.println(" All tokens:");
1321 for (int i = mChildren.size() - 1; i >= 0; --i) {
1322 mChildren.get(i).dumpTokens(pw, dumpAll);
1323 }
1324 }
1325
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001326 @Override
1327 String getName() {
1328 return "ROOT";
1329 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001330}