blob: 22abf3056afffb896b35f28bf936e765d836eaca [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 Kulian4ede3e02017-01-12 11:52:31 -0800231 if (displayId == DEFAULT_DISPLAY && mService.canDispatchPointerEvents()) {
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
Wale Ogunwale1666e312016-12-16 11:27:18 -0800385 TaskStack getStackById(int stackId) {
386 for (int i = mChildren.size() - 1; i >= 0; i--) {
387 final DisplayContent dc = mChildren.get(i);
388 final TaskStack stack = dc.getStackById(stackId);
389 if (stack != null) {
390 return stack;
391 }
392 }
393 return null;
394 }
395
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700396 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800397 forAllWindows((w) -> {
398 if (w.mHasSurface && userId == UserHandle.getUserId(w.mOwnerUid)) {
399 w.mWinAnimator.setSecureLocked(disabled);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700400 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800401 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700402 }
403
404 void updateAppOpsState() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800405 forAllWindows((w) -> {
406 if (w.mAppOp == OP_NONE) {
407 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700408 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800409 final int mode = mService.mAppOps.checkOpNoThrow(w.mAppOp, w.getOwningUid(),
410 w.getOwningPackage());
411 w.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
412 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700413 }
414
415 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800416 final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw());
417 return win != null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700418 }
419
420 void closeSystemDialogs(String reason) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800421 mCloseSystemDialogsReason = reason;
422 forAllWindows(mCloseSystemDialogsConsumer, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700423 }
424
425 void removeReplacedWindows() {
426 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
427 mService.openSurfaceTransaction();
428 try {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800429 forAllWindows(sRemoveReplacedWindowsConsumer, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700430 } finally {
431 mService.closeSurfaceTransaction();
432 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
433 }
434 }
435
436 boolean hasPendingLayoutChanges(WindowAnimator animator) {
437 boolean hasChanges = false;
438
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700439 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700440 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700441 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700442 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
443 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
444 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
445 }
446 if (pendingChanges != 0) {
447 hasChanges = true;
448 }
449 }
450
451 return hasChanges;
452 }
453
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700454 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
455 boolean secure) {
456 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
457 boolean leakedSurface = false;
458 boolean killedApps = false;
459
460 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
461 winAnimator.mSession.mPid, operation);
462
463 final long callingIdentity = Binder.clearCallingIdentity();
464 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700465 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700466 // we haven't left any dangling surfaces around.
467
468 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700469 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700470 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700471 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700472 }
473
474 if (!leakedSurface) {
475 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700476 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700477 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800478 mChildren.get(displayNdx).forAllWindows((w) -> {
479 if (mService.mForceRemoves.contains(w)) {
480 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700481 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800482 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700483 if (wsa.mSurfaceController != null) {
484 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
485 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800486 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700487
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700488 if (pidCandidates.size() > 0) {
489 int[] pids = new int[pidCandidates.size()];
490 for (int i = 0; i < pids.length; i++) {
491 pids[i] = pidCandidates.keyAt(i);
492 }
493 try {
494 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
495 killedApps = true;
496 }
497 } catch (RemoteException e) {
498 }
499 }
500 }
501 }
502
503 if (leakedSurface || killedApps) {
504 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
505 // app to request another one.
506 Slog.w(TAG_WM,
507 "Looks like we have reclaimed some memory, clearing surface for retry.");
508 if (surfaceController != null) {
509 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
510 "RECOVER DESTROY", false);
511 winAnimator.destroySurface();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800512 if (winAnimator.mWin.mAppToken != null
513 && winAnimator.mWin.mAppToken.getController() != null) {
514 winAnimator.mWin.mAppToken.getController().removeStartingWindow();
515 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700516 }
517
518 try {
519 winAnimator.mWin.mClient.dispatchGetNewSurface();
520 } catch (RemoteException e) {
521 }
522 }
523 } finally {
524 Binder.restoreCallingIdentity(callingIdentity);
525 }
526
527 return leakedSurface || killedApps;
528 }
529
530 // "Something has changed! Let's make it correct now."
531 // TODO: Super crazy long method that should be broken down...
532 void performSurfacePlacement(boolean recoveringMemory) {
533 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
534 + Debug.getCallers(3));
535
536 int i;
537 boolean updateInputWindowsNeeded = false;
538
539 if (mService.mFocusMayChange) {
540 mService.mFocusMayChange = false;
541 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
542 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
543 }
544
545 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700546 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700547 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700548 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800549 displayContent.setExitingTokensHasVisible(false);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700550 }
551
552 mHoldScreen = null;
553 mScreenBrightness = -1;
554 mButtonBrightness = -1;
555 mUserActivityTimeout = -1;
556 mObscureApplicationContentOnSecondaryDisplays = false;
557 mSustainedPerformanceModeCurrent = false;
558 mService.mTransactionSequence++;
559
560 // TODO(multi-display):
561 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
562 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
563 final int defaultDw = defaultInfo.logicalWidth;
564 final int defaultDh = defaultInfo.logicalHeight;
565
566 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
567 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
568 mService.openSurfaceTransaction();
569 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700570 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700571 } catch (RuntimeException e) {
572 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
573 } finally {
574 mService.closeSurfaceTransaction();
575 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
576 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
577 }
578
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700579 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
580
581 // If we are ready to perform an app transition, check through all of the app tokens to be
582 // shown and see if they are ready to go.
583 if (mService.mAppTransition.isReady()) {
584 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700585 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700586 if (DEBUG_LAYOUT_REPEATS)
587 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
588 defaultDisplay.pendingLayoutChanges);
589 }
590
591 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
592 // We have finished the animation of an app transition. To do this, we have delayed a
593 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
594 // token list reflects the correct Z-order, but the window list may now be out of sync
595 // with it. So here we will just rebuild the entire app window list. Fun!
596 defaultDisplay.pendingLayoutChanges |=
597 mService.handleAnimatingStoppedAndTransitionLocked();
598 if (DEBUG_LAYOUT_REPEATS)
599 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
600 defaultDisplay.pendingLayoutChanges);
601 }
602
603 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
604 && !mService.mAppTransition.isReady()) {
605 // At this point, there was a window with a wallpaper that was force hiding other
606 // windows behind it, but now it is going away. This may be simple -- just animate away
607 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
608 // shown behind something that was hidden.
609 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
610 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
611 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
612 }
613 mWallpaperForceHidingChanged = false;
614
615 if (mWallpaperMayChange) {
616 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
617 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
618 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
619 defaultDisplay.pendingLayoutChanges);
620 }
621
622 if (mService.mFocusMayChange) {
623 mService.mFocusMayChange = false;
624 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
625 false /*updateInputWindows*/)) {
626 updateInputWindowsNeeded = true;
627 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
628 }
629 }
630
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700631 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700632 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
633 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
634 defaultDisplay.pendingLayoutChanges);
635 }
636
637 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
638 WindowState win = mService.mResizingWindows.get(i);
639 if (win.mAppFreezing) {
640 // Don't remove this window until rotation has completed.
641 continue;
642 }
643 // Discard the saved surface if window size is changed, it can't be reused.
644 if (win.mAppToken != null) {
645 win.mAppToken.destroySavedSurfaces();
646 }
647 win.reportResized();
648 mService.mResizingWindows.remove(i);
649 }
650
651 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
652 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
653 if (mOrientationChangeComplete) {
654 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
655 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
656 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
657 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
658 }
659 mService.stopFreezingDisplayLocked();
660 }
661
662 // Destroy the surface of any windows that are no longer visible.
663 boolean wallpaperDestroyed = false;
664 i = mService.mDestroySurface.size();
665 if (i > 0) {
666 do {
667 i--;
668 WindowState win = mService.mDestroySurface.get(i);
669 win.mDestroying = false;
670 if (mService.mInputMethodWindow == win) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000671 mService.setInputMethodWindowLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700672 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700673 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700674 wallpaperDestroyed = true;
675 }
676 win.destroyOrSaveSurface();
677 } while (i > 0);
678 mService.mDestroySurface.clear();
679 }
680
681 // Time to remove any exiting tokens?
682 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700683 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800684 displayContent.removeExistingTokensIfPossible();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700685 }
686
687 if (wallpaperDestroyed) {
688 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700689 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700690 }
691
692 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700693 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700694 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700695 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700696 }
697 }
698
699 // Finally update all input windows now that the window changes have stabilized.
700 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
701
702 mService.setHoldScreenLocked(mHoldScreen);
703 if (!mService.mDisplayFrozen) {
704 if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) {
705 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
706 } else {
707 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
708 toBrightnessOverride(mScreenBrightness));
709 }
710 if (mButtonBrightness < 0 || mButtonBrightness > 1.0f) {
711 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
712 } else {
713 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
714 toBrightnessOverride(mButtonBrightness));
715 }
716 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
717 mUserActivityTimeout);
718 }
719
720 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
721 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
722 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700723 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700724 (mSustainedPerformanceModeEnabled ? 1 : 0));
725 }
726
727 if (mService.mTurnOnScreen) {
728 if (mService.mAllowTheaterModeWakeFromLayout
729 || Settings.Global.getInt(mService.mContext.getContentResolver(),
730 Settings.Global.THEATER_MODE_ON, 0) == 0) {
731 if (DEBUG_VISIBILITY || DEBUG_POWER) {
732 Slog.v(TAG, "Turning screen on after layout!");
733 }
734 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
735 "android.server.wm:TURN_ON");
736 }
737 mService.mTurnOnScreen = false;
738 }
739
740 if (mUpdateRotation) {
741 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700742 // TODO(multi-display): Update rotation for different displays separately.
743 final int displayId = defaultDisplay.getDisplayId();
744 if (mService.updateRotationUncheckedLocked(false, displayId)) {
745 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700746 } else {
747 mUpdateRotation = false;
748 }
749 }
750
751 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700752 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
753 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700754 mService.checkDrawnWindowsLocked();
755 }
756
757 final int N = mService.mPendingRemove.size();
758 if (N > 0) {
759 if (mService.mPendingRemoveTmp.length < N) {
760 mService.mPendingRemoveTmp = new WindowState[N+10];
761 }
762 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
763 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700764 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700765 for (i = 0; i < N; i++) {
766 final WindowState w = mService.mPendingRemoveTmp[i];
767 w.removeImmediately();
768 final DisplayContent displayContent = w.getDisplayContent();
769 if (displayContent != null && !displayList.contains(displayContent)) {
770 displayList.add(displayContent);
771 }
772 }
773
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700774 for (int j = displayList.size() - 1; j >= 0; --j) {
775 final DisplayContent dc = displayList.get(j);
776 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700777 }
778 }
779
780 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700781 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
782 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700783 }
784
785 if (updateInputWindowsNeeded) {
786 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
787 }
788 mService.setFocusTaskRegionLocked();
789
790 // Check to see if we are now in a state where the screen should
791 // be enabled, because the window obscured flags have changed.
792 mService.enableScreenIfNeededLocked();
793
794 mService.scheduleAnimationLocked();
795 mService.mWindowPlacerLocked.destroyPendingSurfaces();
796
797 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
798 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
799 }
800
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700801 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
802 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700803 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700804 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700805
806 if (mService.mWatermark != null) {
807 mService.mWatermark.positionSurface(defaultDw, defaultDh);
808 }
809 if (mService.mStrictModeFlash != null) {
810 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
811 }
812 if (mService.mCircularDisplayMask != null) {
813 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh, mService.mRotation);
814 }
815 if (mService.mEmulatorDisplayOverlay != null) {
816 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
817 mService.mRotation);
818 }
819
820 boolean focusDisplayed = false;
821
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700822 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700823 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700824 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700825 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700826 }
827
828 if (focusDisplayed) {
829 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
830 }
831
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700832 // Give the display manager a chance to adjust properties like display rotation if it needs
833 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700834 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
835 }
836
837 /**
838 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700839 * @param obscured True if there is a window on top of this obscuring the display.
840 * @param syswin System window?
841 * @return True when the display contains content to show the user. When false, the display
842 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700843 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700844 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700845 final WindowManager.LayoutParams attrs = w.mAttrs;
846 final int attrFlags = attrs.flags;
847 final boolean canBeSeen = w.isDisplayedLw();
848 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700849 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700850
851 if (w.mHasSurface && canBeSeen) {
852 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
853 mHoldScreen = w.mSession;
854 mHoldScreenWindow = w;
855 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
856 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
857 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
858 + Debug.getCallers(10));
859 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700860 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700861 mScreenBrightness = w.mAttrs.screenBrightness;
862 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700863 if (!syswin && w.mAttrs.buttonBrightness >= 0 && mButtonBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700864 mButtonBrightness = w.mAttrs.buttonBrightness;
865 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700866 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700867 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
868 }
869
870 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700871 // This function assumes that the contents of the default display are processed first
872 // before secondary displays.
873 final DisplayContent displayContent = w.getDisplayContent();
874 if (displayContent != null && displayContent.isDefaultDisplay) {
875 // While a dream or keyguard is showing, obscure ordinary application content on
876 // secondary displays (by forcibly enabling mirroring unless there is other content
877 // we want to show) but still allow opaque keyguard dialogs to be shown.
878 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
879 mObscureApplicationContentOnSecondaryDisplays = true;
880 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700881 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700882 } else if (displayContent != null &&
883 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700884 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700885 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700886 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700887 }
888 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
889 mSustainedPerformanceModeCurrent = true;
890 }
891 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700892
893 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700894 }
895
896 boolean copyAnimToLayoutParams() {
897 boolean doRequest = false;
898
899 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
900 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
901 mUpdateRotation = true;
902 doRequest = true;
903 }
904 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
905 mWallpaperMayChange = true;
906 doRequest = true;
907 }
908 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
909 mWallpaperForceHidingChanged = true;
910 doRequest = true;
911 }
912 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
913 mOrientationChangeComplete = false;
914 } else {
915 mOrientationChangeComplete = true;
916 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
917 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
918 doRequest = true;
919 }
920 }
921 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
922 mService.mTurnOnScreen = true;
923 }
924 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
925 mWallpaperActionPending = true;
926 }
927
928 return doRequest;
929 }
930
931 private static int toBrightnessOverride(float value) {
932 return (int)(value * PowerManager.BRIGHTNESS_ON);
933 }
934
935 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
936 final FileDescriptor fd = pfd.getFileDescriptor();
937 if (mSurfaceTraceEnabled) {
938 disableSurfaceTrace();
939 }
940 mSurfaceTraceEnabled = true;
941 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
942 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700943 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
944 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700945 dc.enableSurfaceTrace(fd);
946 }
947 }
948
949 void disableSurfaceTrace() {
950 mSurfaceTraceEnabled = false;
951 mRemoteEventTrace = null;
952 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700953 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
954 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700955 dc.disableSurfaceTrace();
956 }
957 }
958
959 void dumpDisplayContents(PrintWriter pw) {
960 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
961 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700962 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700963 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700964 final DisplayContent displayContent = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700965 displayContent.dump(" ", pw);
966 }
967 } else {
968 pw.println(" NO DISPLAY");
969 }
970 }
971
972 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700973 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700974 return;
975 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700976 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700977 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700978 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700979 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700980 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700981 pw.print(displayContent.getDisplayId());
982 }
983 }
984 pw.println();
985 }
986
987 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800988 final int[] index = new int[1];
989 forAllWindows((w) -> {
990 if (windows == null || windows.contains(w)) {
991 pw.println(" Window #" + index[0] + " " + w + ":");
992 w.dump(pw, " ", dumpAll || windows != null);
993 index[0] = index[0] + 1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700994 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800995 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700996 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700997
Wale Ogunwale02319a62016-09-26 15:21:22 -0700998 void dumpTokens(PrintWriter pw, boolean dumpAll) {
999 pw.println(" All tokens:");
1000 for (int i = mChildren.size() - 1; i >= 0; --i) {
1001 mChildren.get(i).dumpTokens(pw, dumpAll);
1002 }
1003 }
1004
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001005 @Override
1006 String getName() {
1007 return "ROOT";
1008 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001009}