blob: 233e75bbfec7036685d6d3ccc8d87ac747d19e33 [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;
Jorim Jaggi86c39f92017-05-02 18:02:46 +020024import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -070025import android.os.IBinder;
Jorim Jaggi86c39f92017-05-02 18:02:46 +020026import android.os.Looper;
27import android.os.Message;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070028import android.os.ParcelFileDescriptor;
29import android.os.PowerManager;
30import android.os.RemoteException;
31import android.os.SystemClock;
32import android.os.UserHandle;
33import android.provider.Settings;
34import android.util.EventLog;
35import android.util.Slog;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070036import android.util.SparseIntArray;
37import android.view.Display;
38import android.view.DisplayInfo;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070039import android.view.WindowManager;
Jorim Jaggi86c39f92017-05-02 18:02:46 +020040
41import com.android.internal.os.SomeArgs;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070042import com.android.internal.util.ArrayUtils;
43import com.android.server.EventLogTags;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070044
45import java.io.FileDescriptor;
46import java.io.PrintWriter;
47import java.util.ArrayList;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080048import java.util.function.Consumer;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070049
Wale Ogunwalef7cab102016-10-25 15:25:14 -070050import static android.app.AppOpsManager.MODE_ALLOWED;
51import static android.app.AppOpsManager.MODE_DEFAULT;
52import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwale02319a62016-09-26 15:21:22 -070053import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070054import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070055import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070056import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
57import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
58import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070059import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070060import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
61import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi879ff722016-11-04 18:08:17 -070062
Wale Ogunwalee05f5012016-09-16 16:27:29 -070063import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
64import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070065import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
66import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
67import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
69import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
70import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
71import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
72import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
73import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
74import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
75import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
76import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070077import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
78import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070079import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
80import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
81import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
82import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
83import static com.android.server.wm.WindowManagerService.logSurface;
84import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
85import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
86import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
87import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
88import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
89import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
90
91/** Root {@link WindowContainer} for the device. */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -070092class RootWindowContainer extends WindowContainer<DisplayContent> {
Wale Ogunwalee05f5012016-09-16 16:27:29 -070093 private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM;
94
Jorim Jaggi86c39f92017-05-02 18:02:46 +020095 private static final int SET_SCREEN_BRIGHTNESS_OVERRIDE = 1;
96 private static final int SET_USER_ACTIVITY_TIMEOUT = 2;
97
Wale Ogunwalee05f5012016-09-16 16:27:29 -070098 WindowManagerService mService;
99
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700100 private boolean mWallpaperForceHidingChanged = false;
101 private Object mLastWindowFreezeSource = null;
102 private Session mHoldScreen = null;
103 private float mScreenBrightness = -1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700104 private long mUserActivityTimeout = -1;
105 private boolean mUpdateRotation = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700106 // Following variables are for debugging screen wakelock only.
107 // Last window that requires screen wakelock
108 WindowState mHoldScreenWindow = null;
109 // Last window that obscures all windows below
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700110 WindowState mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700111 // Only set while traversing the default display based on its content.
112 // Affects the behavior of mirroring on secondary displays.
113 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
114
115 private boolean mSustainedPerformanceModeEnabled = false;
116 private boolean mSustainedPerformanceModeCurrent = false;
117
118 boolean mWallpaperMayChange = false;
Robert Carr11c26c22016-09-23 12:40:27 -0700119 // During an orientation change, we track whether all windows have rendered
120 // at the new orientation, and this will be false from changing orientation until that occurs.
121 // For seamless rotation cases this always stays true, as the windows complete their orientation
122 // changes 1 by 1 without disturbing global state.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700123 boolean mOrientationChangeComplete = true;
124 boolean mWallpaperActionPending = false;
125
126 private final ArrayList<Integer> mChangedStackList = new ArrayList();
127
128 // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
129 // instances will be replaced with an instance that writes a binary representation of all
130 // commands to mSurfaceTraceFd.
131 boolean mSurfaceTraceEnabled;
132 ParcelFileDescriptor mSurfaceTraceFd;
133 RemoteEventTrace mRemoteEventTrace;
134
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700135 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700136 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700137
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200138 private final Handler mHandler;
139
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800140 private String mCloseSystemDialogsReason;
141 private final Consumer<WindowState> mCloseSystemDialogsConsumer = w -> {
142 if (w.mHasSurface) {
143 try {
144 w.mClient.closeSystemDialogs(mCloseSystemDialogsReason);
145 } catch (RemoteException e) {
146 }
147 }
148 };
149
150 private static final Consumer<WindowState> sRemoveReplacedWindowsConsumer = w -> {
151 final AppWindowToken aToken = w.mAppToken;
152 if (aToken != null) {
153 aToken.removeReplacedWindowIfNeeded(w);
154 }
155 };
156
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700157 RootWindowContainer(WindowManagerService service) {
158 mService = service;
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200159 mHandler = new MyHandler(service.mH.getLooper());
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700160 mLayersController = new WindowLayersController(mService);
Wale Ogunwale0303c572016-10-20 10:16:29 -0700161 mWallpaperController = new WallpaperController(mService);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700162 }
163
164 WindowState computeFocusedWindow() {
David Stevens46939562017-03-24 13:04:00 -0700165 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700166 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700167 final WindowState win = dc.findFocusedWindow();
168 if (win != null) {
169 return win;
170 }
171 }
172 return null;
173 }
174
175 /**
Andrii Kulian7fc22812016-12-28 13:04:11 -0800176 * Get an array with display ids ordered by focus priority - last items should be given
177 * focus first. Sparse array just maps position to displayId.
178 */
179 void getDisplaysInFocusOrder(SparseIntArray displaysInFocusOrder) {
180 displaysInFocusOrder.clear();
181
182 final int size = mChildren.size();
183 for (int i = 0; i < size; ++i) {
Andrii Kulian0214ed92017-05-16 13:44:05 -0700184 final DisplayContent displayContent = mChildren.get(i);
185 if (displayContent.isRemovalDeferred()) {
186 // Don't report displays that are going to be removed soon.
187 continue;
188 }
189 displaysInFocusOrder.put(i, displayContent.getDisplayId());
Andrii Kulian7fc22812016-12-28 13:04:11 -0800190 }
191 }
192
193 /**
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700194 * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
195 * there is a Display for the displayId.
196 *
197 * @param displayId The display the caller is interested in.
198 * @return The DisplayContent associated with displayId or null if there is no Display for it.
199 */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700200 DisplayContent getDisplayContentOrCreate(int displayId) {
201 DisplayContent dc = getDisplayContent(displayId);
202
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700203 if (dc == null) {
204 final Display display = mService.mDisplayManager.getDisplay(displayId);
205 if (display != null) {
Andrii Kulian325cac42017-04-20 16:02:47 -0700206 final long callingIdentity = Binder.clearCallingIdentity();
207 try {
208 dc = createDisplayContent(display);
209 } finally {
210 Binder.restoreCallingIdentity(callingIdentity);
211 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700212 }
213 }
214 return dc;
215 }
216
Wale Ogunwale02319a62016-09-26 15:21:22 -0700217 DisplayContent getDisplayContent(int displayId) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700218 for (int i = mChildren.size() - 1; i >= 0; --i) {
219 final DisplayContent current = mChildren.get(i);
220 if (current.getDisplayId() == displayId) {
221 return current;
222 }
223 }
224 return null;
225 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700226
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700227 private DisplayContent createDisplayContent(final Display display) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700228 final DisplayContent dc = new DisplayContent(display, mService, mLayersController,
229 mWallpaperController);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700230 final int displayId = display.getDisplayId();
231
232 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700233
234 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700235 final Rect rect = new Rect();
236 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
237 displayInfo.overscanLeft = rect.left;
238 displayInfo.overscanTop = rect.top;
239 displayInfo.overscanRight = rect.right;
240 displayInfo.overscanBottom = rect.bottom;
241 if (mService.mDisplayManagerInternal != null) {
242 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
243 displayId, displayInfo);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700244 mService.configureDisplayPolicyLocked(dc);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700245
246 // TODO(multi-display): Create an input channel for each display with touch capability.
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800247 if (displayId == DEFAULT_DISPLAY && mService.canDispatchPointerEvents()) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700248 dc.mTapDetector = new TaskTapPointerEventListener(
249 mService, dc);
250 mService.registerPointerEventListener(dc.mTapDetector);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700251 mService.registerPointerEventListener(mService.mMousePositionTracker);
252 }
253 }
254
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700255 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700256 }
257
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700258 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700259 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700260 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700261 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700262 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700263 return true;
264 }
265 }
266 return false;
267 }
268
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000269 void getWindowsByName(ArrayList<WindowState> output, String name) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700270 int objectId = 0;
271 // See if this is an object ID.
272 try {
273 objectId = Integer.parseInt(name, 16);
274 name = null;
275 } catch (RuntimeException e) {
276 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800277
278 getWindowsByName(output, name, objectId);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700279 }
280
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000281 private void getWindowsByName(ArrayList<WindowState> output, String name, int objectId) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800282 forAllWindows((w) -> {
283 if (name != null) {
284 if (w.mAttrs.getTitle().toString().contains(name)) {
285 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700286 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800287 } else if (System.identityHashCode(w) == objectId) {
288 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700289 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800290 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700291 }
292
Wale Ogunwale02319a62016-09-26 15:21:22 -0700293 /**
294 * Returns the app window token for the input binder if it exist in the system.
295 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
296 * AppWindowToken represents an activity which can only exist on one display.
297 */
298 AppWindowToken getAppWindowToken(IBinder binder) {
299 for (int i = mChildren.size() - 1; i >= 0; --i) {
300 final DisplayContent dc = mChildren.get(i);
301 final AppWindowToken atoken = dc.getAppWindowToken(binder);
302 if (atoken != null) {
303 return atoken;
304 }
305 }
306 return null;
307 }
308
309 /** Returns the display object the input window token is currently mapped on. */
310 DisplayContent getWindowTokenDisplay(WindowToken token) {
311 if (token == null) {
312 return null;
313 }
314
315 for (int i = mChildren.size() - 1; i >= 0; --i) {
316 final DisplayContent dc = mChildren.get(i);
317 final WindowToken current = dc.getWindowToken(token.token);
318 if (current == token) {
319 return dc;
320 }
321 }
322
323 return null;
324 }
325
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700326 /**
327 * Set new display override config and return array of ids of stacks that were changed during
328 * update. If called for the default display, global configuration will also be updated.
329 */
330 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
331 final DisplayContent displayContent = getDisplayContent(displayId);
332 if (displayContent == null) {
333 throw new IllegalArgumentException("Display not found for id: " + displayId);
334 }
335
336 final Configuration currentConfig = displayContent.getOverrideConfiguration();
337 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
338 if (!configChanged) {
339 return null;
340 }
Andrii Kuliand68501e2017-01-10 22:57:27 -0800341 displayContent.onOverrideConfigurationChanged(newConfiguration);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700342
343 if (displayId == DEFAULT_DISPLAY) {
344 // Override configuration of the default display duplicates global config. In this case
345 // we also want to update the global config.
346 return setGlobalConfigurationIfNeeded(newConfiguration);
347 } else {
348 return updateStackBoundsAfterConfigChange(displayId);
349 }
350 }
351
352 private int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700353 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
354 if (!configChanged) {
355 return null;
356 }
357 onConfigurationChanged(newConfiguration);
358 return updateStackBoundsAfterConfigChange();
359 }
360
361 @Override
362 void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700363 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700364 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700365
366 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700367 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700368
Andrii Kulian441e4492016-09-29 15:25:00 -0700369 /**
370 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
371 * bounds were updated.
372 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700373 private int[] updateStackBoundsAfterConfigChange() {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700374 mChangedStackList.clear();
375
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700376 final int numDisplays = mChildren.size();
377 for (int i = 0; i < numDisplays; ++i) {
378 final DisplayContent dc = mChildren.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700379 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700380 }
381
382 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
383 }
384
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700385 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
386 private int[] updateStackBoundsAfterConfigChange(int displayId) {
387 mChangedStackList.clear();
388
389 final DisplayContent dc = getDisplayContent(displayId);
390 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
391
392 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
393 }
394
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700395 private void prepareFreezingTaskBounds() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700396 for (int i = mChildren.size() - 1; i >= 0; i--) {
397 mChildren.get(i).prepareFreezingTaskBounds();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700398 }
399 }
400
Wale Ogunwale1666e312016-12-16 11:27:18 -0800401 TaskStack getStackById(int stackId) {
402 for (int i = mChildren.size() - 1; i >= 0; i--) {
403 final DisplayContent dc = mChildren.get(i);
404 final TaskStack stack = dc.getStackById(stackId);
405 if (stack != null) {
406 return stack;
407 }
408 }
409 return null;
410 }
411
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700412 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800413 forAllWindows((w) -> {
414 if (w.mHasSurface && userId == UserHandle.getUserId(w.mOwnerUid)) {
415 w.mWinAnimator.setSecureLocked(disabled);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700416 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800417 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700418 }
419
420 void updateAppOpsState() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800421 forAllWindows((w) -> {
422 if (w.mAppOp == OP_NONE) {
423 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700424 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800425 final int mode = mService.mAppOps.checkOpNoThrow(w.mAppOp, w.getOwningUid(),
426 w.getOwningPackage());
427 w.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
428 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700429 }
430
431 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800432 final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw());
433 return win != null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700434 }
435
436 void closeSystemDialogs(String reason) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800437 mCloseSystemDialogsReason = reason;
438 forAllWindows(mCloseSystemDialogsConsumer, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700439 }
440
441 void removeReplacedWindows() {
442 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
443 mService.openSurfaceTransaction();
444 try {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800445 forAllWindows(sRemoveReplacedWindowsConsumer, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700446 } finally {
447 mService.closeSurfaceTransaction();
448 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
449 }
450 }
451
452 boolean hasPendingLayoutChanges(WindowAnimator animator) {
453 boolean hasChanges = false;
454
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700455 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700456 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700457 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700458 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
459 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
460 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
461 }
462 if (pendingChanges != 0) {
463 hasChanges = true;
464 }
465 }
466
467 return hasChanges;
468 }
469
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700470 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
471 boolean secure) {
472 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
473 boolean leakedSurface = false;
474 boolean killedApps = false;
475
476 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
477 winAnimator.mSession.mPid, operation);
478
479 final long callingIdentity = Binder.clearCallingIdentity();
480 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700481 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700482 // we haven't left any dangling surfaces around.
483
484 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700485 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700486 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700487 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700488 }
489
490 if (!leakedSurface) {
491 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700492 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700493 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800494 mChildren.get(displayNdx).forAllWindows((w) -> {
495 if (mService.mForceRemoves.contains(w)) {
496 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700497 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800498 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700499 if (wsa.mSurfaceController != null) {
500 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
501 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800502 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700503
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700504 if (pidCandidates.size() > 0) {
505 int[] pids = new int[pidCandidates.size()];
506 for (int i = 0; i < pids.length; i++) {
507 pids[i] = pidCandidates.keyAt(i);
508 }
509 try {
510 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
511 killedApps = true;
512 }
513 } catch (RemoteException e) {
514 }
515 }
516 }
517 }
518
519 if (leakedSurface || killedApps) {
520 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
521 // app to request another one.
522 Slog.w(TAG_WM,
523 "Looks like we have reclaimed some memory, clearing surface for retry.");
524 if (surfaceController != null) {
525 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
526 "RECOVER DESTROY", false);
527 winAnimator.destroySurface();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800528 if (winAnimator.mWin.mAppToken != null
529 && winAnimator.mWin.mAppToken.getController() != null) {
530 winAnimator.mWin.mAppToken.getController().removeStartingWindow();
531 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700532 }
533
534 try {
535 winAnimator.mWin.mClient.dispatchGetNewSurface();
536 } catch (RemoteException e) {
537 }
538 }
539 } finally {
540 Binder.restoreCallingIdentity(callingIdentity);
541 }
542
543 return leakedSurface || killedApps;
544 }
545
546 // "Something has changed! Let's make it correct now."
547 // TODO: Super crazy long method that should be broken down...
548 void performSurfacePlacement(boolean recoveringMemory) {
549 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
550 + Debug.getCallers(3));
551
552 int i;
553 boolean updateInputWindowsNeeded = false;
554
555 if (mService.mFocusMayChange) {
556 mService.mFocusMayChange = false;
557 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
558 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
559 }
560
561 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700562 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700563 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700564 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800565 displayContent.setExitingTokensHasVisible(false);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700566 }
567
568 mHoldScreen = null;
569 mScreenBrightness = -1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700570 mUserActivityTimeout = -1;
571 mObscureApplicationContentOnSecondaryDisplays = false;
572 mSustainedPerformanceModeCurrent = false;
573 mService.mTransactionSequence++;
574
575 // TODO(multi-display):
576 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
577 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
578 final int defaultDw = defaultInfo.logicalWidth;
579 final int defaultDh = defaultInfo.logicalHeight;
580
581 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
582 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
583 mService.openSurfaceTransaction();
584 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700585 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700586 } catch (RuntimeException e) {
587 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
588 } finally {
589 mService.closeSurfaceTransaction();
590 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
591 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
592 }
593
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700594 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
595
596 // If we are ready to perform an app transition, check through all of the app tokens to be
597 // shown and see if they are ready to go.
598 if (mService.mAppTransition.isReady()) {
599 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700600 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700601 if (DEBUG_LAYOUT_REPEATS)
602 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
603 defaultDisplay.pendingLayoutChanges);
604 }
605
606 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
607 // We have finished the animation of an app transition. To do this, we have delayed a
608 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
609 // token list reflects the correct Z-order, but the window list may now be out of sync
610 // with it. So here we will just rebuild the entire app window list. Fun!
611 defaultDisplay.pendingLayoutChanges |=
612 mService.handleAnimatingStoppedAndTransitionLocked();
613 if (DEBUG_LAYOUT_REPEATS)
614 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
615 defaultDisplay.pendingLayoutChanges);
616 }
617
618 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
619 && !mService.mAppTransition.isReady()) {
620 // At this point, there was a window with a wallpaper that was force hiding other
621 // windows behind it, but now it is going away. This may be simple -- just animate away
622 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
623 // shown behind something that was hidden.
624 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
625 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
626 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
627 }
628 mWallpaperForceHidingChanged = false;
629
630 if (mWallpaperMayChange) {
631 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
632 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
633 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
634 defaultDisplay.pendingLayoutChanges);
635 }
636
637 if (mService.mFocusMayChange) {
638 mService.mFocusMayChange = false;
639 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
640 false /*updateInputWindows*/)) {
641 updateInputWindowsNeeded = true;
642 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
643 }
644 }
645
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700646 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700647 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
648 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
649 defaultDisplay.pendingLayoutChanges);
650 }
651
652 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
653 WindowState win = mService.mResizingWindows.get(i);
654 if (win.mAppFreezing) {
655 // Don't remove this window until rotation has completed.
656 continue;
657 }
658 // Discard the saved surface if window size is changed, it can't be reused.
659 if (win.mAppToken != null) {
660 win.mAppToken.destroySavedSurfaces();
661 }
662 win.reportResized();
663 mService.mResizingWindows.remove(i);
664 }
665
666 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
667 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
668 if (mOrientationChangeComplete) {
669 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
670 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
671 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
672 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
673 }
674 mService.stopFreezingDisplayLocked();
675 }
676
677 // Destroy the surface of any windows that are no longer visible.
678 boolean wallpaperDestroyed = false;
679 i = mService.mDestroySurface.size();
680 if (i > 0) {
681 do {
682 i--;
683 WindowState win = mService.mDestroySurface.get(i);
684 win.mDestroying = false;
685 if (mService.mInputMethodWindow == win) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000686 mService.setInputMethodWindowLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700687 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700688 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700689 wallpaperDestroyed = true;
690 }
Robert Carr89a28ab2017-04-24 15:33:11 -0700691 win.destroyOrSaveSurfaceUnchecked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700692 } while (i > 0);
693 mService.mDestroySurface.clear();
694 }
695
696 // Time to remove any exiting tokens?
697 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700698 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800699 displayContent.removeExistingTokensIfPossible();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700700 }
701
702 if (wallpaperDestroyed) {
703 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700704 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700705 }
706
707 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700708 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700709 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700710 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700711 }
712 }
713
714 // Finally update all input windows now that the window changes have stabilized.
715 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
716
717 mService.setHoldScreenLocked(mHoldScreen);
718 if (!mService.mDisplayFrozen) {
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200719 final int brightness = mScreenBrightness < 0 || mScreenBrightness > 1.0f
720 ? -1 : toBrightnessOverride(mScreenBrightness);
721
722 // Post these on a handler such that we don't call into power manager service while
723 // holding the window manager lock to avoid lock contention with power manager lock.
724 mHandler.obtainMessage(SET_SCREEN_BRIGHTNESS_OVERRIDE, brightness, 0).sendToTarget();
725 mHandler.obtainMessage(SET_USER_ACTIVITY_TIMEOUT, mUserActivityTimeout).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700726 }
727
728 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
729 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
730 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700731 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700732 (mSustainedPerformanceModeEnabled ? 1 : 0));
733 }
734
735 if (mService.mTurnOnScreen) {
736 if (mService.mAllowTheaterModeWakeFromLayout
737 || Settings.Global.getInt(mService.mContext.getContentResolver(),
738 Settings.Global.THEATER_MODE_ON, 0) == 0) {
739 if (DEBUG_VISIBILITY || DEBUG_POWER) {
740 Slog.v(TAG, "Turning screen on after layout!");
741 }
742 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
743 "android.server.wm:TURN_ON");
744 }
745 mService.mTurnOnScreen = false;
746 }
747
748 if (mUpdateRotation) {
749 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700750 // TODO(multi-display): Update rotation for different displays separately.
751 final int displayId = defaultDisplay.getDisplayId();
Andrii Kulian06d07d62017-03-14 11:11:47 -0700752 if (defaultDisplay.updateRotationUnchecked(false /* inTransaction */)) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700753 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700754 } else {
755 mUpdateRotation = false;
756 }
757 }
758
759 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700760 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
761 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700762 mService.checkDrawnWindowsLocked();
763 }
764
765 final int N = mService.mPendingRemove.size();
766 if (N > 0) {
767 if (mService.mPendingRemoveTmp.length < N) {
768 mService.mPendingRemoveTmp = new WindowState[N+10];
769 }
770 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
771 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700772 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700773 for (i = 0; i < N; i++) {
774 final WindowState w = mService.mPendingRemoveTmp[i];
775 w.removeImmediately();
776 final DisplayContent displayContent = w.getDisplayContent();
777 if (displayContent != null && !displayList.contains(displayContent)) {
778 displayList.add(displayContent);
779 }
780 }
781
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700782 for (int j = displayList.size() - 1; j >= 0; --j) {
783 final DisplayContent dc = displayList.get(j);
784 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700785 }
786 }
787
788 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700789 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
790 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700791 }
792
793 if (updateInputWindowsNeeded) {
794 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
795 }
David Stevensee9e2772017-02-09 16:30:27 -0800796 mService.setFocusTaskRegionLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700797
798 // Check to see if we are now in a state where the screen should
799 // be enabled, because the window obscured flags have changed.
800 mService.enableScreenIfNeededLocked();
801
802 mService.scheduleAnimationLocked();
803 mService.mWindowPlacerLocked.destroyPendingSurfaces();
804
805 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
806 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
807 }
808
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700809 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
810 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700811 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700812 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700813
Andrii Kulian8ee72852017-03-10 10:36:45 -0800814 // TODO(multi-display): Support these features on secondary screens.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700815 if (mService.mWatermark != null) {
816 mService.mWatermark.positionSurface(defaultDw, defaultDh);
817 }
818 if (mService.mStrictModeFlash != null) {
819 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
820 }
821 if (mService.mCircularDisplayMask != null) {
Andrii Kulian8ee72852017-03-10 10:36:45 -0800822 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh,
823 mService.getDefaultDisplayRotation());
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700824 }
825 if (mService.mEmulatorDisplayOverlay != null) {
826 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
Andrii Kulian8ee72852017-03-10 10:36:45 -0800827 mService.getDefaultDisplayRotation());
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700828 }
829
830 boolean focusDisplayed = false;
831
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700832 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700833 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700834 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700835 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700836 }
837
838 if (focusDisplayed) {
839 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
840 }
841
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700842 // Give the display manager a chance to adjust properties like display rotation if it needs
843 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700844 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
845 }
846
847 /**
848 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700849 * @param obscured True if there is a window on top of this obscuring the display.
850 * @param syswin System window?
851 * @return True when the display contains content to show the user. When false, the display
852 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700853 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700854 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700855 final WindowManager.LayoutParams attrs = w.mAttrs;
856 final int attrFlags = attrs.flags;
857 final boolean canBeSeen = w.isDisplayedLw();
858 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700859 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700860
861 if (w.mHasSurface && canBeSeen) {
862 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
863 mHoldScreen = w.mSession;
864 mHoldScreenWindow = w;
865 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
866 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
Wale Ogunwale743fcc12017-06-06 21:36:50 +0000867 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
868 + Debug.getCallers(10));
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700869 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700870 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700871 mScreenBrightness = w.mAttrs.screenBrightness;
872 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700873 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700874 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
875 }
876
877 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700878 // This function assumes that the contents of the default display are processed first
879 // before secondary displays.
880 final DisplayContent displayContent = w.getDisplayContent();
881 if (displayContent != null && displayContent.isDefaultDisplay) {
882 // While a dream or keyguard is showing, obscure ordinary application content on
883 // secondary displays (by forcibly enabling mirroring unless there is other content
884 // we want to show) but still allow opaque keyguard dialogs to be shown.
885 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
886 mObscureApplicationContentOnSecondaryDisplays = true;
887 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700888 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700889 } else if (displayContent != null &&
890 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700891 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700892 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700893 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700894 }
895 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
896 mSustainedPerformanceModeCurrent = true;
897 }
898 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700899
900 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700901 }
902
903 boolean copyAnimToLayoutParams() {
904 boolean doRequest = false;
905
906 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
907 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
908 mUpdateRotation = true;
909 doRequest = true;
910 }
911 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
912 mWallpaperMayChange = true;
913 doRequest = true;
914 }
915 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
916 mWallpaperForceHidingChanged = true;
917 doRequest = true;
918 }
919 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
920 mOrientationChangeComplete = false;
921 } else {
922 mOrientationChangeComplete = true;
923 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
924 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
925 doRequest = true;
926 }
927 }
928 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
929 mService.mTurnOnScreen = true;
930 }
931 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
932 mWallpaperActionPending = true;
933 }
934
935 return doRequest;
936 }
937
938 private static int toBrightnessOverride(float value) {
939 return (int)(value * PowerManager.BRIGHTNESS_ON);
940 }
941
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200942 private final class MyHandler extends Handler {
943
944 public MyHandler(Looper looper) {
945 super(looper);
946 }
947
948 @Override
949 public void handleMessage(Message msg) {
950 switch (msg.what) {
951 case SET_SCREEN_BRIGHTNESS_OVERRIDE:
952 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
953 msg.arg1);
954 break;
955 case SET_USER_ACTIVITY_TIMEOUT:
956 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
957 (Long) msg.obj);
958 break;
959 default:
960 break;
961 }
962 }
963 }
964
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700965 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
966 final FileDescriptor fd = pfd.getFileDescriptor();
967 if (mSurfaceTraceEnabled) {
968 disableSurfaceTrace();
969 }
970 mSurfaceTraceEnabled = true;
971 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
972 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700973 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
974 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700975 dc.enableSurfaceTrace(fd);
976 }
977 }
978
979 void disableSurfaceTrace() {
980 mSurfaceTraceEnabled = false;
981 mRemoteEventTrace = null;
982 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700983 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
984 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700985 dc.disableSurfaceTrace();
986 }
987 }
988
989 void dumpDisplayContents(PrintWriter pw) {
990 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
991 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700992 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700993 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700994 final DisplayContent displayContent = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700995 displayContent.dump(" ", pw);
996 }
997 } else {
998 pw.println(" NO DISPLAY");
999 }
1000 }
1001
1002 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001003 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001004 return;
1005 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001006 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001007 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001008 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001009 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001010 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001011 pw.print(displayContent.getDisplayId());
1012 }
1013 }
1014 pw.println();
1015 }
1016
1017 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaled1880962016-11-08 10:31:59 -08001018 final int[] index = new int[1];
1019 forAllWindows((w) -> {
1020 if (windows == null || windows.contains(w)) {
1021 pw.println(" Window #" + index[0] + " " + w + ":");
1022 w.dump(pw, " ", dumpAll || windows != null);
1023 index[0] = index[0] + 1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001024 }
Wale Ogunwaled1880962016-11-08 10:31:59 -08001025 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001026 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001027
Wale Ogunwale02319a62016-09-26 15:21:22 -07001028 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1029 pw.println(" All tokens:");
1030 for (int i = mChildren.size() - 1; i >= 0; --i) {
1031 mChildren.get(i).dumpTokens(pw, dumpAll);
1032 }
1033 }
1034
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001035 @Override
1036 String getName() {
1037 return "ROOT";
1038 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001039}