blob: b0e3e3221415215bfc2d580148e63097eb9e3faf [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_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_VISIBILITY;
64import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
65import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
66import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
67import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
68import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
69import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
70import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
71import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070072import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
73import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070074import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
75import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
76import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
77import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
78import static com.android.server.wm.WindowManagerService.logSurface;
79import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
80import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
81import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
82import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
83import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
84import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
85
86/** Root {@link WindowContainer} for the device. */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -070087class RootWindowContainer extends WindowContainer<DisplayContent> {
Wale Ogunwalee05f5012016-09-16 16:27:29 -070088 private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM;
89
90 WindowManagerService mService;
91
Wale Ogunwalee05f5012016-09-16 16:27:29 -070092 private boolean mWallpaperForceHidingChanged = false;
93 private Object mLastWindowFreezeSource = null;
94 private Session mHoldScreen = null;
95 private float mScreenBrightness = -1;
96 private float mButtonBrightness = -1;
97 private long mUserActivityTimeout = -1;
98 private boolean mUpdateRotation = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070099 // Following variables are for debugging screen wakelock only.
100 // Last window that requires screen wakelock
101 WindowState mHoldScreenWindow = null;
102 // Last window that obscures all windows below
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700103 WindowState mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700104 // Only set while traversing the default display based on its content.
105 // Affects the behavior of mirroring on secondary displays.
106 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
107
108 private boolean mSustainedPerformanceModeEnabled = false;
109 private boolean mSustainedPerformanceModeCurrent = false;
110
111 boolean mWallpaperMayChange = false;
Robert Carr11c26c22016-09-23 12:40:27 -0700112 // During an orientation change, we track whether all windows have rendered
113 // at the new orientation, and this will be false from changing orientation until that occurs.
114 // For seamless rotation cases this always stays true, as the windows complete their orientation
115 // changes 1 by 1 without disturbing global state.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700116 boolean mOrientationChangeComplete = true;
117 boolean mWallpaperActionPending = false;
118
119 private final ArrayList<Integer> mChangedStackList = new ArrayList();
120
121 // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
122 // instances will be replaced with an instance that writes a binary representation of all
123 // commands to mSurfaceTraceFd.
124 boolean mSurfaceTraceEnabled;
125 ParcelFileDescriptor mSurfaceTraceFd;
126 RemoteEventTrace mRemoteEventTrace;
127
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700128 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700129 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700130
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800131 private String mCloseSystemDialogsReason;
132 private final Consumer<WindowState> mCloseSystemDialogsConsumer = w -> {
133 if (w.mHasSurface) {
134 try {
135 w.mClient.closeSystemDialogs(mCloseSystemDialogsReason);
136 } catch (RemoteException e) {
137 }
138 }
139 };
140
141 private static final Consumer<WindowState> sRemoveReplacedWindowsConsumer = w -> {
142 final AppWindowToken aToken = w.mAppToken;
143 if (aToken != null) {
144 aToken.removeReplacedWindowIfNeeded(w);
145 }
146 };
147
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700148 RootWindowContainer(WindowManagerService service) {
149 mService = service;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700150 mLayersController = new WindowLayersController(mService);
Wale Ogunwale0303c572016-10-20 10:16:29 -0700151 mWallpaperController = new WallpaperController(mService);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700152 }
153
154 WindowState computeFocusedWindow() {
David Stevens46939562017-03-24 13:04:00 -0700155 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700156 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700157 final WindowState win = dc.findFocusedWindow();
158 if (win != null) {
159 return win;
160 }
161 }
162 return null;
163 }
164
165 /**
Andrii Kulian7fc22812016-12-28 13:04:11 -0800166 * Get an array with display ids ordered by focus priority - last items should be given
167 * focus first. Sparse array just maps position to displayId.
168 */
169 void getDisplaysInFocusOrder(SparseIntArray displaysInFocusOrder) {
170 displaysInFocusOrder.clear();
171
172 final int size = mChildren.size();
173 for (int i = 0; i < size; ++i) {
174 displaysInFocusOrder.put(i, mChildren.get(i).getDisplayId());
175 }
176 }
177
178 /**
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700179 * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
180 * there is a Display for the displayId.
181 *
182 * @param displayId The display the caller is interested in.
183 * @return The DisplayContent associated with displayId or null if there is no Display for it.
184 */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700185 DisplayContent getDisplayContentOrCreate(int displayId) {
186 DisplayContent dc = getDisplayContent(displayId);
187
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700188 if (dc == null) {
189 final Display display = mService.mDisplayManager.getDisplay(displayId);
190 if (display != null) {
191 dc = createDisplayContent(display);
192 }
193 }
194 return dc;
195 }
196
Wale Ogunwale02319a62016-09-26 15:21:22 -0700197 DisplayContent getDisplayContent(int displayId) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700198 for (int i = mChildren.size() - 1; i >= 0; --i) {
199 final DisplayContent current = mChildren.get(i);
200 if (current.getDisplayId() == displayId) {
201 return current;
202 }
203 }
204 return null;
205 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700206
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700207 private DisplayContent createDisplayContent(final Display display) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700208 final DisplayContent dc = new DisplayContent(display, mService, mLayersController,
209 mWallpaperController);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700210 final int displayId = display.getDisplayId();
211
212 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700213
214 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700215 final Rect rect = new Rect();
216 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
217 displayInfo.overscanLeft = rect.left;
218 displayInfo.overscanTop = rect.top;
219 displayInfo.overscanRight = rect.right;
220 displayInfo.overscanBottom = rect.bottom;
221 if (mService.mDisplayManagerInternal != null) {
222 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
223 displayId, displayInfo);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700224 mService.configureDisplayPolicyLocked(dc);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700225
226 // TODO(multi-display): Create an input channel for each display with touch capability.
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800227 if (displayId == DEFAULT_DISPLAY && mService.canDispatchPointerEvents()) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700228 dc.mTapDetector = new TaskTapPointerEventListener(
229 mService, dc);
230 mService.registerPointerEventListener(dc.mTapDetector);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700231 mService.registerPointerEventListener(mService.mMousePositionTracker);
232 }
233 }
234
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700235 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700236 }
237
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700238 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700239 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700240 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700241 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700242 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700243 return true;
244 }
245 }
246 return false;
247 }
248
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000249 void getWindowsByName(ArrayList<WindowState> output, String name) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700250 int objectId = 0;
251 // See if this is an object ID.
252 try {
253 objectId = Integer.parseInt(name, 16);
254 name = null;
255 } catch (RuntimeException e) {
256 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800257
258 getWindowsByName(output, name, objectId);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700259 }
260
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000261 private void getWindowsByName(ArrayList<WindowState> output, String name, int objectId) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800262 forAllWindows((w) -> {
263 if (name != null) {
264 if (w.mAttrs.getTitle().toString().contains(name)) {
265 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700266 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800267 } else if (System.identityHashCode(w) == objectId) {
268 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700269 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800270 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700271 }
272
Wale Ogunwale02319a62016-09-26 15:21:22 -0700273 /**
274 * Returns the app window token for the input binder if it exist in the system.
275 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
276 * AppWindowToken represents an activity which can only exist on one display.
277 */
278 AppWindowToken getAppWindowToken(IBinder binder) {
279 for (int i = mChildren.size() - 1; i >= 0; --i) {
280 final DisplayContent dc = mChildren.get(i);
281 final AppWindowToken atoken = dc.getAppWindowToken(binder);
282 if (atoken != null) {
283 return atoken;
284 }
285 }
286 return null;
287 }
288
289 /** Returns the display object the input window token is currently mapped on. */
290 DisplayContent getWindowTokenDisplay(WindowToken token) {
291 if (token == null) {
292 return null;
293 }
294
295 for (int i = mChildren.size() - 1; i >= 0; --i) {
296 final DisplayContent dc = mChildren.get(i);
297 final WindowToken current = dc.getWindowToken(token.token);
298 if (current == token) {
299 return dc;
300 }
301 }
302
303 return null;
304 }
305
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700306 /**
307 * Set new display override config and return array of ids of stacks that were changed during
308 * update. If called for the default display, global configuration will also be updated.
309 */
310 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
311 final DisplayContent displayContent = getDisplayContent(displayId);
312 if (displayContent == null) {
313 throw new IllegalArgumentException("Display not found for id: " + displayId);
314 }
315
316 final Configuration currentConfig = displayContent.getOverrideConfiguration();
317 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
318 if (!configChanged) {
319 return null;
320 }
Andrii Kuliand68501e2017-01-10 22:57:27 -0800321 displayContent.onOverrideConfigurationChanged(newConfiguration);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700322
323 if (displayId == DEFAULT_DISPLAY) {
324 // Override configuration of the default display duplicates global config. In this case
325 // we also want to update the global config.
326 return setGlobalConfigurationIfNeeded(newConfiguration);
327 } else {
328 return updateStackBoundsAfterConfigChange(displayId);
329 }
330 }
331
332 private int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700333 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
334 if (!configChanged) {
335 return null;
336 }
337 onConfigurationChanged(newConfiguration);
338 return updateStackBoundsAfterConfigChange();
339 }
340
341 @Override
342 void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700343 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700344 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700345
346 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700347 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700348
Andrii Kulian441e4492016-09-29 15:25:00 -0700349 /**
350 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
351 * bounds were updated.
352 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700353 private int[] updateStackBoundsAfterConfigChange() {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700354 mChangedStackList.clear();
355
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700356 final int numDisplays = mChildren.size();
357 for (int i = 0; i < numDisplays; ++i) {
358 final DisplayContent dc = mChildren.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700359 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700360 }
361
362 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
363 }
364
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700365 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
366 private int[] updateStackBoundsAfterConfigChange(int displayId) {
367 mChangedStackList.clear();
368
369 final DisplayContent dc = getDisplayContent(displayId);
370 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
371
372 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
373 }
374
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700375 private void prepareFreezingTaskBounds() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700376 for (int i = mChildren.size() - 1; i >= 0; i--) {
377 mChildren.get(i).prepareFreezingTaskBounds();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700378 }
379 }
380
Wale Ogunwale1666e312016-12-16 11:27:18 -0800381 TaskStack getStackById(int stackId) {
382 for (int i = mChildren.size() - 1; i >= 0; i--) {
383 final DisplayContent dc = mChildren.get(i);
384 final TaskStack stack = dc.getStackById(stackId);
385 if (stack != null) {
386 return stack;
387 }
388 }
389 return null;
390 }
391
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700392 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800393 forAllWindows((w) -> {
394 if (w.mHasSurface && userId == UserHandle.getUserId(w.mOwnerUid)) {
395 w.mWinAnimator.setSecureLocked(disabled);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700396 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800397 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700398 }
399
400 void updateAppOpsState() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800401 forAllWindows((w) -> {
402 if (w.mAppOp == OP_NONE) {
403 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700404 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800405 final int mode = mService.mAppOps.checkOpNoThrow(w.mAppOp, w.getOwningUid(),
406 w.getOwningPackage());
407 w.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
408 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700409 }
410
411 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800412 final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw());
413 return win != null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700414 }
415
416 void closeSystemDialogs(String reason) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800417 mCloseSystemDialogsReason = reason;
418 forAllWindows(mCloseSystemDialogsConsumer, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700419 }
420
421 void removeReplacedWindows() {
422 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
423 mService.openSurfaceTransaction();
424 try {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800425 forAllWindows(sRemoveReplacedWindowsConsumer, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700426 } finally {
427 mService.closeSurfaceTransaction();
428 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
429 }
430 }
431
432 boolean hasPendingLayoutChanges(WindowAnimator animator) {
433 boolean hasChanges = false;
434
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700435 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700436 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700437 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700438 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
439 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
440 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
441 }
442 if (pendingChanges != 0) {
443 hasChanges = true;
444 }
445 }
446
447 return hasChanges;
448 }
449
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700450 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
451 boolean secure) {
452 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
453 boolean leakedSurface = false;
454 boolean killedApps = false;
455
456 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
457 winAnimator.mSession.mPid, operation);
458
459 final long callingIdentity = Binder.clearCallingIdentity();
460 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700461 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700462 // we haven't left any dangling surfaces around.
463
464 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700465 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700466 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700467 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700468 }
469
470 if (!leakedSurface) {
471 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700472 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700473 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800474 mChildren.get(displayNdx).forAllWindows((w) -> {
475 if (mService.mForceRemoves.contains(w)) {
476 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700477 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800478 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700479 if (wsa.mSurfaceController != null) {
480 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
481 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800482 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700483
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700484 if (pidCandidates.size() > 0) {
485 int[] pids = new int[pidCandidates.size()];
486 for (int i = 0; i < pids.length; i++) {
487 pids[i] = pidCandidates.keyAt(i);
488 }
489 try {
490 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
491 killedApps = true;
492 }
493 } catch (RemoteException e) {
494 }
495 }
496 }
497 }
498
499 if (leakedSurface || killedApps) {
500 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
501 // app to request another one.
502 Slog.w(TAG_WM,
503 "Looks like we have reclaimed some memory, clearing surface for retry.");
504 if (surfaceController != null) {
505 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
506 "RECOVER DESTROY", false);
507 winAnimator.destroySurface();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800508 if (winAnimator.mWin.mAppToken != null
509 && winAnimator.mWin.mAppToken.getController() != null) {
510 winAnimator.mWin.mAppToken.getController().removeStartingWindow();
511 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700512 }
513
514 try {
515 winAnimator.mWin.mClient.dispatchGetNewSurface();
516 } catch (RemoteException e) {
517 }
518 }
519 } finally {
520 Binder.restoreCallingIdentity(callingIdentity);
521 }
522
523 return leakedSurface || killedApps;
524 }
525
526 // "Something has changed! Let's make it correct now."
527 // TODO: Super crazy long method that should be broken down...
528 void performSurfacePlacement(boolean recoveringMemory) {
529 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
530 + Debug.getCallers(3));
531
532 int i;
533 boolean updateInputWindowsNeeded = false;
534
535 if (mService.mFocusMayChange) {
536 mService.mFocusMayChange = false;
537 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
538 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
539 }
540
541 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700542 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700543 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700544 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800545 displayContent.setExitingTokensHasVisible(false);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700546 }
547
548 mHoldScreen = null;
549 mScreenBrightness = -1;
550 mButtonBrightness = -1;
551 mUserActivityTimeout = -1;
552 mObscureApplicationContentOnSecondaryDisplays = false;
553 mSustainedPerformanceModeCurrent = false;
554 mService.mTransactionSequence++;
555
556 // TODO(multi-display):
557 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
558 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
559 final int defaultDw = defaultInfo.logicalWidth;
560 final int defaultDh = defaultInfo.logicalHeight;
561
562 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
563 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
564 mService.openSurfaceTransaction();
565 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700566 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700567 } catch (RuntimeException e) {
568 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
569 } finally {
570 mService.closeSurfaceTransaction();
571 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
572 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
573 }
574
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700575 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
576
577 // If we are ready to perform an app transition, check through all of the app tokens to be
578 // shown and see if they are ready to go.
579 if (mService.mAppTransition.isReady()) {
580 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700581 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700582 if (DEBUG_LAYOUT_REPEATS)
583 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
584 defaultDisplay.pendingLayoutChanges);
585 }
586
587 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
588 // We have finished the animation of an app transition. To do this, we have delayed a
589 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
590 // token list reflects the correct Z-order, but the window list may now be out of sync
591 // with it. So here we will just rebuild the entire app window list. Fun!
592 defaultDisplay.pendingLayoutChanges |=
593 mService.handleAnimatingStoppedAndTransitionLocked();
594 if (DEBUG_LAYOUT_REPEATS)
595 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
596 defaultDisplay.pendingLayoutChanges);
597 }
598
599 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
600 && !mService.mAppTransition.isReady()) {
601 // At this point, there was a window with a wallpaper that was force hiding other
602 // windows behind it, but now it is going away. This may be simple -- just animate away
603 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
604 // shown behind something that was hidden.
605 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
606 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
607 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
608 }
609 mWallpaperForceHidingChanged = false;
610
611 if (mWallpaperMayChange) {
612 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
613 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
614 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
615 defaultDisplay.pendingLayoutChanges);
616 }
617
618 if (mService.mFocusMayChange) {
619 mService.mFocusMayChange = false;
620 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
621 false /*updateInputWindows*/)) {
622 updateInputWindowsNeeded = true;
623 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
624 }
625 }
626
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700627 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700628 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
629 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
630 defaultDisplay.pendingLayoutChanges);
631 }
632
633 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
634 WindowState win = mService.mResizingWindows.get(i);
635 if (win.mAppFreezing) {
636 // Don't remove this window until rotation has completed.
637 continue;
638 }
639 // Discard the saved surface if window size is changed, it can't be reused.
640 if (win.mAppToken != null) {
641 win.mAppToken.destroySavedSurfaces();
642 }
643 win.reportResized();
644 mService.mResizingWindows.remove(i);
645 }
646
647 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
648 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
649 if (mOrientationChangeComplete) {
650 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
651 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
652 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
653 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
654 }
655 mService.stopFreezingDisplayLocked();
656 }
657
658 // Destroy the surface of any windows that are no longer visible.
659 boolean wallpaperDestroyed = false;
660 i = mService.mDestroySurface.size();
661 if (i > 0) {
662 do {
663 i--;
664 WindowState win = mService.mDestroySurface.get(i);
665 win.mDestroying = false;
666 if (mService.mInputMethodWindow == win) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000667 mService.setInputMethodWindowLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700668 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700669 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700670 wallpaperDestroyed = true;
671 }
672 win.destroyOrSaveSurface();
673 } while (i > 0);
674 mService.mDestroySurface.clear();
675 }
676
677 // Time to remove any exiting tokens?
678 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700679 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800680 displayContent.removeExistingTokensIfPossible();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700681 }
682
683 if (wallpaperDestroyed) {
684 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700685 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700686 }
687
688 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700689 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700690 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700691 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700692 }
693 }
694
695 // Finally update all input windows now that the window changes have stabilized.
696 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
697
698 mService.setHoldScreenLocked(mHoldScreen);
699 if (!mService.mDisplayFrozen) {
700 if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) {
701 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
702 } else {
703 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
704 toBrightnessOverride(mScreenBrightness));
705 }
706 if (mButtonBrightness < 0 || mButtonBrightness > 1.0f) {
707 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
708 } else {
709 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
710 toBrightnessOverride(mButtonBrightness));
711 }
712 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
713 mUserActivityTimeout);
714 }
715
716 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
717 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
718 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700719 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700720 (mSustainedPerformanceModeEnabled ? 1 : 0));
721 }
722
723 if (mService.mTurnOnScreen) {
724 if (mService.mAllowTheaterModeWakeFromLayout
725 || Settings.Global.getInt(mService.mContext.getContentResolver(),
726 Settings.Global.THEATER_MODE_ON, 0) == 0) {
727 if (DEBUG_VISIBILITY || DEBUG_POWER) {
728 Slog.v(TAG, "Turning screen on after layout!");
729 }
730 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
731 "android.server.wm:TURN_ON");
732 }
733 mService.mTurnOnScreen = false;
734 }
735
736 if (mUpdateRotation) {
737 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700738 // TODO(multi-display): Update rotation for different displays separately.
739 final int displayId = defaultDisplay.getDisplayId();
Andrii Kulian06d07d62017-03-14 11:11:47 -0700740 if (defaultDisplay.updateRotationUnchecked(false /* inTransaction */)) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700741 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700742 } else {
743 mUpdateRotation = false;
744 }
745 }
746
747 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700748 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
749 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700750 mService.checkDrawnWindowsLocked();
751 }
752
753 final int N = mService.mPendingRemove.size();
754 if (N > 0) {
755 if (mService.mPendingRemoveTmp.length < N) {
756 mService.mPendingRemoveTmp = new WindowState[N+10];
757 }
758 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
759 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700760 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700761 for (i = 0; i < N; i++) {
762 final WindowState w = mService.mPendingRemoveTmp[i];
763 w.removeImmediately();
764 final DisplayContent displayContent = w.getDisplayContent();
765 if (displayContent != null && !displayList.contains(displayContent)) {
766 displayList.add(displayContent);
767 }
768 }
769
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700770 for (int j = displayList.size() - 1; j >= 0; --j) {
771 final DisplayContent dc = displayList.get(j);
772 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700773 }
774 }
775
776 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700777 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
778 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700779 }
780
781 if (updateInputWindowsNeeded) {
782 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
783 }
David Stevensee9e2772017-02-09 16:30:27 -0800784 mService.setFocusTaskRegionLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700785
786 // Check to see if we are now in a state where the screen should
787 // be enabled, because the window obscured flags have changed.
788 mService.enableScreenIfNeededLocked();
789
790 mService.scheduleAnimationLocked();
791 mService.mWindowPlacerLocked.destroyPendingSurfaces();
792
793 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
794 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
795 }
796
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700797 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
798 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700799 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700800 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700801
Andrii Kulian8ee72852017-03-10 10:36:45 -0800802 // TODO(multi-display): Support these features on secondary screens.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700803 if (mService.mWatermark != null) {
804 mService.mWatermark.positionSurface(defaultDw, defaultDh);
805 }
806 if (mService.mStrictModeFlash != null) {
807 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
808 }
809 if (mService.mCircularDisplayMask != null) {
Andrii Kulian8ee72852017-03-10 10:36:45 -0800810 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh,
811 mService.getDefaultDisplayRotation());
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700812 }
813 if (mService.mEmulatorDisplayOverlay != null) {
814 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
Andrii Kulian8ee72852017-03-10 10:36:45 -0800815 mService.getDefaultDisplayRotation());
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700816 }
817
818 boolean focusDisplayed = false;
819
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700820 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700821 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700822 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700823 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700824 }
825
826 if (focusDisplayed) {
827 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
828 }
829
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700830 // Give the display manager a chance to adjust properties like display rotation if it needs
831 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700832 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
833 }
834
835 /**
836 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700837 * @param obscured True if there is a window on top of this obscuring the display.
838 * @param syswin System window?
839 * @return True when the display contains content to show the user. When false, the display
840 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700841 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700842 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700843 final WindowManager.LayoutParams attrs = w.mAttrs;
844 final int attrFlags = attrs.flags;
845 final boolean canBeSeen = w.isDisplayedLw();
846 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700847 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700848
849 if (w.mHasSurface && canBeSeen) {
850 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
851 mHoldScreen = w.mSession;
852 mHoldScreenWindow = w;
853 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
854 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
855 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
856 + Debug.getCallers(10));
857 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700858 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700859 mScreenBrightness = w.mAttrs.screenBrightness;
860 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700861 if (!syswin && w.mAttrs.buttonBrightness >= 0 && mButtonBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700862 mButtonBrightness = w.mAttrs.buttonBrightness;
863 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700864 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700865 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
866 }
867
868 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700869 // This function assumes that the contents of the default display are processed first
870 // before secondary displays.
871 final DisplayContent displayContent = w.getDisplayContent();
872 if (displayContent != null && displayContent.isDefaultDisplay) {
873 // While a dream or keyguard is showing, obscure ordinary application content on
874 // secondary displays (by forcibly enabling mirroring unless there is other content
875 // we want to show) but still allow opaque keyguard dialogs to be shown.
876 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
877 mObscureApplicationContentOnSecondaryDisplays = true;
878 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700879 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700880 } else if (displayContent != null &&
881 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700882 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700883 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700884 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700885 }
886 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
887 mSustainedPerformanceModeCurrent = true;
888 }
889 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700890
891 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700892 }
893
894 boolean copyAnimToLayoutParams() {
895 boolean doRequest = false;
896
897 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
898 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
899 mUpdateRotation = true;
900 doRequest = true;
901 }
902 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
903 mWallpaperMayChange = true;
904 doRequest = true;
905 }
906 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
907 mWallpaperForceHidingChanged = true;
908 doRequest = true;
909 }
910 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
911 mOrientationChangeComplete = false;
912 } else {
913 mOrientationChangeComplete = true;
914 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
915 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
916 doRequest = true;
917 }
918 }
919 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
920 mService.mTurnOnScreen = true;
921 }
922 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
923 mWallpaperActionPending = true;
924 }
925
926 return doRequest;
927 }
928
929 private static int toBrightnessOverride(float value) {
930 return (int)(value * PowerManager.BRIGHTNESS_ON);
931 }
932
933 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
934 final FileDescriptor fd = pfd.getFileDescriptor();
935 if (mSurfaceTraceEnabled) {
936 disableSurfaceTrace();
937 }
938 mSurfaceTraceEnabled = true;
939 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
940 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700941 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
942 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700943 dc.enableSurfaceTrace(fd);
944 }
945 }
946
947 void disableSurfaceTrace() {
948 mSurfaceTraceEnabled = false;
949 mRemoteEventTrace = null;
950 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700951 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
952 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700953 dc.disableSurfaceTrace();
954 }
955 }
956
957 void dumpDisplayContents(PrintWriter pw) {
958 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
959 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700960 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700961 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700962 final DisplayContent displayContent = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700963 displayContent.dump(" ", pw);
964 }
965 } else {
966 pw.println(" NO DISPLAY");
967 }
968 }
969
970 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700971 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700972 return;
973 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700974 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700975 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700976 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700977 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700978 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700979 pw.print(displayContent.getDisplayId());
980 }
981 }
982 pw.println();
983 }
984
985 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800986 final int[] index = new int[1];
987 forAllWindows((w) -> {
988 if (windows == null || windows.contains(w)) {
989 pw.println(" Window #" + index[0] + " " + w + ":");
990 w.dump(pw, " ", dumpAll || windows != null);
991 index[0] = index[0] + 1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700992 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800993 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700994 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -0700995
Wale Ogunwale02319a62016-09-26 15:21:22 -0700996 void dumpTokens(PrintWriter pw, boolean dumpAll) {
997 pw.println(" All tokens:");
998 for (int i = mChildren.size() - 1; i >= 0; --i) {
999 mChildren.get(i).dumpTokens(pw, dumpAll);
1000 }
1001 }
1002
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001003 @Override
1004 String getName() {
1005 return "ROOT";
1006 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001007}