blob: ee6d4ea24feae699bf726cffd84068f88278166b [file] [log] [blame]
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.server.wm;
18
Wale Ogunwalee05f5012016-09-16 16:27:29 -070019import android.content.res.Configuration;
20import android.graphics.Rect;
Ruchi Kandoi0d434042016-10-03 09:12:02 -070021import android.hardware.power.V1_0.PowerHint;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070022import android.os.Binder;
23import android.os.Debug;
Wale Ogunwale02319a62016-09-26 15:21:22 -070024import android.os.IBinder;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070025import android.os.ParcelFileDescriptor;
26import android.os.PowerManager;
27import android.os.RemoteException;
28import android.os.SystemClock;
29import android.os.UserHandle;
30import android.provider.Settings;
31import android.util.EventLog;
32import android.util.Slog;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070033import android.util.SparseIntArray;
34import android.view.Display;
35import android.view.DisplayInfo;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070036import android.view.WindowManager;
37import com.android.internal.util.ArrayUtils;
38import com.android.server.EventLogTags;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070039
40import java.io.FileDescriptor;
41import java.io.PrintWriter;
42import java.util.ArrayList;
43
Wale Ogunwalef7cab102016-10-25 15:25:14 -070044import static android.app.AppOpsManager.MODE_ALLOWED;
45import static android.app.AppOpsManager.MODE_DEFAULT;
46import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwale02319a62016-09-26 15:21:22 -070047import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070048import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070049import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070050import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
51import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
52import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070053import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070054import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
55import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi879ff722016-11-04 18:08:17 -070056
Wale Ogunwalee05f5012016-09-16 16:27:29 -070057import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
58import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
59import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070060import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
61import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
62import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070063import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
64import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
65import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
66import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
67import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
68import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
69import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
70import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
71import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
72import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070073import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
74import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070075import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
76import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
77import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
78import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
79import static com.android.server.wm.WindowManagerService.logSurface;
80import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
81import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
82import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
83import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
84import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
85import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
86
87/** Root {@link WindowContainer} for the device. */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -070088class RootWindowContainer extends WindowContainer<DisplayContent> {
Wale Ogunwalee05f5012016-09-16 16:27:29 -070089 private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM;
90
91 WindowManagerService mService;
92
Wale Ogunwalee05f5012016-09-16 16:27:29 -070093 private boolean mWallpaperForceHidingChanged = false;
94 private Object mLastWindowFreezeSource = null;
95 private Session mHoldScreen = null;
96 private float mScreenBrightness = -1;
97 private float mButtonBrightness = -1;
98 private long mUserActivityTimeout = -1;
99 private boolean mUpdateRotation = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700100 // Following variables are for debugging screen wakelock only.
101 // Last window that requires screen wakelock
102 WindowState mHoldScreenWindow = null;
103 // Last window that obscures all windows below
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700104 WindowState mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700105 // Only set while traversing the default display based on its content.
106 // Affects the behavior of mirroring on secondary displays.
107 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
108
109 private boolean mSustainedPerformanceModeEnabled = false;
110 private boolean mSustainedPerformanceModeCurrent = false;
111
112 boolean mWallpaperMayChange = false;
Robert Carr11c26c22016-09-23 12:40:27 -0700113 // During an orientation change, we track whether all windows have rendered
114 // at the new orientation, and this will be false from changing orientation until that occurs.
115 // For seamless rotation cases this always stays true, as the windows complete their orientation
116 // changes 1 by 1 without disturbing global state.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700117 boolean mOrientationChangeComplete = true;
118 boolean mWallpaperActionPending = false;
119
120 private final ArrayList<Integer> mChangedStackList = new ArrayList();
121
122 // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
123 // instances will be replaced with an instance that writes a binary representation of all
124 // commands to mSurfaceTraceFd.
125 boolean mSurfaceTraceEnabled;
126 ParcelFileDescriptor mSurfaceTraceFd;
127 RemoteEventTrace mRemoteEventTrace;
128
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700129 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700130 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700131
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700132 RootWindowContainer(WindowManagerService service) {
133 mService = service;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700134 mLayersController = new WindowLayersController(mService);
Wale Ogunwale0303c572016-10-20 10:16:29 -0700135 mWallpaperController = new WallpaperController(mService);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700136 }
137
138 WindowState computeFocusedWindow() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700139 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700140 for (int i = 0; i < count; i++) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700141 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700142 final WindowState win = dc.findFocusedWindow();
143 if (win != null) {
144 return win;
145 }
146 }
147 return null;
148 }
149
150 /**
151 * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
152 * there is a Display for the displayId.
153 *
154 * @param displayId The display the caller is interested in.
155 * @return The DisplayContent associated with displayId or null if there is no Display for it.
156 */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700157 DisplayContent getDisplayContentOrCreate(int displayId) {
158 DisplayContent dc = getDisplayContent(displayId);
159
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700160 if (dc == null) {
161 final Display display = mService.mDisplayManager.getDisplay(displayId);
162 if (display != null) {
163 dc = createDisplayContent(display);
164 }
165 }
166 return dc;
167 }
168
Wale Ogunwale02319a62016-09-26 15:21:22 -0700169 DisplayContent getDisplayContent(int displayId) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700170 for (int i = mChildren.size() - 1; i >= 0; --i) {
171 final DisplayContent current = mChildren.get(i);
172 if (current.getDisplayId() == displayId) {
173 return current;
174 }
175 }
176 return null;
177 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700178
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700179 private DisplayContent createDisplayContent(final Display display) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700180 final DisplayContent dc = new DisplayContent(display, mService, mLayersController,
181 mWallpaperController);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700182 final int displayId = display.getDisplayId();
183
184 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
185 addChild(dc, null);
186
187 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700188 final Rect rect = new Rect();
189 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
190 displayInfo.overscanLeft = rect.left;
191 displayInfo.overscanTop = rect.top;
192 displayInfo.overscanRight = rect.right;
193 displayInfo.overscanBottom = rect.bottom;
194 if (mService.mDisplayManagerInternal != null) {
195 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
196 displayId, displayInfo);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700197 mService.configureDisplayPolicyLocked(dc);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700198
199 // TODO(multi-display): Create an input channel for each display with touch capability.
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700200 if (displayId == DEFAULT_DISPLAY) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700201 dc.mTapDetector = new TaskTapPointerEventListener(
202 mService, dc);
203 mService.registerPointerEventListener(dc.mTapDetector);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700204 mService.registerPointerEventListener(mService.mMousePositionTracker);
205 }
206 }
207
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700208 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700209 }
210
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700211 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700212 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700213 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700214 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700215 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700216 return true;
217 }
218 }
219 return false;
220 }
221
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000222 void getWindowsByName(ArrayList<WindowState> output, String name) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700223 int objectId = 0;
224 // See if this is an object ID.
225 try {
226 objectId = Integer.parseInt(name, 16);
227 name = null;
228 } catch (RuntimeException e) {
229 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800230
231 getWindowsByName(output, name, objectId);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700232 }
233
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000234 private void getWindowsByName(ArrayList<WindowState> output, String name, int objectId) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800235 forAllWindows((w) -> {
236 if (name != null) {
237 if (w.mAttrs.getTitle().toString().contains(name)) {
238 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700239 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800240 } else if (System.identityHashCode(w) == objectId) {
241 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700242 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800243 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700244 }
245
Wale Ogunwale02319a62016-09-26 15:21:22 -0700246 /**
247 * Returns the app window token for the input binder if it exist in the system.
248 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
249 * AppWindowToken represents an activity which can only exist on one display.
250 */
251 AppWindowToken getAppWindowToken(IBinder binder) {
252 for (int i = mChildren.size() - 1; i >= 0; --i) {
253 final DisplayContent dc = mChildren.get(i);
254 final AppWindowToken atoken = dc.getAppWindowToken(binder);
255 if (atoken != null) {
256 return atoken;
257 }
258 }
259 return null;
260 }
261
262 /** Returns the display object the input window token is currently mapped on. */
263 DisplayContent getWindowTokenDisplay(WindowToken token) {
264 if (token == null) {
265 return null;
266 }
267
268 for (int i = mChildren.size() - 1; i >= 0; --i) {
269 final DisplayContent dc = mChildren.get(i);
270 final WindowToken current = dc.getWindowToken(token.token);
271 if (current == token) {
272 return dc;
273 }
274 }
275
276 return null;
277 }
278
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700279 /**
280 * Set new display override config and return array of ids of stacks that were changed during
281 * update. If called for the default display, global configuration will also be updated.
282 */
283 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
284 final DisplayContent displayContent = getDisplayContent(displayId);
285 if (displayContent == null) {
286 throw new IllegalArgumentException("Display not found for id: " + displayId);
287 }
288
289 final Configuration currentConfig = displayContent.getOverrideConfiguration();
290 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
291 if (!configChanged) {
292 return null;
293 }
294 displayContent.onOverrideConfigurationChanged(currentConfig);
295
296 if (displayId == DEFAULT_DISPLAY) {
297 // Override configuration of the default display duplicates global config. In this case
298 // we also want to update the global config.
299 return setGlobalConfigurationIfNeeded(newConfiguration);
300 } else {
301 return updateStackBoundsAfterConfigChange(displayId);
302 }
303 }
304
305 private int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700306 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
307 if (!configChanged) {
308 return null;
309 }
310 onConfigurationChanged(newConfiguration);
311 return updateStackBoundsAfterConfigChange();
312 }
313
314 @Override
315 void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700316 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700317 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700318
319 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700320 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700321
Andrii Kulian441e4492016-09-29 15:25:00 -0700322 /**
323 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
324 * bounds were updated.
325 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700326 private int[] updateStackBoundsAfterConfigChange() {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700327 mChangedStackList.clear();
328
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700329 final int numDisplays = mChildren.size();
330 for (int i = 0; i < numDisplays; ++i) {
331 final DisplayContent dc = mChildren.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700332 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700333 }
334
335 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
336 }
337
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700338 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
339 private int[] updateStackBoundsAfterConfigChange(int displayId) {
340 mChangedStackList.clear();
341
342 final DisplayContent dc = getDisplayContent(displayId);
343 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
344
345 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
346 }
347
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700348 private void prepareFreezingTaskBounds() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700349 for (int i = mChildren.size() - 1; i >= 0; i--) {
350 mChildren.get(i).prepareFreezingTaskBounds();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700351 }
352 }
353
354 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800355 forAllWindows((w) -> {
356 if (w.mHasSurface && userId == UserHandle.getUserId(w.mOwnerUid)) {
357 w.mWinAnimator.setSecureLocked(disabled);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700358 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800359 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700360 }
361
362 void updateAppOpsState() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800363 forAllWindows((w) -> {
364 if (w.mAppOp == OP_NONE) {
365 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700366 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800367 final int mode = mService.mAppOps.checkOpNoThrow(w.mAppOp, w.getOwningUid(),
368 w.getOwningPackage());
369 w.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
370 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700371 }
372
373 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800374 final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw());
375 return win != null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700376 }
377
378 void closeSystemDialogs(String reason) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800379 forAllWindows((w) -> {
380 if (w.mHasSurface) {
381 try {
382 w.mClient.closeSystemDialogs(reason);
383 } catch (RemoteException e) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700384 }
385 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800386 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700387 }
388
389 void removeReplacedWindows() {
390 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
391 mService.openSurfaceTransaction();
392 try {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800393 forAllWindows((w) -> {
394 final AppWindowToken aToken = w.mAppToken;
395 if (aToken != null) {
396 aToken.removeReplacedWindowIfNeeded(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700397 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800398 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700399 } finally {
400 mService.closeSurfaceTransaction();
401 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
402 }
403 }
404
405 boolean hasPendingLayoutChanges(WindowAnimator animator) {
406 boolean hasChanges = false;
407
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700408 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700409 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700410 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700411 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
412 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
413 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
414 }
415 if (pendingChanges != 0) {
416 hasChanges = true;
417 }
418 }
419
420 return hasChanges;
421 }
422
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700423 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
424 boolean secure) {
425 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
426 boolean leakedSurface = false;
427 boolean killedApps = false;
428
429 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
430 winAnimator.mSession.mPid, operation);
431
432 final long callingIdentity = Binder.clearCallingIdentity();
433 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700434 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700435 // we haven't left any dangling surfaces around.
436
437 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700438 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700439 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700440 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700441 }
442
443 if (!leakedSurface) {
444 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700445 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700446 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800447 mChildren.get(displayNdx).forAllWindows((w) -> {
448 if (mService.mForceRemoves.contains(w)) {
449 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700450 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800451 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700452 if (wsa.mSurfaceController != null) {
453 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
454 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800455 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700456
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700457 if (pidCandidates.size() > 0) {
458 int[] pids = new int[pidCandidates.size()];
459 for (int i = 0; i < pids.length; i++) {
460 pids[i] = pidCandidates.keyAt(i);
461 }
462 try {
463 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
464 killedApps = true;
465 }
466 } catch (RemoteException e) {
467 }
468 }
469 }
470 }
471
472 if (leakedSurface || killedApps) {
473 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
474 // app to request another one.
475 Slog.w(TAG_WM,
476 "Looks like we have reclaimed some memory, clearing surface for retry.");
477 if (surfaceController != null) {
478 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
479 "RECOVER DESTROY", false);
480 winAnimator.destroySurface();
481 mService.scheduleRemoveStartingWindowLocked(winAnimator.mWin.mAppToken);
482 }
483
484 try {
485 winAnimator.mWin.mClient.dispatchGetNewSurface();
486 } catch (RemoteException e) {
487 }
488 }
489 } finally {
490 Binder.restoreCallingIdentity(callingIdentity);
491 }
492
493 return leakedSurface || killedApps;
494 }
495
496 // "Something has changed! Let's make it correct now."
497 // TODO: Super crazy long method that should be broken down...
498 void performSurfacePlacement(boolean recoveringMemory) {
499 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
500 + Debug.getCallers(3));
501
502 int i;
503 boolean updateInputWindowsNeeded = false;
504
505 if (mService.mFocusMayChange) {
506 mService.mFocusMayChange = false;
507 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
508 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
509 }
510
511 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700512 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700513 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700514 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700515 for (i = displayContent.mExitingTokens.size() - 1; i >= 0; i--) {
516 displayContent.mExitingTokens.get(i).hasVisible = false;
517 }
518 }
519
520 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
521 // Initialize state of exiting applications.
522 final AppTokenList exitingAppTokens =
523 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
524 for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
525 exitingAppTokens.get(tokenNdx).hasVisible = false;
526 }
527 }
528
529 mHoldScreen = null;
530 mScreenBrightness = -1;
531 mButtonBrightness = -1;
532 mUserActivityTimeout = -1;
533 mObscureApplicationContentOnSecondaryDisplays = false;
534 mSustainedPerformanceModeCurrent = false;
535 mService.mTransactionSequence++;
536
537 // TODO(multi-display):
538 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
539 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
540 final int defaultDw = defaultInfo.logicalWidth;
541 final int defaultDh = defaultInfo.logicalHeight;
542
543 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
544 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
545 mService.openSurfaceTransaction();
546 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700547 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700548 } catch (RuntimeException e) {
549 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
550 } finally {
551 mService.closeSurfaceTransaction();
552 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
553 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
554 }
555
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700556 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
557
558 // If we are ready to perform an app transition, check through all of the app tokens to be
559 // shown and see if they are ready to go.
560 if (mService.mAppTransition.isReady()) {
561 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700562 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700563 if (DEBUG_LAYOUT_REPEATS)
564 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
565 defaultDisplay.pendingLayoutChanges);
566 }
567
568 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
569 // We have finished the animation of an app transition. To do this, we have delayed a
570 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
571 // token list reflects the correct Z-order, but the window list may now be out of sync
572 // with it. So here we will just rebuild the entire app window list. Fun!
573 defaultDisplay.pendingLayoutChanges |=
574 mService.handleAnimatingStoppedAndTransitionLocked();
575 if (DEBUG_LAYOUT_REPEATS)
576 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
577 defaultDisplay.pendingLayoutChanges);
578 }
579
580 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
581 && !mService.mAppTransition.isReady()) {
582 // At this point, there was a window with a wallpaper that was force hiding other
583 // windows behind it, but now it is going away. This may be simple -- just animate away
584 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
585 // shown behind something that was hidden.
586 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
587 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
588 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
589 }
590 mWallpaperForceHidingChanged = false;
591
592 if (mWallpaperMayChange) {
593 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
594 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
595 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
596 defaultDisplay.pendingLayoutChanges);
597 }
598
599 if (mService.mFocusMayChange) {
600 mService.mFocusMayChange = false;
601 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
602 false /*updateInputWindows*/)) {
603 updateInputWindowsNeeded = true;
604 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
605 }
606 }
607
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700608 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700609 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
610 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
611 defaultDisplay.pendingLayoutChanges);
612 }
613
614 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
615 WindowState win = mService.mResizingWindows.get(i);
616 if (win.mAppFreezing) {
617 // Don't remove this window until rotation has completed.
618 continue;
619 }
620 // Discard the saved surface if window size is changed, it can't be reused.
621 if (win.mAppToken != null) {
622 win.mAppToken.destroySavedSurfaces();
623 }
624 win.reportResized();
625 mService.mResizingWindows.remove(i);
626 }
627
628 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
629 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
630 if (mOrientationChangeComplete) {
631 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
632 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
633 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
634 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
635 }
636 mService.stopFreezingDisplayLocked();
637 }
638
639 // Destroy the surface of any windows that are no longer visible.
640 boolean wallpaperDestroyed = false;
641 i = mService.mDestroySurface.size();
642 if (i > 0) {
643 do {
644 i--;
645 WindowState win = mService.mDestroySurface.get(i);
646 win.mDestroying = false;
647 if (mService.mInputMethodWindow == win) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000648 mService.setInputMethodWindowLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700649 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700650 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700651 wallpaperDestroyed = true;
652 }
653 win.destroyOrSaveSurface();
654 } while (i > 0);
655 mService.mDestroySurface.clear();
656 }
657
658 // Time to remove any exiting tokens?
659 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700660 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700661 ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens;
662 for (i = exitingTokens.size() - 1; i >= 0; i--) {
663 WindowToken token = exitingTokens.get(i);
664 if (!token.hasVisible) {
665 exitingTokens.remove(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700666 }
667 }
668 }
669
670 // Time to remove any exiting applications?
671 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
672 // Initialize state of exiting applications.
673 final AppTokenList exitingAppTokens =
674 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
675 for (i = exitingAppTokens.size() - 1; i >= 0; i--) {
676 final AppWindowToken token = exitingAppTokens.get(i);
677 if (!token.hasVisible && !mService.mClosingApps.contains(token) &&
678 (!token.mIsExiting || token.isEmpty())) {
679 // Make sure there is no animation running on this token, so any windows
680 // associated with it will be removed as soon as their animations are complete
681 token.mAppAnimator.clearAnimation();
682 token.mAppAnimator.animating = false;
683 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
684 "performLayout: App token exiting now removed" + token);
685 token.removeIfPossible();
686 }
687 }
688 }
689
690 if (wallpaperDestroyed) {
691 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700692 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700693 }
694
695 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700696 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700697 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700698 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700699 }
700 }
701
702 // Finally update all input windows now that the window changes have stabilized.
703 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
704
705 mService.setHoldScreenLocked(mHoldScreen);
706 if (!mService.mDisplayFrozen) {
707 if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) {
708 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
709 } else {
710 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
711 toBrightnessOverride(mScreenBrightness));
712 }
713 if (mButtonBrightness < 0 || mButtonBrightness > 1.0f) {
714 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
715 } else {
716 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
717 toBrightnessOverride(mButtonBrightness));
718 }
719 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
720 mUserActivityTimeout);
721 }
722
723 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
724 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
725 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700726 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700727 (mSustainedPerformanceModeEnabled ? 1 : 0));
728 }
729
730 if (mService.mTurnOnScreen) {
731 if (mService.mAllowTheaterModeWakeFromLayout
732 || Settings.Global.getInt(mService.mContext.getContentResolver(),
733 Settings.Global.THEATER_MODE_ON, 0) == 0) {
734 if (DEBUG_VISIBILITY || DEBUG_POWER) {
735 Slog.v(TAG, "Turning screen on after layout!");
736 }
737 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
738 "android.server.wm:TURN_ON");
739 }
740 mService.mTurnOnScreen = false;
741 }
742
743 if (mUpdateRotation) {
744 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700745 // TODO(multi-display): Update rotation for different displays separately.
746 final int displayId = defaultDisplay.getDisplayId();
747 if (mService.updateRotationUncheckedLocked(false, displayId)) {
748 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700749 } else {
750 mUpdateRotation = false;
751 }
752 }
753
754 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700755 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
756 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700757 mService.checkDrawnWindowsLocked();
758 }
759
760 final int N = mService.mPendingRemove.size();
761 if (N > 0) {
762 if (mService.mPendingRemoveTmp.length < N) {
763 mService.mPendingRemoveTmp = new WindowState[N+10];
764 }
765 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
766 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700767 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700768 for (i = 0; i < N; i++) {
769 final WindowState w = mService.mPendingRemoveTmp[i];
770 w.removeImmediately();
771 final DisplayContent displayContent = w.getDisplayContent();
772 if (displayContent != null && !displayList.contains(displayContent)) {
773 displayList.add(displayContent);
774 }
775 }
776
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700777 for (int j = displayList.size() - 1; j >= 0; --j) {
778 final DisplayContent dc = displayList.get(j);
779 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700780 }
781 }
782
783 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700784 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
785 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700786 }
787
788 if (updateInputWindowsNeeded) {
789 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
790 }
791 mService.setFocusTaskRegionLocked();
792
793 // Check to see if we are now in a state where the screen should
794 // be enabled, because the window obscured flags have changed.
795 mService.enableScreenIfNeededLocked();
796
797 mService.scheduleAnimationLocked();
798 mService.mWindowPlacerLocked.destroyPendingSurfaces();
799
800 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
801 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
802 }
803
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700804 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
805 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700806 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700807 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700808
809 if (mService.mWatermark != null) {
810 mService.mWatermark.positionSurface(defaultDw, defaultDh);
811 }
812 if (mService.mStrictModeFlash != null) {
813 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
814 }
815 if (mService.mCircularDisplayMask != null) {
816 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh, mService.mRotation);
817 }
818 if (mService.mEmulatorDisplayOverlay != null) {
819 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
820 mService.mRotation);
821 }
822
823 boolean focusDisplayed = false;
824
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700825 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700826 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700827 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700828 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700829 }
830
831 if (focusDisplayed) {
832 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
833 }
834
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700835 // Give the display manager a chance to adjust properties like display rotation if it needs
836 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700837 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
838 }
839
840 /**
841 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700842 * @param obscured True if there is a window on top of this obscuring the display.
843 * @param syswin System window?
844 * @return True when the display contains content to show the user. When false, the display
845 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700846 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700847 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700848 final WindowManager.LayoutParams attrs = w.mAttrs;
849 final int attrFlags = attrs.flags;
850 final boolean canBeSeen = w.isDisplayedLw();
851 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700852 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700853
854 if (w.mHasSurface && canBeSeen) {
855 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
856 mHoldScreen = w.mSession;
857 mHoldScreenWindow = w;
858 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
859 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
860 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
861 + Debug.getCallers(10));
862 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700863 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700864 mScreenBrightness = w.mAttrs.screenBrightness;
865 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700866 if (!syswin && w.mAttrs.buttonBrightness >= 0 && mButtonBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700867 mButtonBrightness = w.mAttrs.buttonBrightness;
868 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700869 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700870 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
871 }
872
873 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700874 // This function assumes that the contents of the default display are processed first
875 // before secondary displays.
876 final DisplayContent displayContent = w.getDisplayContent();
877 if (displayContent != null && displayContent.isDefaultDisplay) {
878 // While a dream or keyguard is showing, obscure ordinary application content on
879 // secondary displays (by forcibly enabling mirroring unless there is other content
880 // we want to show) but still allow opaque keyguard dialogs to be shown.
881 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
882 mObscureApplicationContentOnSecondaryDisplays = true;
883 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700884 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700885 } else if (displayContent != null &&
886 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700887 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700888 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700889 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700890 }
891 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
892 mSustainedPerformanceModeCurrent = true;
893 }
894 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700895
896 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700897 }
898
899 boolean copyAnimToLayoutParams() {
900 boolean doRequest = false;
901
902 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
903 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
904 mUpdateRotation = true;
905 doRequest = true;
906 }
907 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
908 mWallpaperMayChange = true;
909 doRequest = true;
910 }
911 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
912 mWallpaperForceHidingChanged = true;
913 doRequest = true;
914 }
915 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
916 mOrientationChangeComplete = false;
917 } else {
918 mOrientationChangeComplete = true;
919 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
920 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
921 doRequest = true;
922 }
923 }
924 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
925 mService.mTurnOnScreen = true;
926 }
927 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
928 mWallpaperActionPending = true;
929 }
930
931 return doRequest;
932 }
933
934 private static int toBrightnessOverride(float value) {
935 return (int)(value * PowerManager.BRIGHTNESS_ON);
936 }
937
938 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
939 final FileDescriptor fd = pfd.getFileDescriptor();
940 if (mSurfaceTraceEnabled) {
941 disableSurfaceTrace();
942 }
943 mSurfaceTraceEnabled = true;
944 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
945 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700946 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
947 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700948 dc.enableSurfaceTrace(fd);
949 }
950 }
951
952 void disableSurfaceTrace() {
953 mSurfaceTraceEnabled = false;
954 mRemoteEventTrace = null;
955 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700956 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
957 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700958 dc.disableSurfaceTrace();
959 }
960 }
961
962 void dumpDisplayContents(PrintWriter pw) {
963 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
964 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700965 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700966 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700967 final DisplayContent displayContent = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700968 displayContent.dump(" ", pw);
969 }
970 } else {
971 pw.println(" NO DISPLAY");
972 }
973 }
974
975 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700976 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700977 return;
978 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700979 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700980 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700981 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700982 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700983 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700984 pw.print(displayContent.getDisplayId());
985 }
986 }
987 pw.println();
988 }
989
990 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800991 final int[] index = new int[1];
992 forAllWindows((w) -> {
993 if (windows == null || windows.contains(w)) {
994 pw.println(" Window #" + index[0] + " " + w + ":");
995 w.dump(pw, " ", dumpAll || windows != null);
996 index[0] = index[0] + 1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700997 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800998 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700999 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001000
Wale Ogunwale02319a62016-09-26 15:21:22 -07001001 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1002 pw.println(" All tokens:");
1003 for (int i = mChildren.size() - 1; i >= 0; --i) {
1004 mChildren.get(i).dumpTokens(pw, dumpAll);
1005 }
1006 }
1007
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001008 @Override
1009 String getName() {
1010 return "ROOT";
1011 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001012}