blob: 126e0800cf07f11d81902a0d71bbff9bd4ba93da [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);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700216
217 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700218 final Rect rect = new Rect();
219 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
220 displayInfo.overscanLeft = rect.left;
221 displayInfo.overscanTop = rect.top;
222 displayInfo.overscanRight = rect.right;
223 displayInfo.overscanBottom = rect.bottom;
224 if (mService.mDisplayManagerInternal != null) {
225 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
226 displayId, displayInfo);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700227 mService.configureDisplayPolicyLocked(dc);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700228
229 // TODO(multi-display): Create an input channel for each display with touch capability.
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800230 if (displayId == DEFAULT_DISPLAY && mService.canDispatchPointerEvents()) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700231 dc.mTapDetector = new TaskTapPointerEventListener(
232 mService, dc);
233 mService.registerPointerEventListener(dc.mTapDetector);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700234 mService.registerPointerEventListener(mService.mMousePositionTracker);
235 }
236 }
237
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700238 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700239 }
240
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700241 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700242 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700243 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700244 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700245 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700246 return true;
247 }
248 }
249 return false;
250 }
251
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000252 void getWindowsByName(ArrayList<WindowState> output, String name) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700253 int objectId = 0;
254 // See if this is an object ID.
255 try {
256 objectId = Integer.parseInt(name, 16);
257 name = null;
258 } catch (RuntimeException e) {
259 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800260
261 getWindowsByName(output, name, objectId);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700262 }
263
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000264 private void getWindowsByName(ArrayList<WindowState> output, String name, int objectId) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800265 forAllWindows((w) -> {
266 if (name != null) {
267 if (w.mAttrs.getTitle().toString().contains(name)) {
268 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700269 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800270 } else if (System.identityHashCode(w) == objectId) {
271 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700272 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800273 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700274 }
275
Wale Ogunwale02319a62016-09-26 15:21:22 -0700276 /**
277 * Returns the app window token for the input binder if it exist in the system.
278 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
279 * AppWindowToken represents an activity which can only exist on one display.
280 */
281 AppWindowToken getAppWindowToken(IBinder binder) {
282 for (int i = mChildren.size() - 1; i >= 0; --i) {
283 final DisplayContent dc = mChildren.get(i);
284 final AppWindowToken atoken = dc.getAppWindowToken(binder);
285 if (atoken != null) {
286 return atoken;
287 }
288 }
289 return null;
290 }
291
292 /** Returns the display object the input window token is currently mapped on. */
293 DisplayContent getWindowTokenDisplay(WindowToken token) {
294 if (token == null) {
295 return null;
296 }
297
298 for (int i = mChildren.size() - 1; i >= 0; --i) {
299 final DisplayContent dc = mChildren.get(i);
300 final WindowToken current = dc.getWindowToken(token.token);
301 if (current == token) {
302 return dc;
303 }
304 }
305
306 return null;
307 }
308
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700309 /**
310 * Set new display override config and return array of ids of stacks that were changed during
311 * update. If called for the default display, global configuration will also be updated.
312 */
313 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
314 final DisplayContent displayContent = getDisplayContent(displayId);
315 if (displayContent == null) {
316 throw new IllegalArgumentException("Display not found for id: " + displayId);
317 }
318
319 final Configuration currentConfig = displayContent.getOverrideConfiguration();
320 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
321 if (!configChanged) {
322 return null;
323 }
Andrii Kuliand68501e2017-01-10 22:57:27 -0800324 displayContent.onOverrideConfigurationChanged(newConfiguration);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700325
326 if (displayId == DEFAULT_DISPLAY) {
327 // Override configuration of the default display duplicates global config. In this case
328 // we also want to update the global config.
329 return setGlobalConfigurationIfNeeded(newConfiguration);
330 } else {
331 return updateStackBoundsAfterConfigChange(displayId);
332 }
333 }
334
335 private int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700336 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
337 if (!configChanged) {
338 return null;
339 }
340 onConfigurationChanged(newConfiguration);
341 return updateStackBoundsAfterConfigChange();
342 }
343
344 @Override
345 void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700346 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700347 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700348
349 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700350 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700351
Andrii Kulian441e4492016-09-29 15:25:00 -0700352 /**
353 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
354 * bounds were updated.
355 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700356 private int[] updateStackBoundsAfterConfigChange() {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700357 mChangedStackList.clear();
358
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700359 final int numDisplays = mChildren.size();
360 for (int i = 0; i < numDisplays; ++i) {
361 final DisplayContent dc = mChildren.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700362 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700363 }
364
365 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
366 }
367
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700368 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
369 private int[] updateStackBoundsAfterConfigChange(int displayId) {
370 mChangedStackList.clear();
371
372 final DisplayContent dc = getDisplayContent(displayId);
373 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
374
375 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
376 }
377
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700378 private void prepareFreezingTaskBounds() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700379 for (int i = mChildren.size() - 1; i >= 0; i--) {
380 mChildren.get(i).prepareFreezingTaskBounds();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700381 }
382 }
383
Wale Ogunwale1666e312016-12-16 11:27:18 -0800384 TaskStack getStackById(int stackId) {
385 for (int i = mChildren.size() - 1; i >= 0; i--) {
386 final DisplayContent dc = mChildren.get(i);
387 final TaskStack stack = dc.getStackById(stackId);
388 if (stack != null) {
389 return stack;
390 }
391 }
392 return null;
393 }
394
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700395 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800396 forAllWindows((w) -> {
397 if (w.mHasSurface && userId == UserHandle.getUserId(w.mOwnerUid)) {
398 w.mWinAnimator.setSecureLocked(disabled);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700399 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800400 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700401 }
402
403 void updateAppOpsState() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800404 forAllWindows((w) -> {
405 if (w.mAppOp == OP_NONE) {
406 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700407 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800408 final int mode = mService.mAppOps.checkOpNoThrow(w.mAppOp, w.getOwningUid(),
409 w.getOwningPackage());
410 w.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
411 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700412 }
413
414 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800415 final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw());
416 return win != null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700417 }
418
419 void closeSystemDialogs(String reason) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800420 mCloseSystemDialogsReason = reason;
421 forAllWindows(mCloseSystemDialogsConsumer, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700422 }
423
424 void removeReplacedWindows() {
425 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
426 mService.openSurfaceTransaction();
427 try {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800428 forAllWindows(sRemoveReplacedWindowsConsumer, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700429 } finally {
430 mService.closeSurfaceTransaction();
431 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
432 }
433 }
434
435 boolean hasPendingLayoutChanges(WindowAnimator animator) {
436 boolean hasChanges = false;
437
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700438 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700439 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700440 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700441 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
442 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
443 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
444 }
445 if (pendingChanges != 0) {
446 hasChanges = true;
447 }
448 }
449
450 return hasChanges;
451 }
452
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700453 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
454 boolean secure) {
455 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
456 boolean leakedSurface = false;
457 boolean killedApps = false;
458
459 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
460 winAnimator.mSession.mPid, operation);
461
462 final long callingIdentity = Binder.clearCallingIdentity();
463 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700464 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700465 // we haven't left any dangling surfaces around.
466
467 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700468 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700469 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700470 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700471 }
472
473 if (!leakedSurface) {
474 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700475 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700476 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800477 mChildren.get(displayNdx).forAllWindows((w) -> {
478 if (mService.mForceRemoves.contains(w)) {
479 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700480 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800481 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700482 if (wsa.mSurfaceController != null) {
483 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
484 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800485 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700486
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700487 if (pidCandidates.size() > 0) {
488 int[] pids = new int[pidCandidates.size()];
489 for (int i = 0; i < pids.length; i++) {
490 pids[i] = pidCandidates.keyAt(i);
491 }
492 try {
493 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
494 killedApps = true;
495 }
496 } catch (RemoteException e) {
497 }
498 }
499 }
500 }
501
502 if (leakedSurface || killedApps) {
503 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
504 // app to request another one.
505 Slog.w(TAG_WM,
506 "Looks like we have reclaimed some memory, clearing surface for retry.");
507 if (surfaceController != null) {
508 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
509 "RECOVER DESTROY", false);
510 winAnimator.destroySurface();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800511 if (winAnimator.mWin.mAppToken != null
512 && winAnimator.mWin.mAppToken.getController() != null) {
513 winAnimator.mWin.mAppToken.getController().removeStartingWindow();
514 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700515 }
516
517 try {
518 winAnimator.mWin.mClient.dispatchGetNewSurface();
519 } catch (RemoteException e) {
520 }
521 }
522 } finally {
523 Binder.restoreCallingIdentity(callingIdentity);
524 }
525
526 return leakedSurface || killedApps;
527 }
528
529 // "Something has changed! Let's make it correct now."
530 // TODO: Super crazy long method that should be broken down...
531 void performSurfacePlacement(boolean recoveringMemory) {
532 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
533 + Debug.getCallers(3));
534
535 int i;
536 boolean updateInputWindowsNeeded = false;
537
538 if (mService.mFocusMayChange) {
539 mService.mFocusMayChange = false;
540 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
541 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
542 }
543
544 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700545 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700546 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700547 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800548 displayContent.setExitingTokensHasVisible(false);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700549 }
550
551 mHoldScreen = null;
552 mScreenBrightness = -1;
553 mButtonBrightness = -1;
554 mUserActivityTimeout = -1;
555 mObscureApplicationContentOnSecondaryDisplays = false;
556 mSustainedPerformanceModeCurrent = false;
557 mService.mTransactionSequence++;
558
559 // TODO(multi-display):
560 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
561 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
562 final int defaultDw = defaultInfo.logicalWidth;
563 final int defaultDh = defaultInfo.logicalHeight;
564
565 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
566 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
567 mService.openSurfaceTransaction();
568 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700569 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700570 } catch (RuntimeException e) {
571 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
572 } finally {
573 mService.closeSurfaceTransaction();
574 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
575 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
576 }
577
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700578 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
579
580 // If we are ready to perform an app transition, check through all of the app tokens to be
581 // shown and see if they are ready to go.
582 if (mService.mAppTransition.isReady()) {
583 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700584 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700585 if (DEBUG_LAYOUT_REPEATS)
586 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
587 defaultDisplay.pendingLayoutChanges);
588 }
589
590 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
591 // We have finished the animation of an app transition. To do this, we have delayed a
592 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
593 // token list reflects the correct Z-order, but the window list may now be out of sync
594 // with it. So here we will just rebuild the entire app window list. Fun!
595 defaultDisplay.pendingLayoutChanges |=
596 mService.handleAnimatingStoppedAndTransitionLocked();
597 if (DEBUG_LAYOUT_REPEATS)
598 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
599 defaultDisplay.pendingLayoutChanges);
600 }
601
602 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
603 && !mService.mAppTransition.isReady()) {
604 // At this point, there was a window with a wallpaper that was force hiding other
605 // windows behind it, but now it is going away. This may be simple -- just animate away
606 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
607 // shown behind something that was hidden.
608 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
609 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
610 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
611 }
612 mWallpaperForceHidingChanged = false;
613
614 if (mWallpaperMayChange) {
615 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
616 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
617 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
618 defaultDisplay.pendingLayoutChanges);
619 }
620
621 if (mService.mFocusMayChange) {
622 mService.mFocusMayChange = false;
623 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
624 false /*updateInputWindows*/)) {
625 updateInputWindowsNeeded = true;
626 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
627 }
628 }
629
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700630 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700631 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
632 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
633 defaultDisplay.pendingLayoutChanges);
634 }
635
636 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
637 WindowState win = mService.mResizingWindows.get(i);
638 if (win.mAppFreezing) {
639 // Don't remove this window until rotation has completed.
640 continue;
641 }
642 // Discard the saved surface if window size is changed, it can't be reused.
643 if (win.mAppToken != null) {
644 win.mAppToken.destroySavedSurfaces();
645 }
646 win.reportResized();
647 mService.mResizingWindows.remove(i);
648 }
649
650 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
651 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
652 if (mOrientationChangeComplete) {
653 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
654 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
655 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
656 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
657 }
658 mService.stopFreezingDisplayLocked();
659 }
660
661 // Destroy the surface of any windows that are no longer visible.
662 boolean wallpaperDestroyed = false;
663 i = mService.mDestroySurface.size();
664 if (i > 0) {
665 do {
666 i--;
667 WindowState win = mService.mDestroySurface.get(i);
668 win.mDestroying = false;
669 if (mService.mInputMethodWindow == win) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000670 mService.setInputMethodWindowLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700671 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700672 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700673 wallpaperDestroyed = true;
674 }
675 win.destroyOrSaveSurface();
676 } while (i > 0);
677 mService.mDestroySurface.clear();
678 }
679
680 // Time to remove any exiting tokens?
681 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700682 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800683 displayContent.removeExistingTokensIfPossible();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700684 }
685
686 if (wallpaperDestroyed) {
687 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700688 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700689 }
690
691 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700692 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700693 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700694 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700695 }
696 }
697
698 // Finally update all input windows now that the window changes have stabilized.
699 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
700
701 mService.setHoldScreenLocked(mHoldScreen);
702 if (!mService.mDisplayFrozen) {
703 if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) {
704 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
705 } else {
706 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
707 toBrightnessOverride(mScreenBrightness));
708 }
709 if (mButtonBrightness < 0 || mButtonBrightness > 1.0f) {
710 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
711 } else {
712 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
713 toBrightnessOverride(mButtonBrightness));
714 }
715 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
716 mUserActivityTimeout);
717 }
718
719 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
720 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
721 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700722 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700723 (mSustainedPerformanceModeEnabled ? 1 : 0));
724 }
725
726 if (mService.mTurnOnScreen) {
727 if (mService.mAllowTheaterModeWakeFromLayout
728 || Settings.Global.getInt(mService.mContext.getContentResolver(),
729 Settings.Global.THEATER_MODE_ON, 0) == 0) {
730 if (DEBUG_VISIBILITY || DEBUG_POWER) {
731 Slog.v(TAG, "Turning screen on after layout!");
732 }
733 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
734 "android.server.wm:TURN_ON");
735 }
736 mService.mTurnOnScreen = false;
737 }
738
739 if (mUpdateRotation) {
740 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700741 // TODO(multi-display): Update rotation for different displays separately.
742 final int displayId = defaultDisplay.getDisplayId();
743 if (mService.updateRotationUncheckedLocked(false, displayId)) {
744 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700745 } else {
746 mUpdateRotation = false;
747 }
748 }
749
750 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700751 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
752 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700753 mService.checkDrawnWindowsLocked();
754 }
755
756 final int N = mService.mPendingRemove.size();
757 if (N > 0) {
758 if (mService.mPendingRemoveTmp.length < N) {
759 mService.mPendingRemoveTmp = new WindowState[N+10];
760 }
761 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
762 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700763 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700764 for (i = 0; i < N; i++) {
765 final WindowState w = mService.mPendingRemoveTmp[i];
766 w.removeImmediately();
767 final DisplayContent displayContent = w.getDisplayContent();
768 if (displayContent != null && !displayList.contains(displayContent)) {
769 displayList.add(displayContent);
770 }
771 }
772
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700773 for (int j = displayList.size() - 1; j >= 0; --j) {
774 final DisplayContent dc = displayList.get(j);
775 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700776 }
777 }
778
779 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700780 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
781 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700782 }
783
784 if (updateInputWindowsNeeded) {
785 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
786 }
David Stevensee9e2772017-02-09 16:30:27 -0800787 mService.setFocusTaskRegionLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700788
789 // Check to see if we are now in a state where the screen should
790 // be enabled, because the window obscured flags have changed.
791 mService.enableScreenIfNeededLocked();
792
793 mService.scheduleAnimationLocked();
794 mService.mWindowPlacerLocked.destroyPendingSurfaces();
795
796 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
797 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
798 }
799
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700800 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
801 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700802 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700803 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700804
805 if (mService.mWatermark != null) {
806 mService.mWatermark.positionSurface(defaultDw, defaultDh);
807 }
808 if (mService.mStrictModeFlash != null) {
809 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
810 }
811 if (mService.mCircularDisplayMask != null) {
812 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh, mService.mRotation);
813 }
814 if (mService.mEmulatorDisplayOverlay != null) {
815 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
816 mService.mRotation);
817 }
818
819 boolean focusDisplayed = false;
820
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700821 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700822 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700823 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700824 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700825 }
826
827 if (focusDisplayed) {
828 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
829 }
830
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700831 // Give the display manager a chance to adjust properties like display rotation if it needs
832 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700833 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
834 }
835
836 /**
837 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700838 * @param obscured True if there is a window on top of this obscuring the display.
839 * @param syswin System window?
840 * @return True when the display contains content to show the user. When false, the display
841 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700842 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700843 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700844 final WindowManager.LayoutParams attrs = w.mAttrs;
845 final int attrFlags = attrs.flags;
846 final boolean canBeSeen = w.isDisplayedLw();
847 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700848 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700849
850 if (w.mHasSurface && canBeSeen) {
851 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
852 mHoldScreen = w.mSession;
853 mHoldScreenWindow = w;
854 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
855 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
856 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
857 + Debug.getCallers(10));
858 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700859 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700860 mScreenBrightness = w.mAttrs.screenBrightness;
861 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700862 if (!syswin && w.mAttrs.buttonBrightness >= 0 && mButtonBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700863 mButtonBrightness = w.mAttrs.buttonBrightness;
864 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700865 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700866 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
867 }
868
869 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700870 // This function assumes that the contents of the default display are processed first
871 // before secondary displays.
872 final DisplayContent displayContent = w.getDisplayContent();
873 if (displayContent != null && displayContent.isDefaultDisplay) {
874 // While a dream or keyguard is showing, obscure ordinary application content on
875 // secondary displays (by forcibly enabling mirroring unless there is other content
876 // we want to show) but still allow opaque keyguard dialogs to be shown.
877 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
878 mObscureApplicationContentOnSecondaryDisplays = true;
879 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700880 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700881 } else if (displayContent != null &&
882 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700883 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700884 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700885 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700886 }
887 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
888 mSustainedPerformanceModeCurrent = true;
889 }
890 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700891
892 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700893 }
894
895 boolean copyAnimToLayoutParams() {
896 boolean doRequest = false;
897
898 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
899 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
900 mUpdateRotation = true;
901 doRequest = true;
902 }
903 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
904 mWallpaperMayChange = true;
905 doRequest = true;
906 }
907 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
908 mWallpaperForceHidingChanged = true;
909 doRequest = true;
910 }
911 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
912 mOrientationChangeComplete = false;
913 } else {
914 mOrientationChangeComplete = true;
915 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
916 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
917 doRequest = true;
918 }
919 }
920 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
921 mService.mTurnOnScreen = true;
922 }
923 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
924 mWallpaperActionPending = true;
925 }
926
927 return doRequest;
928 }
929
930 private static int toBrightnessOverride(float value) {
931 return (int)(value * PowerManager.BRIGHTNESS_ON);
932 }
933
934 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
935 final FileDescriptor fd = pfd.getFileDescriptor();
936 if (mSurfaceTraceEnabled) {
937 disableSurfaceTrace();
938 }
939 mSurfaceTraceEnabled = true;
940 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
941 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700942 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
943 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700944 dc.enableSurfaceTrace(fd);
945 }
946 }
947
948 void disableSurfaceTrace() {
949 mSurfaceTraceEnabled = false;
950 mRemoteEventTrace = null;
951 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700952 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
953 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700954 dc.disableSurfaceTrace();
955 }
956 }
957
958 void dumpDisplayContents(PrintWriter pw) {
959 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
960 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700961 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700962 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700963 final DisplayContent displayContent = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700964 displayContent.dump(" ", pw);
965 }
966 } else {
967 pw.println(" NO DISPLAY");
968 }
969 }
970
971 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700972 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700973 return;
974 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700975 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700976 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700977 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700978 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700979 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700980 pw.print(displayContent.getDisplayId());
981 }
982 }
983 pw.println();
984 }
985
986 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800987 final int[] index = new int[1];
988 forAllWindows((w) -> {
989 if (windows == null || windows.contains(w)) {
990 pw.println(" Window #" + index[0] + " " + w + ":");
991 w.dump(pw, " ", dumpAll || windows != null);
992 index[0] = index[0] + 1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700993 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800994 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700995 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700996
Wale Ogunwale02319a62016-09-26 15:21:22 -0700997 void dumpTokens(PrintWriter pw, boolean dumpAll) {
998 pw.println(" All tokens:");
999 for (int i = mChildren.size() - 1; i >= 0; --i) {
1000 mChildren.get(i).dumpTokens(pw, dumpAll);
1001 }
1002 }
1003
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001004 @Override
1005 String getName() {
1006 return "ROOT";
1007 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001008}