blob: 88986e33894ae4805f25709eaa96919376f68de9 [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;
43
Wale Ogunwalef7cab102016-10-25 15:25:14 -070044import static android.app.AppOpsManager.MODE_ALLOWED;
45import static android.app.AppOpsManager.MODE_DEFAULT;
46import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwale02319a62016-09-26 15:21:22 -070047import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070048import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070049import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070050import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
51import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
52import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070053import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070054import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
55import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi879ff722016-11-04 18:08:17 -070056
Wale Ogunwalee05f5012016-09-16 16:27:29 -070057import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
58import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
59import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070060import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
61import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
62import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070063import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
64import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
65import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
66import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
67import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
68import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
69import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
70import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
71import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
72import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070073import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
74import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070075import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
76import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
77import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
78import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
79import static com.android.server.wm.WindowManagerService.logSurface;
80import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
81import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
82import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
83import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
84import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
85import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
86
87/** Root {@link WindowContainer} for the device. */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -070088class RootWindowContainer extends WindowContainer<DisplayContent> {
Wale Ogunwalee05f5012016-09-16 16:27:29 -070089 private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM;
90
91 WindowManagerService mService;
92
Wale Ogunwalee05f5012016-09-16 16:27:29 -070093 private boolean mWallpaperForceHidingChanged = false;
94 private Object mLastWindowFreezeSource = null;
95 private Session mHoldScreen = null;
96 private float mScreenBrightness = -1;
97 private float mButtonBrightness = -1;
98 private long mUserActivityTimeout = -1;
99 private boolean mUpdateRotation = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700100 // Following variables are for debugging screen wakelock only.
101 // Last window that requires screen wakelock
102 WindowState mHoldScreenWindow = null;
103 // Last window that obscures all windows below
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700104 WindowState mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700105 // Only set while traversing the default display based on its content.
106 // Affects the behavior of mirroring on secondary displays.
107 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
108
109 private boolean mSustainedPerformanceModeEnabled = false;
110 private boolean mSustainedPerformanceModeCurrent = false;
111
112 boolean mWallpaperMayChange = false;
Robert Carr11c26c22016-09-23 12:40:27 -0700113 // During an orientation change, we track whether all windows have rendered
114 // at the new orientation, and this will be false from changing orientation until that occurs.
115 // For seamless rotation cases this always stays true, as the windows complete their orientation
116 // changes 1 by 1 without disturbing global state.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700117 boolean mOrientationChangeComplete = true;
118 boolean mWallpaperActionPending = false;
119
120 private final ArrayList<Integer> mChangedStackList = new ArrayList();
121
122 // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
123 // instances will be replaced with an instance that writes a binary representation of all
124 // commands to mSurfaceTraceFd.
125 boolean mSurfaceTraceEnabled;
126 ParcelFileDescriptor mSurfaceTraceFd;
127 RemoteEventTrace mRemoteEventTrace;
128
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700129 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700130 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700131
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700132 RootWindowContainer(WindowManagerService service) {
133 mService = service;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700134 mLayersController = new WindowLayersController(mService);
Wale Ogunwale0303c572016-10-20 10:16:29 -0700135 mWallpaperController = new WallpaperController(mService);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700136 }
137
138 WindowState computeFocusedWindow() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700139 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700140 for (int i = 0; i < count; i++) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700141 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700142 final WindowState win = dc.findFocusedWindow();
143 if (win != null) {
144 return win;
145 }
146 }
147 return null;
148 }
149
150 /**
151 * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
152 * there is a Display for the displayId.
153 *
154 * @param displayId The display the caller is interested in.
155 * @return The DisplayContent associated with displayId or null if there is no Display for it.
156 */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700157 DisplayContent getDisplayContentOrCreate(int displayId) {
158 DisplayContent dc = getDisplayContent(displayId);
159
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700160 if (dc == null) {
161 final Display display = mService.mDisplayManager.getDisplay(displayId);
162 if (display != null) {
163 dc = createDisplayContent(display);
164 }
165 }
166 return dc;
167 }
168
Wale Ogunwale02319a62016-09-26 15:21:22 -0700169 DisplayContent getDisplayContent(int displayId) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700170 for (int i = mChildren.size() - 1; i >= 0; --i) {
171 final DisplayContent current = mChildren.get(i);
172 if (current.getDisplayId() == displayId) {
173 return current;
174 }
175 }
176 return null;
177 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700178
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700179 private DisplayContent createDisplayContent(final Display display) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700180 final DisplayContent dc = new DisplayContent(display, mService, mLayersController,
181 mWallpaperController);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700182 final int displayId = display.getDisplayId();
183
184 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
185 addChild(dc, null);
186
187 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700188 final Rect rect = new Rect();
189 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
190 displayInfo.overscanLeft = rect.left;
191 displayInfo.overscanTop = rect.top;
192 displayInfo.overscanRight = rect.right;
193 displayInfo.overscanBottom = rect.bottom;
194 if (mService.mDisplayManagerInternal != null) {
195 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
196 displayId, displayInfo);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700197 mService.configureDisplayPolicyLocked(dc);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700198
199 // TODO(multi-display): Create an input channel for each display with touch capability.
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700200 if (displayId == DEFAULT_DISPLAY) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700201 dc.mTapDetector = new TaskTapPointerEventListener(
202 mService, dc);
203 mService.registerPointerEventListener(dc.mTapDetector);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700204 mService.registerPointerEventListener(mService.mMousePositionTracker);
205 }
206 }
207
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700208 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700209 }
210
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700211 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700212 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700213 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700214 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700215 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700216 return true;
217 }
218 }
219 return false;
220 }
221
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700222 void getWindowsByName(WindowList output, String name) {
223 int objectId = 0;
224 // See if this is an object ID.
225 try {
226 objectId = Integer.parseInt(name, 16);
227 name = null;
228 } catch (RuntimeException e) {
229 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800230
231 getWindowsByName(output, name, objectId);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700232 }
233
Wale Ogunwaled1880962016-11-08 10:31:59 -0800234 private void getWindowsByName(WindowList output, String name, int objectId) {
235 forAllWindows((w) -> {
236 if (name != null) {
237 if (w.mAttrs.getTitle().toString().contains(name)) {
238 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700239 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800240 } else if (System.identityHashCode(w) == objectId) {
241 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700242 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800243 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700244 }
245
Wale Ogunwale02319a62016-09-26 15:21:22 -0700246 /**
247 * Returns the app window token for the input binder if it exist in the system.
248 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
249 * AppWindowToken represents an activity which can only exist on one display.
250 */
251 AppWindowToken getAppWindowToken(IBinder binder) {
252 for (int i = mChildren.size() - 1; i >= 0; --i) {
253 final DisplayContent dc = mChildren.get(i);
254 final AppWindowToken atoken = dc.getAppWindowToken(binder);
255 if (atoken != null) {
256 return atoken;
257 }
258 }
259 return null;
260 }
261
262 /** Returns the display object the input window token is currently mapped on. */
263 DisplayContent getWindowTokenDisplay(WindowToken token) {
264 if (token == null) {
265 return null;
266 }
267
268 for (int i = mChildren.size() - 1; i >= 0; --i) {
269 final DisplayContent dc = mChildren.get(i);
270 final WindowToken current = dc.getWindowToken(token.token);
271 if (current == token) {
272 return dc;
273 }
274 }
275
276 return null;
277 }
278
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700279 // TODO: Users would have their own window containers under the display container?
280 void switchUser() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700281 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700282 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700283 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700284 dc.switchUser();
285 }
286 }
287
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700288 /**
289 * Set new display override config and return array of ids of stacks that were changed during
290 * update. If called for the default display, global configuration will also be updated.
291 */
292 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
293 final DisplayContent displayContent = getDisplayContent(displayId);
294 if (displayContent == null) {
295 throw new IllegalArgumentException("Display not found for id: " + displayId);
296 }
297
298 final Configuration currentConfig = displayContent.getOverrideConfiguration();
299 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
300 if (!configChanged) {
301 return null;
302 }
303 displayContent.onOverrideConfigurationChanged(currentConfig);
304
305 if (displayId == DEFAULT_DISPLAY) {
306 // Override configuration of the default display duplicates global config. In this case
307 // we also want to update the global config.
308 return setGlobalConfigurationIfNeeded(newConfiguration);
309 } else {
310 return updateStackBoundsAfterConfigChange(displayId);
311 }
312 }
313
314 private int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700315 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
316 if (!configChanged) {
317 return null;
318 }
319 onConfigurationChanged(newConfiguration);
320 return updateStackBoundsAfterConfigChange();
321 }
322
323 @Override
324 void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700325 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700326 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700327
328 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700329 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700330
Andrii Kulian441e4492016-09-29 15:25:00 -0700331 /**
332 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
333 * bounds were updated.
334 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700335 private int[] updateStackBoundsAfterConfigChange() {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700336 mChangedStackList.clear();
337
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700338 final int numDisplays = mChildren.size();
339 for (int i = 0; i < numDisplays; ++i) {
340 final DisplayContent dc = mChildren.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700341 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700342 }
343
344 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
345 }
346
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700347 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
348 private int[] updateStackBoundsAfterConfigChange(int displayId) {
349 mChangedStackList.clear();
350
351 final DisplayContent dc = getDisplayContent(displayId);
352 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
353
354 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
355 }
356
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700357 private void prepareFreezingTaskBounds() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700358 for (int i = mChildren.size() - 1; i >= 0; i--) {
359 mChildren.get(i).prepareFreezingTaskBounds();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700360 }
361 }
362
363 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800364 forAllWindows((w) -> {
365 if (w.mHasSurface && userId == UserHandle.getUserId(w.mOwnerUid)) {
366 w.mWinAnimator.setSecureLocked(disabled);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700367 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800368 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700369 }
370
371 void updateAppOpsState() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800372 forAllWindows((w) -> {
373 if (w.mAppOp == OP_NONE) {
374 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700375 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800376 final int mode = mService.mAppOps.checkOpNoThrow(w.mAppOp, w.getOwningUid(),
377 w.getOwningPackage());
378 w.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
379 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700380 }
381
382 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800383 final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw());
384 return win != null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700385 }
386
387 void closeSystemDialogs(String reason) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800388 forAllWindows((w) -> {
389 if (w.mHasSurface) {
390 try {
391 w.mClient.closeSystemDialogs(reason);
392 } catch (RemoteException e) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700393 }
394 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800395 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700396 }
397
398 void removeReplacedWindows() {
399 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
400 mService.openSurfaceTransaction();
401 try {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800402 forAllWindows((w) -> {
403 final AppWindowToken aToken = w.mAppToken;
404 if (aToken != null) {
405 aToken.removeReplacedWindowIfNeeded(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700406 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800407 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700408 } finally {
409 mService.closeSurfaceTransaction();
410 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
411 }
412 }
413
414 boolean hasPendingLayoutChanges(WindowAnimator animator) {
415 boolean hasChanges = false;
416
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700417 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700418 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700419 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700420 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
421 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
422 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
423 }
424 if (pendingChanges != 0) {
425 hasChanges = true;
426 }
427 }
428
429 return hasChanges;
430 }
431
432 void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700433 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700434 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700435 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700436 dc.updateInputWindows(inputMonitor, inputFocus, inDrag);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700437 }
438 }
439
440 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
441 boolean secure) {
442 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
443 boolean leakedSurface = false;
444 boolean killedApps = false;
445
446 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
447 winAnimator.mSession.mPid, operation);
448
449 final long callingIdentity = Binder.clearCallingIdentity();
450 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700451 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700452 // we haven't left any dangling surfaces around.
453
454 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700455 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700456 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700457 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700458 }
459
460 if (!leakedSurface) {
461 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700462 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700463 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800464 mChildren.get(displayNdx).forAllWindows((w) -> {
465 if (mService.mForceRemoves.contains(w)) {
466 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700467 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800468 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700469 if (wsa.mSurfaceController != null) {
470 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
471 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800472 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700473
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700474 if (pidCandidates.size() > 0) {
475 int[] pids = new int[pidCandidates.size()];
476 for (int i = 0; i < pids.length; i++) {
477 pids[i] = pidCandidates.keyAt(i);
478 }
479 try {
480 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
481 killedApps = true;
482 }
483 } catch (RemoteException e) {
484 }
485 }
486 }
487 }
488
489 if (leakedSurface || killedApps) {
490 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
491 // app to request another one.
492 Slog.w(TAG_WM,
493 "Looks like we have reclaimed some memory, clearing surface for retry.");
494 if (surfaceController != null) {
495 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
496 "RECOVER DESTROY", false);
497 winAnimator.destroySurface();
498 mService.scheduleRemoveStartingWindowLocked(winAnimator.mWin.mAppToken);
499 }
500
501 try {
502 winAnimator.mWin.mClient.dispatchGetNewSurface();
503 } catch (RemoteException e) {
504 }
505 }
506 } finally {
507 Binder.restoreCallingIdentity(callingIdentity);
508 }
509
510 return leakedSurface || killedApps;
511 }
512
513 // "Something has changed! Let's make it correct now."
514 // TODO: Super crazy long method that should be broken down...
515 void performSurfacePlacement(boolean recoveringMemory) {
516 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
517 + Debug.getCallers(3));
518
519 int i;
520 boolean updateInputWindowsNeeded = false;
521
522 if (mService.mFocusMayChange) {
523 mService.mFocusMayChange = false;
524 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
525 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
526 }
527
528 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700529 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700530 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700531 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700532 for (i = displayContent.mExitingTokens.size() - 1; i >= 0; i--) {
533 displayContent.mExitingTokens.get(i).hasVisible = false;
534 }
535 }
536
537 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
538 // Initialize state of exiting applications.
539 final AppTokenList exitingAppTokens =
540 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
541 for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
542 exitingAppTokens.get(tokenNdx).hasVisible = false;
543 }
544 }
545
546 mHoldScreen = null;
547 mScreenBrightness = -1;
548 mButtonBrightness = -1;
549 mUserActivityTimeout = -1;
550 mObscureApplicationContentOnSecondaryDisplays = false;
551 mSustainedPerformanceModeCurrent = false;
552 mService.mTransactionSequence++;
553
554 // TODO(multi-display):
555 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
556 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
557 final int defaultDw = defaultInfo.logicalWidth;
558 final int defaultDh = defaultInfo.logicalHeight;
559
560 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
561 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
562 mService.openSurfaceTransaction();
563 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700564 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700565 } catch (RuntimeException e) {
566 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
567 } finally {
568 mService.closeSurfaceTransaction();
569 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
570 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
571 }
572
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700573 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
574
575 // If we are ready to perform an app transition, check through all of the app tokens to be
576 // shown and see if they are ready to go.
577 if (mService.mAppTransition.isReady()) {
578 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700579 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700580 if (DEBUG_LAYOUT_REPEATS)
581 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
582 defaultDisplay.pendingLayoutChanges);
583 }
584
585 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
586 // We have finished the animation of an app transition. To do this, we have delayed a
587 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
588 // token list reflects the correct Z-order, but the window list may now be out of sync
589 // with it. So here we will just rebuild the entire app window list. Fun!
590 defaultDisplay.pendingLayoutChanges |=
591 mService.handleAnimatingStoppedAndTransitionLocked();
592 if (DEBUG_LAYOUT_REPEATS)
593 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
594 defaultDisplay.pendingLayoutChanges);
595 }
596
597 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
598 && !mService.mAppTransition.isReady()) {
599 // At this point, there was a window with a wallpaper that was force hiding other
600 // windows behind it, but now it is going away. This may be simple -- just animate away
601 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
602 // shown behind something that was hidden.
603 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
604 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
605 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
606 }
607 mWallpaperForceHidingChanged = false;
608
609 if (mWallpaperMayChange) {
610 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
611 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
612 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
613 defaultDisplay.pendingLayoutChanges);
614 }
615
616 if (mService.mFocusMayChange) {
617 mService.mFocusMayChange = false;
618 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
619 false /*updateInputWindows*/)) {
620 updateInputWindowsNeeded = true;
621 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
622 }
623 }
624
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700625 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700626 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
627 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
628 defaultDisplay.pendingLayoutChanges);
629 }
630
631 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
632 WindowState win = mService.mResizingWindows.get(i);
633 if (win.mAppFreezing) {
634 // Don't remove this window until rotation has completed.
635 continue;
636 }
637 // Discard the saved surface if window size is changed, it can't be reused.
638 if (win.mAppToken != null) {
639 win.mAppToken.destroySavedSurfaces();
640 }
641 win.reportResized();
642 mService.mResizingWindows.remove(i);
643 }
644
645 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
646 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
647 if (mOrientationChangeComplete) {
648 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
649 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
650 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
651 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
652 }
653 mService.stopFreezingDisplayLocked();
654 }
655
656 // Destroy the surface of any windows that are no longer visible.
657 boolean wallpaperDestroyed = false;
658 i = mService.mDestroySurface.size();
659 if (i > 0) {
660 do {
661 i--;
662 WindowState win = mService.mDestroySurface.get(i);
663 win.mDestroying = false;
664 if (mService.mInputMethodWindow == win) {
665 mService.mInputMethodWindow = null;
666 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700667 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700668 wallpaperDestroyed = true;
669 }
670 win.destroyOrSaveSurface();
671 } while (i > 0);
672 mService.mDestroySurface.clear();
673 }
674
675 // Time to remove any exiting tokens?
676 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700677 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700678 ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens;
679 for (i = exitingTokens.size() - 1; i >= 0; i--) {
680 WindowToken token = exitingTokens.get(i);
681 if (!token.hasVisible) {
682 exitingTokens.remove(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700683 }
684 }
685 }
686
687 // Time to remove any exiting applications?
688 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
689 // Initialize state of exiting applications.
690 final AppTokenList exitingAppTokens =
691 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
692 for (i = exitingAppTokens.size() - 1; i >= 0; i--) {
693 final AppWindowToken token = exitingAppTokens.get(i);
694 if (!token.hasVisible && !mService.mClosingApps.contains(token) &&
695 (!token.mIsExiting || token.isEmpty())) {
696 // Make sure there is no animation running on this token, so any windows
697 // associated with it will be removed as soon as their animations are complete
698 token.mAppAnimator.clearAnimation();
699 token.mAppAnimator.animating = false;
700 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
701 "performLayout: App token exiting now removed" + token);
702 token.removeIfPossible();
703 }
704 }
705 }
706
707 if (wallpaperDestroyed) {
708 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700709 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700710 }
711
712 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700713 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700714 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700715 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700716 }
717 }
718
719 // Finally update all input windows now that the window changes have stabilized.
720 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
721
722 mService.setHoldScreenLocked(mHoldScreen);
723 if (!mService.mDisplayFrozen) {
724 if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) {
725 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
726 } else {
727 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
728 toBrightnessOverride(mScreenBrightness));
729 }
730 if (mButtonBrightness < 0 || mButtonBrightness > 1.0f) {
731 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
732 } else {
733 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
734 toBrightnessOverride(mButtonBrightness));
735 }
736 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
737 mUserActivityTimeout);
738 }
739
740 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
741 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
742 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700743 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700744 (mSustainedPerformanceModeEnabled ? 1 : 0));
745 }
746
747 if (mService.mTurnOnScreen) {
748 if (mService.mAllowTheaterModeWakeFromLayout
749 || Settings.Global.getInt(mService.mContext.getContentResolver(),
750 Settings.Global.THEATER_MODE_ON, 0) == 0) {
751 if (DEBUG_VISIBILITY || DEBUG_POWER) {
752 Slog.v(TAG, "Turning screen on after layout!");
753 }
754 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
755 "android.server.wm:TURN_ON");
756 }
757 mService.mTurnOnScreen = false;
758 }
759
760 if (mUpdateRotation) {
761 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700762 // TODO(multi-display): Update rotation for different displays separately.
763 final int displayId = defaultDisplay.getDisplayId();
764 if (mService.updateRotationUncheckedLocked(false, displayId)) {
765 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700766 } else {
767 mUpdateRotation = false;
768 }
769 }
770
771 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700772 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
773 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700774 mService.checkDrawnWindowsLocked();
775 }
776
777 final int N = mService.mPendingRemove.size();
778 if (N > 0) {
779 if (mService.mPendingRemoveTmp.length < N) {
780 mService.mPendingRemoveTmp = new WindowState[N+10];
781 }
782 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
783 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700784 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700785 for (i = 0; i < N; i++) {
786 final WindowState w = mService.mPendingRemoveTmp[i];
787 w.removeImmediately();
788 final DisplayContent displayContent = w.getDisplayContent();
789 if (displayContent != null && !displayList.contains(displayContent)) {
790 displayList.add(displayContent);
791 }
792 }
793
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700794 for (int j = displayList.size() - 1; j >= 0; --j) {
795 final DisplayContent dc = displayList.get(j);
796 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700797 }
798 }
799
800 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700801 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
802 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700803 }
804
805 if (updateInputWindowsNeeded) {
806 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
807 }
808 mService.setFocusTaskRegionLocked();
809
810 // Check to see if we are now in a state where the screen should
811 // be enabled, because the window obscured flags have changed.
812 mService.enableScreenIfNeededLocked();
813
814 mService.scheduleAnimationLocked();
815 mService.mWindowPlacerLocked.destroyPendingSurfaces();
816
817 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
818 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
819 }
820
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700821 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
822 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700823 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700824 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700825
826 if (mService.mWatermark != null) {
827 mService.mWatermark.positionSurface(defaultDw, defaultDh);
828 }
829 if (mService.mStrictModeFlash != null) {
830 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
831 }
832 if (mService.mCircularDisplayMask != null) {
833 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh, mService.mRotation);
834 }
835 if (mService.mEmulatorDisplayOverlay != null) {
836 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
837 mService.mRotation);
838 }
839
840 boolean focusDisplayed = false;
841
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700842 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700843 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700844 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700845 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700846 }
847
848 if (focusDisplayed) {
849 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
850 }
851
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700852 // Give the display manager a chance to adjust properties like display rotation if it needs
853 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700854 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
855 }
856
857 /**
858 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700859 * @param obscured True if there is a window on top of this obscuring the display.
860 * @param syswin System window?
861 * @return True when the display contains content to show the user. When false, the display
862 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700863 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700864 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700865 final WindowManager.LayoutParams attrs = w.mAttrs;
866 final int attrFlags = attrs.flags;
867 final boolean canBeSeen = w.isDisplayedLw();
868 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700869 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700870
871 if (w.mHasSurface && canBeSeen) {
872 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
873 mHoldScreen = w.mSession;
874 mHoldScreenWindow = w;
875 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
876 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
877 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
878 + Debug.getCallers(10));
879 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700880 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700881 mScreenBrightness = w.mAttrs.screenBrightness;
882 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700883 if (!syswin && w.mAttrs.buttonBrightness >= 0 && mButtonBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700884 mButtonBrightness = w.mAttrs.buttonBrightness;
885 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700886 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700887 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
888 }
889
890 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700891 // This function assumes that the contents of the default display are processed first
892 // before secondary displays.
893 final DisplayContent displayContent = w.getDisplayContent();
894 if (displayContent != null && displayContent.isDefaultDisplay) {
895 // While a dream or keyguard is showing, obscure ordinary application content on
896 // secondary displays (by forcibly enabling mirroring unless there is other content
897 // we want to show) but still allow opaque keyguard dialogs to be shown.
898 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
899 mObscureApplicationContentOnSecondaryDisplays = true;
900 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700901 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700902 } else if (displayContent != null &&
903 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700904 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700905 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700906 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700907 }
908 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
909 mSustainedPerformanceModeCurrent = true;
910 }
911 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700912
913 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700914 }
915
916 boolean copyAnimToLayoutParams() {
917 boolean doRequest = false;
918
919 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
920 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
921 mUpdateRotation = true;
922 doRequest = true;
923 }
924 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
925 mWallpaperMayChange = true;
926 doRequest = true;
927 }
928 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
929 mWallpaperForceHidingChanged = true;
930 doRequest = true;
931 }
932 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
933 mOrientationChangeComplete = false;
934 } else {
935 mOrientationChangeComplete = true;
936 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
937 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
938 doRequest = true;
939 }
940 }
941 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
942 mService.mTurnOnScreen = true;
943 }
944 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
945 mWallpaperActionPending = true;
946 }
947
948 return doRequest;
949 }
950
951 private static int toBrightnessOverride(float value) {
952 return (int)(value * PowerManager.BRIGHTNESS_ON);
953 }
954
955 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
956 final FileDescriptor fd = pfd.getFileDescriptor();
957 if (mSurfaceTraceEnabled) {
958 disableSurfaceTrace();
959 }
960 mSurfaceTraceEnabled = true;
961 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
962 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700963 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
964 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700965 dc.enableSurfaceTrace(fd);
966 }
967 }
968
969 void disableSurfaceTrace() {
970 mSurfaceTraceEnabled = false;
971 mRemoteEventTrace = null;
972 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700973 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
974 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700975 dc.disableSurfaceTrace();
976 }
977 }
978
979 void dumpDisplayContents(PrintWriter pw) {
980 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
981 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700982 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700983 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700984 final DisplayContent displayContent = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700985 displayContent.dump(" ", pw);
986 }
987 } else {
988 pw.println(" NO DISPLAY");
989 }
990 }
991
992 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700993 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700994 return;
995 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700996 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700997 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700998 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700999 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001000 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001001 pw.print(displayContent.getDisplayId());
1002 }
1003 }
1004 pw.println();
1005 }
1006
1007 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaled1880962016-11-08 10:31:59 -08001008 final int[] index = new int[1];
1009 forAllWindows((w) -> {
1010 if (windows == null || windows.contains(w)) {
1011 pw.println(" Window #" + index[0] + " " + w + ":");
1012 w.dump(pw, " ", dumpAll || windows != null);
1013 index[0] = index[0] + 1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001014 }
Wale Ogunwaled1880962016-11-08 10:31:59 -08001015 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001016 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001017
Wale Ogunwale02319a62016-09-26 15:21:22 -07001018 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1019 pw.println(" All tokens:");
1020 for (int i = mChildren.size() - 1; i >= 0; --i) {
1021 mChildren.get(i).dumpTokens(pw, dumpAll);
1022 }
1023 }
1024
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001025 @Override
1026 String getName() {
1027 return "ROOT";
1028 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001029}