blob: 06b508afc6259afde1bf9c36c41869b8adc758bb [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 Ogunwale1e129a42016-11-21 13:03:47 -080043import java.util.function.Consumer;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070044
Wale Ogunwalef7cab102016-10-25 15:25:14 -070045import static android.app.AppOpsManager.MODE_ALLOWED;
46import static android.app.AppOpsManager.MODE_DEFAULT;
47import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwale02319a62016-09-26 15:21:22 -070048import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070049import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070050import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070051import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
52import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
53import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070054import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070055import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
56import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi879ff722016-11-04 18:08:17 -070057
Wale Ogunwalee05f5012016-09-16 16:27:29 -070058import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
59import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
60import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070061import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
62import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
63import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070064import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
65import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
66import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
67import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
68import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
69import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
70import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
71import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
72import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
73import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070074import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
75import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070076import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
77import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
78import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
79import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
80import static com.android.server.wm.WindowManagerService.logSurface;
81import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
82import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
83import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
84import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
85import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
86import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
87
88/** Root {@link WindowContainer} for the device. */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -070089class RootWindowContainer extends WindowContainer<DisplayContent> {
Wale Ogunwalee05f5012016-09-16 16:27:29 -070090 private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM;
91
92 WindowManagerService mService;
93
Wale Ogunwalee05f5012016-09-16 16:27:29 -070094 private boolean mWallpaperForceHidingChanged = false;
95 private Object mLastWindowFreezeSource = null;
96 private Session mHoldScreen = null;
97 private float mScreenBrightness = -1;
98 private float mButtonBrightness = -1;
99 private long mUserActivityTimeout = -1;
100 private boolean mUpdateRotation = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700101 // Following variables are for debugging screen wakelock only.
102 // Last window that requires screen wakelock
103 WindowState mHoldScreenWindow = null;
104 // Last window that obscures all windows below
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700105 WindowState mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700106 // Only set while traversing the default display based on its content.
107 // Affects the behavior of mirroring on secondary displays.
108 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
109
110 private boolean mSustainedPerformanceModeEnabled = false;
111 private boolean mSustainedPerformanceModeCurrent = false;
112
113 boolean mWallpaperMayChange = false;
Robert Carr11c26c22016-09-23 12:40:27 -0700114 // During an orientation change, we track whether all windows have rendered
115 // at the new orientation, and this will be false from changing orientation until that occurs.
116 // For seamless rotation cases this always stays true, as the windows complete their orientation
117 // changes 1 by 1 without disturbing global state.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700118 boolean mOrientationChangeComplete = true;
119 boolean mWallpaperActionPending = false;
120
121 private final ArrayList<Integer> mChangedStackList = new ArrayList();
122
123 // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
124 // instances will be replaced with an instance that writes a binary representation of all
125 // commands to mSurfaceTraceFd.
126 boolean mSurfaceTraceEnabled;
127 ParcelFileDescriptor mSurfaceTraceFd;
128 RemoteEventTrace mRemoteEventTrace;
129
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700130 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700131 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700132
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800133 private String mCloseSystemDialogsReason;
134 private final Consumer<WindowState> mCloseSystemDialogsConsumer = w -> {
135 if (w.mHasSurface) {
136 try {
137 w.mClient.closeSystemDialogs(mCloseSystemDialogsReason);
138 } catch (RemoteException e) {
139 }
140 }
141 };
142
143 private static final Consumer<WindowState> sRemoveReplacedWindowsConsumer = w -> {
144 final AppWindowToken aToken = w.mAppToken;
145 if (aToken != null) {
146 aToken.removeReplacedWindowIfNeeded(w);
147 }
148 };
149
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700150 RootWindowContainer(WindowManagerService service) {
151 mService = service;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700152 mLayersController = new WindowLayersController(mService);
Wale Ogunwale0303c572016-10-20 10:16:29 -0700153 mWallpaperController = new WallpaperController(mService);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700154 }
155
156 WindowState computeFocusedWindow() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700157 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700158 for (int i = 0; i < count; i++) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700159 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700160 final WindowState win = dc.findFocusedWindow();
161 if (win != null) {
162 return win;
163 }
164 }
165 return null;
166 }
167
168 /**
Andrii Kulian7fc22812016-12-28 13:04:11 -0800169 * Get an array with display ids ordered by focus priority - last items should be given
170 * focus first. Sparse array just maps position to displayId.
171 */
172 void getDisplaysInFocusOrder(SparseIntArray displaysInFocusOrder) {
173 displaysInFocusOrder.clear();
174
175 final int size = mChildren.size();
176 for (int i = 0; i < size; ++i) {
177 displaysInFocusOrder.put(i, mChildren.get(i).getDisplayId());
178 }
179 }
180
181 /**
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700182 * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
183 * there is a Display for the displayId.
184 *
185 * @param displayId The display the caller is interested in.
186 * @return The DisplayContent associated with displayId or null if there is no Display for it.
187 */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700188 DisplayContent getDisplayContentOrCreate(int displayId) {
189 DisplayContent dc = getDisplayContent(displayId);
190
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700191 if (dc == null) {
192 final Display display = mService.mDisplayManager.getDisplay(displayId);
193 if (display != null) {
194 dc = createDisplayContent(display);
195 }
196 }
197 return dc;
198 }
199
Wale Ogunwale02319a62016-09-26 15:21:22 -0700200 DisplayContent getDisplayContent(int displayId) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700201 for (int i = mChildren.size() - 1; i >= 0; --i) {
202 final DisplayContent current = mChildren.get(i);
203 if (current.getDisplayId() == displayId) {
204 return current;
205 }
206 }
207 return null;
208 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700209
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700210 private DisplayContent createDisplayContent(final Display display) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700211 final DisplayContent dc = new DisplayContent(display, mService, mLayersController,
212 mWallpaperController);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700213 final int displayId = display.getDisplayId();
214
215 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
216 addChild(dc, null);
217
218 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700219 final Rect rect = new Rect();
220 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
221 displayInfo.overscanLeft = rect.left;
222 displayInfo.overscanTop = rect.top;
223 displayInfo.overscanRight = rect.right;
224 displayInfo.overscanBottom = rect.bottom;
225 if (mService.mDisplayManagerInternal != null) {
226 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
227 displayId, displayInfo);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700228 mService.configureDisplayPolicyLocked(dc);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700229
230 // TODO(multi-display): Create an input channel for each display with touch capability.
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700231 if (displayId == DEFAULT_DISPLAY) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700232 dc.mTapDetector = new TaskTapPointerEventListener(
233 mService, dc);
234 mService.registerPointerEventListener(dc.mTapDetector);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700235 mService.registerPointerEventListener(mService.mMousePositionTracker);
236 }
237 }
238
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700239 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700240 }
241
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700242 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700243 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700244 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700245 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700246 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700247 return true;
248 }
249 }
250 return false;
251 }
252
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000253 void getWindowsByName(ArrayList<WindowState> output, String name) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700254 int objectId = 0;
255 // See if this is an object ID.
256 try {
257 objectId = Integer.parseInt(name, 16);
258 name = null;
259 } catch (RuntimeException e) {
260 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800261
262 getWindowsByName(output, name, objectId);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700263 }
264
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000265 private void getWindowsByName(ArrayList<WindowState> output, String name, int objectId) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800266 forAllWindows((w) -> {
267 if (name != null) {
268 if (w.mAttrs.getTitle().toString().contains(name)) {
269 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700270 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800271 } else if (System.identityHashCode(w) == objectId) {
272 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700273 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800274 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700275 }
276
Wale Ogunwale02319a62016-09-26 15:21:22 -0700277 /**
278 * Returns the app window token for the input binder if it exist in the system.
279 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
280 * AppWindowToken represents an activity which can only exist on one display.
281 */
282 AppWindowToken getAppWindowToken(IBinder binder) {
283 for (int i = mChildren.size() - 1; i >= 0; --i) {
284 final DisplayContent dc = mChildren.get(i);
285 final AppWindowToken atoken = dc.getAppWindowToken(binder);
286 if (atoken != null) {
287 return atoken;
288 }
289 }
290 return null;
291 }
292
293 /** Returns the display object the input window token is currently mapped on. */
294 DisplayContent getWindowTokenDisplay(WindowToken token) {
295 if (token == null) {
296 return null;
297 }
298
299 for (int i = mChildren.size() - 1; i >= 0; --i) {
300 final DisplayContent dc = mChildren.get(i);
301 final WindowToken current = dc.getWindowToken(token.token);
302 if (current == token) {
303 return dc;
304 }
305 }
306
307 return null;
308 }
309
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700310 /**
311 * Set new display override config and return array of ids of stacks that were changed during
312 * update. If called for the default display, global configuration will also be updated.
313 */
314 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
315 final DisplayContent displayContent = getDisplayContent(displayId);
316 if (displayContent == null) {
317 throw new IllegalArgumentException("Display not found for id: " + displayId);
318 }
319
320 final Configuration currentConfig = displayContent.getOverrideConfiguration();
321 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
322 if (!configChanged) {
323 return null;
324 }
Andrii Kuliand68501e2017-01-10 22:57:27 -0800325 displayContent.onOverrideConfigurationChanged(newConfiguration);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700326
327 if (displayId == DEFAULT_DISPLAY) {
328 // Override configuration of the default display duplicates global config. In this case
329 // we also want to update the global config.
330 return setGlobalConfigurationIfNeeded(newConfiguration);
331 } else {
332 return updateStackBoundsAfterConfigChange(displayId);
333 }
334 }
335
336 private int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700337 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
338 if (!configChanged) {
339 return null;
340 }
341 onConfigurationChanged(newConfiguration);
342 return updateStackBoundsAfterConfigChange();
343 }
344
345 @Override
346 void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700347 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700348 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700349
350 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700351 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700352
Andrii Kulian441e4492016-09-29 15:25:00 -0700353 /**
354 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
355 * bounds were updated.
356 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700357 private int[] updateStackBoundsAfterConfigChange() {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700358 mChangedStackList.clear();
359
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700360 final int numDisplays = mChildren.size();
361 for (int i = 0; i < numDisplays; ++i) {
362 final DisplayContent dc = mChildren.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700363 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700364 }
365
366 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
367 }
368
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700369 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
370 private int[] updateStackBoundsAfterConfigChange(int displayId) {
371 mChangedStackList.clear();
372
373 final DisplayContent dc = getDisplayContent(displayId);
374 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
375
376 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
377 }
378
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700379 private void prepareFreezingTaskBounds() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700380 for (int i = mChildren.size() - 1; i >= 0; i--) {
381 mChildren.get(i).prepareFreezingTaskBounds();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700382 }
383 }
384
385 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800386 forAllWindows((w) -> {
387 if (w.mHasSurface && userId == UserHandle.getUserId(w.mOwnerUid)) {
388 w.mWinAnimator.setSecureLocked(disabled);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700389 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800390 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700391 }
392
393 void updateAppOpsState() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800394 forAllWindows((w) -> {
395 if (w.mAppOp == OP_NONE) {
396 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700397 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800398 final int mode = mService.mAppOps.checkOpNoThrow(w.mAppOp, w.getOwningUid(),
399 w.getOwningPackage());
400 w.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
401 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700402 }
403
404 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800405 final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw());
406 return win != null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700407 }
408
409 void closeSystemDialogs(String reason) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800410 mCloseSystemDialogsReason = reason;
411 forAllWindows(mCloseSystemDialogsConsumer, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700412 }
413
414 void removeReplacedWindows() {
415 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
416 mService.openSurfaceTransaction();
417 try {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800418 forAllWindows(sRemoveReplacedWindowsConsumer, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700419 } finally {
420 mService.closeSurfaceTransaction();
421 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
422 }
423 }
424
425 boolean hasPendingLayoutChanges(WindowAnimator animator) {
426 boolean hasChanges = false;
427
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700428 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700429 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700430 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700431 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
432 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
433 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
434 }
435 if (pendingChanges != 0) {
436 hasChanges = true;
437 }
438 }
439
440 return hasChanges;
441 }
442
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700443 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
444 boolean secure) {
445 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
446 boolean leakedSurface = false;
447 boolean killedApps = false;
448
449 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
450 winAnimator.mSession.mPid, operation);
451
452 final long callingIdentity = Binder.clearCallingIdentity();
453 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700454 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700455 // we haven't left any dangling surfaces around.
456
457 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700458 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700459 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700460 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700461 }
462
463 if (!leakedSurface) {
464 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700465 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700466 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800467 mChildren.get(displayNdx).forAllWindows((w) -> {
468 if (mService.mForceRemoves.contains(w)) {
469 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700470 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800471 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700472 if (wsa.mSurfaceController != null) {
473 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
474 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800475 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700476
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700477 if (pidCandidates.size() > 0) {
478 int[] pids = new int[pidCandidates.size()];
479 for (int i = 0; i < pids.length; i++) {
480 pids[i] = pidCandidates.keyAt(i);
481 }
482 try {
483 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
484 killedApps = true;
485 }
486 } catch (RemoteException e) {
487 }
488 }
489 }
490 }
491
492 if (leakedSurface || killedApps) {
493 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
494 // app to request another one.
495 Slog.w(TAG_WM,
496 "Looks like we have reclaimed some memory, clearing surface for retry.");
497 if (surfaceController != null) {
498 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
499 "RECOVER DESTROY", false);
500 winAnimator.destroySurface();
501 mService.scheduleRemoveStartingWindowLocked(winAnimator.mWin.mAppToken);
502 }
503
504 try {
505 winAnimator.mWin.mClient.dispatchGetNewSurface();
506 } catch (RemoteException e) {
507 }
508 }
509 } finally {
510 Binder.restoreCallingIdentity(callingIdentity);
511 }
512
513 return leakedSurface || killedApps;
514 }
515
516 // "Something has changed! Let's make it correct now."
517 // TODO: Super crazy long method that should be broken down...
518 void performSurfacePlacement(boolean recoveringMemory) {
519 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
520 + Debug.getCallers(3));
521
522 int i;
523 boolean updateInputWindowsNeeded = false;
524
525 if (mService.mFocusMayChange) {
526 mService.mFocusMayChange = false;
527 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
528 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
529 }
530
531 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700532 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700533 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700534 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700535 for (i = displayContent.mExitingTokens.size() - 1; i >= 0; i--) {
536 displayContent.mExitingTokens.get(i).hasVisible = false;
537 }
538 }
539
540 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
541 // Initialize state of exiting applications.
542 final AppTokenList exitingAppTokens =
543 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
544 for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
545 exitingAppTokens.get(tokenNdx).hasVisible = false;
546 }
547 }
548
549 mHoldScreen = null;
550 mScreenBrightness = -1;
551 mButtonBrightness = -1;
552 mUserActivityTimeout = -1;
553 mObscureApplicationContentOnSecondaryDisplays = false;
554 mSustainedPerformanceModeCurrent = false;
555 mService.mTransactionSequence++;
556
557 // TODO(multi-display):
558 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
559 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
560 final int defaultDw = defaultInfo.logicalWidth;
561 final int defaultDh = defaultInfo.logicalHeight;
562
563 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
564 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
565 mService.openSurfaceTransaction();
566 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700567 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700568 } catch (RuntimeException e) {
569 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
570 } finally {
571 mService.closeSurfaceTransaction();
572 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
573 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
574 }
575
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700576 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
577
578 // If we are ready to perform an app transition, check through all of the app tokens to be
579 // shown and see if they are ready to go.
580 if (mService.mAppTransition.isReady()) {
581 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700582 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700583 if (DEBUG_LAYOUT_REPEATS)
584 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
585 defaultDisplay.pendingLayoutChanges);
586 }
587
588 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
589 // We have finished the animation of an app transition. To do this, we have delayed a
590 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
591 // token list reflects the correct Z-order, but the window list may now be out of sync
592 // with it. So here we will just rebuild the entire app window list. Fun!
593 defaultDisplay.pendingLayoutChanges |=
594 mService.handleAnimatingStoppedAndTransitionLocked();
595 if (DEBUG_LAYOUT_REPEATS)
596 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
597 defaultDisplay.pendingLayoutChanges);
598 }
599
600 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
601 && !mService.mAppTransition.isReady()) {
602 // At this point, there was a window with a wallpaper that was force hiding other
603 // windows behind it, but now it is going away. This may be simple -- just animate away
604 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
605 // shown behind something that was hidden.
606 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
607 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
608 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
609 }
610 mWallpaperForceHidingChanged = false;
611
612 if (mWallpaperMayChange) {
613 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
614 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
615 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
616 defaultDisplay.pendingLayoutChanges);
617 }
618
619 if (mService.mFocusMayChange) {
620 mService.mFocusMayChange = false;
621 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
622 false /*updateInputWindows*/)) {
623 updateInputWindowsNeeded = true;
624 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
625 }
626 }
627
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700628 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700629 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
630 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
631 defaultDisplay.pendingLayoutChanges);
632 }
633
634 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
635 WindowState win = mService.mResizingWindows.get(i);
636 if (win.mAppFreezing) {
637 // Don't remove this window until rotation has completed.
638 continue;
639 }
640 // Discard the saved surface if window size is changed, it can't be reused.
641 if (win.mAppToken != null) {
642 win.mAppToken.destroySavedSurfaces();
643 }
644 win.reportResized();
645 mService.mResizingWindows.remove(i);
646 }
647
648 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
649 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
650 if (mOrientationChangeComplete) {
651 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
652 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
653 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
654 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
655 }
656 mService.stopFreezingDisplayLocked();
657 }
658
659 // Destroy the surface of any windows that are no longer visible.
660 boolean wallpaperDestroyed = false;
661 i = mService.mDestroySurface.size();
662 if (i > 0) {
663 do {
664 i--;
665 WindowState win = mService.mDestroySurface.get(i);
666 win.mDestroying = false;
667 if (mService.mInputMethodWindow == win) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000668 mService.setInputMethodWindowLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700669 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700670 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700671 wallpaperDestroyed = true;
672 }
673 win.destroyOrSaveSurface();
674 } while (i > 0);
675 mService.mDestroySurface.clear();
676 }
677
678 // Time to remove any exiting tokens?
679 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700680 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700681 ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens;
682 for (i = exitingTokens.size() - 1; i >= 0; i--) {
683 WindowToken token = exitingTokens.get(i);
684 if (!token.hasVisible) {
685 exitingTokens.remove(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700686 }
687 }
688 }
689
690 // Time to remove any exiting applications?
691 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
692 // Initialize state of exiting applications.
693 final AppTokenList exitingAppTokens =
694 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
695 for (i = exitingAppTokens.size() - 1; i >= 0; i--) {
696 final AppWindowToken token = exitingAppTokens.get(i);
697 if (!token.hasVisible && !mService.mClosingApps.contains(token) &&
698 (!token.mIsExiting || token.isEmpty())) {
699 // Make sure there is no animation running on this token, so any windows
700 // associated with it will be removed as soon as their animations are complete
701 token.mAppAnimator.clearAnimation();
702 token.mAppAnimator.animating = false;
703 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
704 "performLayout: App token exiting now removed" + token);
705 token.removeIfPossible();
706 }
707 }
708 }
709
710 if (wallpaperDestroyed) {
711 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700712 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700713 }
714
715 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700716 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700717 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700718 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700719 }
720 }
721
722 // Finally update all input windows now that the window changes have stabilized.
723 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
724
725 mService.setHoldScreenLocked(mHoldScreen);
726 if (!mService.mDisplayFrozen) {
727 if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) {
728 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
729 } else {
730 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
731 toBrightnessOverride(mScreenBrightness));
732 }
733 if (mButtonBrightness < 0 || mButtonBrightness > 1.0f) {
734 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
735 } else {
736 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
737 toBrightnessOverride(mButtonBrightness));
738 }
739 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
740 mUserActivityTimeout);
741 }
742
743 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
744 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
745 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700746 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700747 (mSustainedPerformanceModeEnabled ? 1 : 0));
748 }
749
750 if (mService.mTurnOnScreen) {
751 if (mService.mAllowTheaterModeWakeFromLayout
752 || Settings.Global.getInt(mService.mContext.getContentResolver(),
753 Settings.Global.THEATER_MODE_ON, 0) == 0) {
754 if (DEBUG_VISIBILITY || DEBUG_POWER) {
755 Slog.v(TAG, "Turning screen on after layout!");
756 }
757 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
758 "android.server.wm:TURN_ON");
759 }
760 mService.mTurnOnScreen = false;
761 }
762
763 if (mUpdateRotation) {
764 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700765 // TODO(multi-display): Update rotation for different displays separately.
766 final int displayId = defaultDisplay.getDisplayId();
767 if (mService.updateRotationUncheckedLocked(false, displayId)) {
768 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700769 } else {
770 mUpdateRotation = false;
771 }
772 }
773
774 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700775 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
776 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700777 mService.checkDrawnWindowsLocked();
778 }
779
780 final int N = mService.mPendingRemove.size();
781 if (N > 0) {
782 if (mService.mPendingRemoveTmp.length < N) {
783 mService.mPendingRemoveTmp = new WindowState[N+10];
784 }
785 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
786 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700787 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700788 for (i = 0; i < N; i++) {
789 final WindowState w = mService.mPendingRemoveTmp[i];
790 w.removeImmediately();
791 final DisplayContent displayContent = w.getDisplayContent();
792 if (displayContent != null && !displayList.contains(displayContent)) {
793 displayList.add(displayContent);
794 }
795 }
796
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700797 for (int j = displayList.size() - 1; j >= 0; --j) {
798 final DisplayContent dc = displayList.get(j);
799 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700800 }
801 }
802
803 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700804 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
805 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700806 }
807
808 if (updateInputWindowsNeeded) {
809 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
810 }
811 mService.setFocusTaskRegionLocked();
812
813 // Check to see if we are now in a state where the screen should
814 // be enabled, because the window obscured flags have changed.
815 mService.enableScreenIfNeededLocked();
816
817 mService.scheduleAnimationLocked();
818 mService.mWindowPlacerLocked.destroyPendingSurfaces();
819
820 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
821 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
822 }
823
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700824 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
825 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700826 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700827 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700828
829 if (mService.mWatermark != null) {
830 mService.mWatermark.positionSurface(defaultDw, defaultDh);
831 }
832 if (mService.mStrictModeFlash != null) {
833 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
834 }
835 if (mService.mCircularDisplayMask != null) {
836 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh, mService.mRotation);
837 }
838 if (mService.mEmulatorDisplayOverlay != null) {
839 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
840 mService.mRotation);
841 }
842
843 boolean focusDisplayed = false;
844
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700845 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700846 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700847 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700848 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700849 }
850
851 if (focusDisplayed) {
852 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
853 }
854
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700855 // Give the display manager a chance to adjust properties like display rotation if it needs
856 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700857 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
858 }
859
860 /**
861 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700862 * @param obscured True if there is a window on top of this obscuring the display.
863 * @param syswin System window?
864 * @return True when the display contains content to show the user. When false, the display
865 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700866 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700867 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700868 final WindowManager.LayoutParams attrs = w.mAttrs;
869 final int attrFlags = attrs.flags;
870 final boolean canBeSeen = w.isDisplayedLw();
871 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700872 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700873
874 if (w.mHasSurface && canBeSeen) {
875 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
876 mHoldScreen = w.mSession;
877 mHoldScreenWindow = w;
878 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
879 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
880 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
881 + Debug.getCallers(10));
882 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700883 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700884 mScreenBrightness = w.mAttrs.screenBrightness;
885 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700886 if (!syswin && w.mAttrs.buttonBrightness >= 0 && mButtonBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700887 mButtonBrightness = w.mAttrs.buttonBrightness;
888 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700889 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700890 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
891 }
892
893 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700894 // This function assumes that the contents of the default display are processed first
895 // before secondary displays.
896 final DisplayContent displayContent = w.getDisplayContent();
897 if (displayContent != null && displayContent.isDefaultDisplay) {
898 // While a dream or keyguard is showing, obscure ordinary application content on
899 // secondary displays (by forcibly enabling mirroring unless there is other content
900 // we want to show) but still allow opaque keyguard dialogs to be shown.
901 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
902 mObscureApplicationContentOnSecondaryDisplays = true;
903 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700904 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700905 } else if (displayContent != null &&
906 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700907 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700908 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700909 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700910 }
911 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
912 mSustainedPerformanceModeCurrent = true;
913 }
914 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700915
916 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700917 }
918
919 boolean copyAnimToLayoutParams() {
920 boolean doRequest = false;
921
922 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
923 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
924 mUpdateRotation = true;
925 doRequest = true;
926 }
927 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
928 mWallpaperMayChange = true;
929 doRequest = true;
930 }
931 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
932 mWallpaperForceHidingChanged = true;
933 doRequest = true;
934 }
935 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
936 mOrientationChangeComplete = false;
937 } else {
938 mOrientationChangeComplete = true;
939 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
940 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
941 doRequest = true;
942 }
943 }
944 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
945 mService.mTurnOnScreen = true;
946 }
947 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
948 mWallpaperActionPending = true;
949 }
950
951 return doRequest;
952 }
953
954 private static int toBrightnessOverride(float value) {
955 return (int)(value * PowerManager.BRIGHTNESS_ON);
956 }
957
958 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
959 final FileDescriptor fd = pfd.getFileDescriptor();
960 if (mSurfaceTraceEnabled) {
961 disableSurfaceTrace();
962 }
963 mSurfaceTraceEnabled = true;
964 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
965 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700966 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
967 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700968 dc.enableSurfaceTrace(fd);
969 }
970 }
971
972 void disableSurfaceTrace() {
973 mSurfaceTraceEnabled = false;
974 mRemoteEventTrace = null;
975 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700976 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
977 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700978 dc.disableSurfaceTrace();
979 }
980 }
981
982 void dumpDisplayContents(PrintWriter pw) {
983 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
984 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700985 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700986 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700987 final DisplayContent displayContent = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700988 displayContent.dump(" ", pw);
989 }
990 } else {
991 pw.println(" NO DISPLAY");
992 }
993 }
994
995 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700996 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700997 return;
998 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700999 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001000 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001001 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001002 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001003 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001004 pw.print(displayContent.getDisplayId());
1005 }
1006 }
1007 pw.println();
1008 }
1009
1010 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaled1880962016-11-08 10:31:59 -08001011 final int[] index = new int[1];
1012 forAllWindows((w) -> {
1013 if (windows == null || windows.contains(w)) {
1014 pw.println(" Window #" + index[0] + " " + w + ":");
1015 w.dump(pw, " ", dumpAll || windows != null);
1016 index[0] = index[0] + 1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001017 }
Wale Ogunwaled1880962016-11-08 10:31:59 -08001018 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001019 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001020
Wale Ogunwale02319a62016-09-26 15:21:22 -07001021 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1022 pw.println(" All tokens:");
1023 for (int i = mChildren.size() - 1; i >= 0; --i) {
1024 mChildren.get(i).dumpTokens(pw, dumpAll);
1025 }
1026 }
1027
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001028 @Override
1029 String getName() {
1030 return "ROOT";
1031 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001032}