blob: b364fb9c7b45b47212ecec76df1810623108f62e [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;
Steven Timotiusaf03df62017-07-18 16:56:43 -070037import android.util.proto.ProtoOutputStream;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070038import android.view.Display;
39import android.view.DisplayInfo;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070040import android.view.WindowManager;
Jorim Jaggi86c39f92017-05-02 18:02:46 +020041
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;
Andrii Kulian48146fd2017-08-07 11:22:50 -070054import static android.view.Display.INVALID_DISPLAY;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070055import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070056import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070057import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
58import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
59import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070060import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070061import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
62import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi879ff722016-11-04 18:08:17 -070063
Wale Ogunwalee05f5012016-09-16 16:27:29 -070064import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
65import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070066import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
67import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
68import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070069import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
70import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
71import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
72import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
73import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
74import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
75import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
76import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
77import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070078import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
79import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070080import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
81import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
82import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
83import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
84import static com.android.server.wm.WindowManagerService.logSurface;
85import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
86import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
87import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
88import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
89import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
90import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Steven Timotiusaf03df62017-07-18 16:56:43 -070091import static com.android.server.wm.proto.WindowManagerServiceProto.DISPLAYS;
92import static com.android.server.wm.proto.WindowManagerServiceProto.WINDOWS;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070093
94/** Root {@link WindowContainer} for the device. */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -070095class RootWindowContainer extends WindowContainer<DisplayContent> {
Wale Ogunwalee05f5012016-09-16 16:27:29 -070096 private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM;
97
Jorim Jaggi86c39f92017-05-02 18:02:46 +020098 private static final int SET_SCREEN_BRIGHTNESS_OVERRIDE = 1;
99 private static final int SET_USER_ACTIVITY_TIMEOUT = 2;
100
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700101 WindowManagerService mService;
102
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700103 private boolean mWallpaperForceHidingChanged = false;
104 private Object mLastWindowFreezeSource = null;
105 private Session mHoldScreen = null;
106 private float mScreenBrightness = -1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700107 private long mUserActivityTimeout = -1;
108 private boolean mUpdateRotation = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700109 // Following variables are for debugging screen wakelock only.
110 // Last window that requires screen wakelock
111 WindowState mHoldScreenWindow = null;
112 // Last window that obscures all windows below
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700113 WindowState mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700114 // Only set while traversing the default display based on its content.
115 // Affects the behavior of mirroring on secondary displays.
116 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
117
118 private boolean mSustainedPerformanceModeEnabled = false;
119 private boolean mSustainedPerformanceModeCurrent = false;
120
121 boolean mWallpaperMayChange = false;
Robert Carr11c26c22016-09-23 12:40:27 -0700122 // During an orientation change, we track whether all windows have rendered
123 // at the new orientation, and this will be false from changing orientation until that occurs.
124 // For seamless rotation cases this always stays true, as the windows complete their orientation
125 // changes 1 by 1 without disturbing global state.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700126 boolean mOrientationChangeComplete = true;
127 boolean mWallpaperActionPending = false;
128
129 private final ArrayList<Integer> mChangedStackList = new ArrayList();
130
131 // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
132 // instances will be replaced with an instance that writes a binary representation of all
133 // commands to mSurfaceTraceFd.
134 boolean mSurfaceTraceEnabled;
135 ParcelFileDescriptor mSurfaceTraceFd;
136 RemoteEventTrace mRemoteEventTrace;
137
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700138 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700139 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700140
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200141 private final Handler mHandler;
142
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800143 private String mCloseSystemDialogsReason;
144 private final Consumer<WindowState> mCloseSystemDialogsConsumer = w -> {
145 if (w.mHasSurface) {
146 try {
147 w.mClient.closeSystemDialogs(mCloseSystemDialogsReason);
148 } catch (RemoteException e) {
149 }
150 }
151 };
152
153 private static final Consumer<WindowState> sRemoveReplacedWindowsConsumer = w -> {
154 final AppWindowToken aToken = w.mAppToken;
155 if (aToken != null) {
156 aToken.removeReplacedWindowIfNeeded(w);
157 }
158 };
159
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700160 RootWindowContainer(WindowManagerService service) {
161 mService = service;
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200162 mHandler = new MyHandler(service.mH.getLooper());
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700163 mLayersController = new WindowLayersController(mService);
Wale Ogunwale0303c572016-10-20 10:16:29 -0700164 mWallpaperController = new WallpaperController(mService);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700165 }
166
167 WindowState computeFocusedWindow() {
David Stevens46939562017-03-24 13:04:00 -0700168 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700169 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700170 final WindowState win = dc.findFocusedWindow();
171 if (win != null) {
172 return win;
173 }
174 }
175 return null;
176 }
177
178 /**
Andrii Kulian7fc22812016-12-28 13:04:11 -0800179 * Get an array with display ids ordered by focus priority - last items should be given
180 * focus first. Sparse array just maps position to displayId.
181 */
182 void getDisplaysInFocusOrder(SparseIntArray displaysInFocusOrder) {
183 displaysInFocusOrder.clear();
184
185 final int size = mChildren.size();
186 for (int i = 0; i < size; ++i) {
Andrii Kulian0214ed92017-05-16 13:44:05 -0700187 final DisplayContent displayContent = mChildren.get(i);
188 if (displayContent.isRemovalDeferred()) {
189 // Don't report displays that are going to be removed soon.
190 continue;
191 }
192 displaysInFocusOrder.put(i, displayContent.getDisplayId());
Andrii Kulian7fc22812016-12-28 13:04:11 -0800193 }
194 }
195
196 /**
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700197 * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
198 * there is a Display for the displayId.
199 *
200 * @param displayId The display the caller is interested in.
201 * @return The DisplayContent associated with displayId or null if there is no Display for it.
202 */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700203 DisplayContent getDisplayContentOrCreate(int displayId) {
204 DisplayContent dc = getDisplayContent(displayId);
205
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700206 if (dc == null) {
207 final Display display = mService.mDisplayManager.getDisplay(displayId);
208 if (display != null) {
Andrii Kulian325cac42017-04-20 16:02:47 -0700209 final long callingIdentity = Binder.clearCallingIdentity();
210 try {
211 dc = createDisplayContent(display);
212 } finally {
213 Binder.restoreCallingIdentity(callingIdentity);
214 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700215 }
216 }
217 return dc;
218 }
219
Wale Ogunwale02319a62016-09-26 15:21:22 -0700220 DisplayContent getDisplayContent(int displayId) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700221 for (int i = mChildren.size() - 1; i >= 0; --i) {
222 final DisplayContent current = mChildren.get(i);
223 if (current.getDisplayId() == displayId) {
224 return current;
225 }
226 }
227 return null;
228 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700229
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700230 private DisplayContent createDisplayContent(final Display display) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700231 final DisplayContent dc = new DisplayContent(display, mService, mLayersController,
232 mWallpaperController);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700233 final int displayId = display.getDisplayId();
234
235 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700236
237 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700238 final Rect rect = new Rect();
239 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
240 displayInfo.overscanLeft = rect.left;
241 displayInfo.overscanTop = rect.top;
242 displayInfo.overscanRight = rect.right;
243 displayInfo.overscanBottom = rect.bottom;
244 if (mService.mDisplayManagerInternal != null) {
245 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
246 displayId, displayInfo);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700247 mService.configureDisplayPolicyLocked(dc);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700248
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700249 // Tap Listeners are supported for:
250 // 1. All physical displays (multi-display).
251 // 2. VirtualDisplays that support virtual touch input. (Only VR for now)
252 // TODO(multi-display): Support VirtualDisplays with no virtual touch input.
253 if ((display.getType() != Display.TYPE_VIRTUAL
254 || (display.getType() == Display.TYPE_VIRTUAL
255 // Only VR VirtualDisplays
256 && displayId == mService.mVr2dDisplayId))
257 && mService.canDispatchPointerEvents()) {
258 if (DEBUG_DISPLAY) {
259 Slog.d(TAG,
260 "Registering PointerEventListener for DisplayId: " + displayId);
261 }
262 dc.mTapDetector = new TaskTapPointerEventListener(mService, dc);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700263 mService.registerPointerEventListener(dc.mTapDetector);
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700264 if (displayId == DEFAULT_DISPLAY) {
265 mService.registerPointerEventListener(mService.mMousePositionTracker);
266 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700267 }
268 }
269
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700270 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700271 }
272
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700273 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700274 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700275 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700276 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700277 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700278 return true;
279 }
280 }
281 return false;
282 }
283
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000284 void getWindowsByName(ArrayList<WindowState> output, String name) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700285 int objectId = 0;
286 // See if this is an object ID.
287 try {
288 objectId = Integer.parseInt(name, 16);
289 name = null;
290 } catch (RuntimeException e) {
291 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800292
293 getWindowsByName(output, name, objectId);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700294 }
295
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000296 private void getWindowsByName(ArrayList<WindowState> output, String name, int objectId) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800297 forAllWindows((w) -> {
298 if (name != null) {
299 if (w.mAttrs.getTitle().toString().contains(name)) {
300 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700301 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800302 } else if (System.identityHashCode(w) == objectId) {
303 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700304 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800305 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700306 }
307
Wale Ogunwale02319a62016-09-26 15:21:22 -0700308 /**
309 * Returns the app window token for the input binder if it exist in the system.
310 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
311 * AppWindowToken represents an activity which can only exist on one display.
312 */
313 AppWindowToken getAppWindowToken(IBinder binder) {
314 for (int i = mChildren.size() - 1; i >= 0; --i) {
315 final DisplayContent dc = mChildren.get(i);
316 final AppWindowToken atoken = dc.getAppWindowToken(binder);
317 if (atoken != null) {
318 return atoken;
319 }
320 }
321 return null;
322 }
323
324 /** Returns the display object the input window token is currently mapped on. */
325 DisplayContent getWindowTokenDisplay(WindowToken token) {
326 if (token == null) {
327 return null;
328 }
329
330 for (int i = mChildren.size() - 1; i >= 0; --i) {
331 final DisplayContent dc = mChildren.get(i);
332 final WindowToken current = dc.getWindowToken(token.token);
333 if (current == token) {
334 return dc;
335 }
336 }
337
338 return null;
339 }
340
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700341 /**
342 * Set new display override config and return array of ids of stacks that were changed during
343 * update. If called for the default display, global configuration will also be updated.
344 */
345 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
346 final DisplayContent displayContent = getDisplayContent(displayId);
347 if (displayContent == null) {
348 throw new IllegalArgumentException("Display not found for id: " + displayId);
349 }
350
351 final Configuration currentConfig = displayContent.getOverrideConfiguration();
352 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
353 if (!configChanged) {
354 return null;
355 }
Andrii Kuliand68501e2017-01-10 22:57:27 -0800356 displayContent.onOverrideConfigurationChanged(newConfiguration);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700357
358 if (displayId == DEFAULT_DISPLAY) {
359 // Override configuration of the default display duplicates global config. In this case
360 // we also want to update the global config.
361 return setGlobalConfigurationIfNeeded(newConfiguration);
362 } else {
363 return updateStackBoundsAfterConfigChange(displayId);
364 }
365 }
366
367 private int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700368 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
369 if (!configChanged) {
370 return null;
371 }
372 onConfigurationChanged(newConfiguration);
373 return updateStackBoundsAfterConfigChange();
374 }
375
376 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -0700377 public void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700378 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700379 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700380
381 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700382 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700383
Andrii Kulian441e4492016-09-29 15:25:00 -0700384 /**
385 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
386 * bounds were updated.
387 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700388 private int[] updateStackBoundsAfterConfigChange() {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700389 mChangedStackList.clear();
390
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700391 final int numDisplays = mChildren.size();
392 for (int i = 0; i < numDisplays; ++i) {
393 final DisplayContent dc = mChildren.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700394 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700395 }
396
397 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
398 }
399
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700400 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
401 private int[] updateStackBoundsAfterConfigChange(int displayId) {
402 mChangedStackList.clear();
403
404 final DisplayContent dc = getDisplayContent(displayId);
405 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
406
407 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
408 }
409
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700410 private void prepareFreezingTaskBounds() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700411 for (int i = mChildren.size() - 1; i >= 0; i--) {
412 mChildren.get(i).prepareFreezingTaskBounds();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700413 }
414 }
415
Wale Ogunwale1666e312016-12-16 11:27:18 -0800416 TaskStack getStackById(int stackId) {
417 for (int i = mChildren.size() - 1; i >= 0; i--) {
418 final DisplayContent dc = mChildren.get(i);
419 final TaskStack stack = dc.getStackById(stackId);
420 if (stack != null) {
421 return stack;
422 }
423 }
424 return null;
425 }
426
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700427 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800428 forAllWindows((w) -> {
429 if (w.mHasSurface && userId == UserHandle.getUserId(w.mOwnerUid)) {
430 w.mWinAnimator.setSecureLocked(disabled);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700431 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800432 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700433 }
434
435 void updateAppOpsState() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800436 forAllWindows((w) -> {
437 if (w.mAppOp == OP_NONE) {
438 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700439 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800440 final int mode = mService.mAppOps.checkOpNoThrow(w.mAppOp, w.getOwningUid(),
441 w.getOwningPackage());
442 w.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
443 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700444 }
445
446 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800447 final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw());
448 return win != null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700449 }
450
451 void closeSystemDialogs(String reason) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800452 mCloseSystemDialogsReason = reason;
453 forAllWindows(mCloseSystemDialogsConsumer, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700454 }
455
456 void removeReplacedWindows() {
457 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
458 mService.openSurfaceTransaction();
459 try {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800460 forAllWindows(sRemoveReplacedWindowsConsumer, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700461 } finally {
462 mService.closeSurfaceTransaction();
463 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
464 }
465 }
466
467 boolean hasPendingLayoutChanges(WindowAnimator animator) {
468 boolean hasChanges = false;
469
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700470 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700471 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700472 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700473 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
474 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
475 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
476 }
477 if (pendingChanges != 0) {
478 hasChanges = true;
479 }
480 }
481
482 return hasChanges;
483 }
484
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700485 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
486 boolean secure) {
487 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
488 boolean leakedSurface = false;
489 boolean killedApps = false;
490
491 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
492 winAnimator.mSession.mPid, operation);
493
494 final long callingIdentity = Binder.clearCallingIdentity();
495 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700496 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700497 // we haven't left any dangling surfaces around.
498
499 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700500 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700501 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700502 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700503 }
504
505 if (!leakedSurface) {
506 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700507 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700508 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800509 mChildren.get(displayNdx).forAllWindows((w) -> {
510 if (mService.mForceRemoves.contains(w)) {
511 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700512 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800513 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700514 if (wsa.mSurfaceController != null) {
515 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
516 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800517 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700518
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700519 if (pidCandidates.size() > 0) {
520 int[] pids = new int[pidCandidates.size()];
521 for (int i = 0; i < pids.length; i++) {
522 pids[i] = pidCandidates.keyAt(i);
523 }
524 try {
525 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
526 killedApps = true;
527 }
528 } catch (RemoteException e) {
529 }
530 }
531 }
532 }
533
534 if (leakedSurface || killedApps) {
535 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
536 // app to request another one.
537 Slog.w(TAG_WM,
538 "Looks like we have reclaimed some memory, clearing surface for retry.");
539 if (surfaceController != null) {
540 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
541 "RECOVER DESTROY", false);
542 winAnimator.destroySurface();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800543 if (winAnimator.mWin.mAppToken != null
544 && winAnimator.mWin.mAppToken.getController() != null) {
545 winAnimator.mWin.mAppToken.getController().removeStartingWindow();
546 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700547 }
548
549 try {
550 winAnimator.mWin.mClient.dispatchGetNewSurface();
551 } catch (RemoteException e) {
552 }
553 }
554 } finally {
555 Binder.restoreCallingIdentity(callingIdentity);
556 }
557
558 return leakedSurface || killedApps;
559 }
560
561 // "Something has changed! Let's make it correct now."
562 // TODO: Super crazy long method that should be broken down...
563 void performSurfacePlacement(boolean recoveringMemory) {
564 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
565 + Debug.getCallers(3));
566
567 int i;
568 boolean updateInputWindowsNeeded = false;
569
570 if (mService.mFocusMayChange) {
571 mService.mFocusMayChange = false;
572 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
573 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
574 }
575
576 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700577 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700578 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700579 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800580 displayContent.setExitingTokensHasVisible(false);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700581 }
582
583 mHoldScreen = null;
584 mScreenBrightness = -1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700585 mUserActivityTimeout = -1;
586 mObscureApplicationContentOnSecondaryDisplays = false;
587 mSustainedPerformanceModeCurrent = false;
588 mService.mTransactionSequence++;
589
590 // TODO(multi-display):
591 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
592 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
593 final int defaultDw = defaultInfo.logicalWidth;
594 final int defaultDh = defaultInfo.logicalHeight;
595
596 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
597 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
598 mService.openSurfaceTransaction();
599 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700600 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700601 } catch (RuntimeException e) {
602 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
603 } finally {
604 mService.closeSurfaceTransaction();
605 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
606 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
607 }
608
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700609 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
610
611 // If we are ready to perform an app transition, check through all of the app tokens to be
612 // shown and see if they are ready to go.
613 if (mService.mAppTransition.isReady()) {
614 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700615 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700616 if (DEBUG_LAYOUT_REPEATS)
617 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
618 defaultDisplay.pendingLayoutChanges);
619 }
620
621 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
622 // We have finished the animation of an app transition. To do this, we have delayed a
623 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
624 // token list reflects the correct Z-order, but the window list may now be out of sync
625 // with it. So here we will just rebuild the entire app window list. Fun!
626 defaultDisplay.pendingLayoutChanges |=
627 mService.handleAnimatingStoppedAndTransitionLocked();
628 if (DEBUG_LAYOUT_REPEATS)
629 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
630 defaultDisplay.pendingLayoutChanges);
631 }
632
633 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
634 && !mService.mAppTransition.isReady()) {
635 // At this point, there was a window with a wallpaper that was force hiding other
636 // windows behind it, but now it is going away. This may be simple -- just animate away
637 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
638 // shown behind something that was hidden.
639 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
640 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
641 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
642 }
643 mWallpaperForceHidingChanged = false;
644
645 if (mWallpaperMayChange) {
646 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
647 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
648 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
649 defaultDisplay.pendingLayoutChanges);
650 }
651
652 if (mService.mFocusMayChange) {
653 mService.mFocusMayChange = false;
654 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
655 false /*updateInputWindows*/)) {
656 updateInputWindowsNeeded = true;
657 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
658 }
659 }
660
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700661 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700662 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
663 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
664 defaultDisplay.pendingLayoutChanges);
665 }
666
667 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
668 WindowState win = mService.mResizingWindows.get(i);
669 if (win.mAppFreezing) {
670 // Don't remove this window until rotation has completed.
671 continue;
672 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700673 win.reportResized();
674 mService.mResizingWindows.remove(i);
675 }
676
677 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
678 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
679 if (mOrientationChangeComplete) {
680 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
681 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
682 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
683 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
684 }
685 mService.stopFreezingDisplayLocked();
686 }
687
688 // Destroy the surface of any windows that are no longer visible.
689 boolean wallpaperDestroyed = false;
690 i = mService.mDestroySurface.size();
691 if (i > 0) {
692 do {
693 i--;
694 WindowState win = mService.mDestroySurface.get(i);
695 win.mDestroying = false;
696 if (mService.mInputMethodWindow == win) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000697 mService.setInputMethodWindowLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700698 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700699 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700700 wallpaperDestroyed = true;
701 }
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200702 win.destroySurfaceUnchecked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700703 } while (i > 0);
704 mService.mDestroySurface.clear();
705 }
706
707 // Time to remove any exiting tokens?
708 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700709 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800710 displayContent.removeExistingTokensIfPossible();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700711 }
712
713 if (wallpaperDestroyed) {
714 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700715 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700716 }
717
718 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700719 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700720 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700721 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700722 }
723 }
724
725 // Finally update all input windows now that the window changes have stabilized.
726 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
727
728 mService.setHoldScreenLocked(mHoldScreen);
729 if (!mService.mDisplayFrozen) {
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200730 final int brightness = mScreenBrightness < 0 || mScreenBrightness > 1.0f
731 ? -1 : toBrightnessOverride(mScreenBrightness);
732
733 // Post these on a handler such that we don't call into power manager service while
734 // holding the window manager lock to avoid lock contention with power manager lock.
735 mHandler.obtainMessage(SET_SCREEN_BRIGHTNESS_OVERRIDE, brightness, 0).sendToTarget();
736 mHandler.obtainMessage(SET_USER_ACTIVITY_TIMEOUT, mUserActivityTimeout).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700737 }
738
739 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
740 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
741 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700742 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700743 (mSustainedPerformanceModeEnabled ? 1 : 0));
744 }
745
746 if (mService.mTurnOnScreen) {
747 if (mService.mAllowTheaterModeWakeFromLayout
748 || Settings.Global.getInt(mService.mContext.getContentResolver(),
749 Settings.Global.THEATER_MODE_ON, 0) == 0) {
750 if (DEBUG_VISIBILITY || DEBUG_POWER) {
751 Slog.v(TAG, "Turning screen on after layout!");
752 }
753 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
754 "android.server.wm:TURN_ON");
755 }
756 mService.mTurnOnScreen = false;
757 }
758
759 if (mUpdateRotation) {
760 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian48146fd2017-08-07 11:22:50 -0700761 // TODO(multi-display): Update rotation for different displays separately.
762 final int displayId = defaultDisplay.getDisplayId();
763 if (defaultDisplay.updateRotationUnchecked(false /* inTransaction */)) {
764 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
765 } else {
766 mUpdateRotation = false;
767 }
768 // Update rotation of VR virtual display separately. Currently this is the only kind of
769 // secondary display that can be rotated because of the single-display limitations in
770 // PhoneWindowManager.
771 final DisplayContent vrDisplay = mService.mVr2dDisplayId != INVALID_DISPLAY
772 ? getDisplayContent(mService.mVr2dDisplayId) : null;
773 if (vrDisplay != null && vrDisplay.updateRotationUnchecked(false /* inTransaction */)) {
774 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mService.mVr2dDisplayId)
775 .sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700776 }
777 }
778
779 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700780 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
781 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700782 mService.checkDrawnWindowsLocked();
783 }
784
785 final int N = mService.mPendingRemove.size();
786 if (N > 0) {
787 if (mService.mPendingRemoveTmp.length < N) {
788 mService.mPendingRemoveTmp = new WindowState[N+10];
789 }
790 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
791 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700792 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700793 for (i = 0; i < N; i++) {
794 final WindowState w = mService.mPendingRemoveTmp[i];
795 w.removeImmediately();
796 final DisplayContent displayContent = w.getDisplayContent();
797 if (displayContent != null && !displayList.contains(displayContent)) {
798 displayList.add(displayContent);
799 }
800 }
801
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700802 for (int j = displayList.size() - 1; j >= 0; --j) {
803 final DisplayContent dc = displayList.get(j);
804 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700805 }
806 }
807
808 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700809 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
810 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700811 }
812
813 if (updateInputWindowsNeeded) {
814 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
815 }
David Stevensee9e2772017-02-09 16:30:27 -0800816 mService.setFocusTaskRegionLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700817
818 // Check to see if we are now in a state where the screen should
819 // be enabled, because the window obscured flags have changed.
820 mService.enableScreenIfNeededLocked();
821
822 mService.scheduleAnimationLocked();
823 mService.mWindowPlacerLocked.destroyPendingSurfaces();
824
825 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
826 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
827 }
828
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700829 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
830 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700831 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700832 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700833
Andrii Kulian8ee72852017-03-10 10:36:45 -0800834 // TODO(multi-display): Support these features on secondary screens.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700835 if (mService.mWatermark != null) {
836 mService.mWatermark.positionSurface(defaultDw, defaultDh);
837 }
838 if (mService.mStrictModeFlash != null) {
839 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
840 }
841 if (mService.mCircularDisplayMask != null) {
Andrii Kulian8ee72852017-03-10 10:36:45 -0800842 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh,
843 mService.getDefaultDisplayRotation());
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700844 }
845 if (mService.mEmulatorDisplayOverlay != null) {
846 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
Andrii Kulian8ee72852017-03-10 10:36:45 -0800847 mService.getDefaultDisplayRotation());
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700848 }
849
850 boolean focusDisplayed = false;
851
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700852 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700853 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700854 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700855 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700856 }
857
858 if (focusDisplayed) {
859 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
860 }
861
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700862 // Give the display manager a chance to adjust properties like display rotation if it needs
863 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700864 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
865 }
866
867 /**
868 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700869 * @param obscured True if there is a window on top of this obscuring the display.
870 * @param syswin System window?
871 * @return True when the display contains content to show the user. When false, the display
872 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700873 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700874 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700875 final WindowManager.LayoutParams attrs = w.mAttrs;
876 final int attrFlags = attrs.flags;
877 final boolean canBeSeen = w.isDisplayedLw();
878 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700879 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700880
881 if (w.mHasSurface && canBeSeen) {
882 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
883 mHoldScreen = w.mSession;
884 mHoldScreenWindow = w;
885 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
886 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
Wale Ogunwale743fcc12017-06-06 21:36:50 +0000887 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
888 + Debug.getCallers(10));
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700889 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700890 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700891 mScreenBrightness = w.mAttrs.screenBrightness;
892 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700893 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700894 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
895 }
896
897 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700898 // This function assumes that the contents of the default display are processed first
899 // before secondary displays.
900 final DisplayContent displayContent = w.getDisplayContent();
901 if (displayContent != null && displayContent.isDefaultDisplay) {
902 // While a dream or keyguard is showing, obscure ordinary application content on
903 // secondary displays (by forcibly enabling mirroring unless there is other content
904 // we want to show) but still allow opaque keyguard dialogs to be shown.
905 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
906 mObscureApplicationContentOnSecondaryDisplays = true;
907 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700908 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700909 } else if (displayContent != null &&
910 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700911 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700912 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700913 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700914 }
915 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
916 mSustainedPerformanceModeCurrent = true;
917 }
918 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700919
920 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700921 }
922
923 boolean copyAnimToLayoutParams() {
924 boolean doRequest = false;
925
926 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
927 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
928 mUpdateRotation = true;
929 doRequest = true;
930 }
931 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
932 mWallpaperMayChange = true;
933 doRequest = true;
934 }
935 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
936 mWallpaperForceHidingChanged = true;
937 doRequest = true;
938 }
939 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
940 mOrientationChangeComplete = false;
941 } else {
942 mOrientationChangeComplete = true;
943 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
944 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
945 doRequest = true;
946 }
947 }
948 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
949 mService.mTurnOnScreen = true;
950 }
951 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
952 mWallpaperActionPending = true;
953 }
954
955 return doRequest;
956 }
957
958 private static int toBrightnessOverride(float value) {
959 return (int)(value * PowerManager.BRIGHTNESS_ON);
960 }
961
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200962 private final class MyHandler extends Handler {
963
964 public MyHandler(Looper looper) {
965 super(looper);
966 }
967
968 @Override
969 public void handleMessage(Message msg) {
970 switch (msg.what) {
971 case SET_SCREEN_BRIGHTNESS_OVERRIDE:
972 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
973 msg.arg1);
974 break;
975 case SET_USER_ACTIVITY_TIMEOUT:
976 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
977 (Long) msg.obj);
978 break;
979 default:
980 break;
981 }
982 }
983 }
984
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700985 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
986 final FileDescriptor fd = pfd.getFileDescriptor();
987 if (mSurfaceTraceEnabled) {
988 disableSurfaceTrace();
989 }
990 mSurfaceTraceEnabled = true;
991 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
992 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700993 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
994 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700995 dc.enableSurfaceTrace(fd);
996 }
997 }
998
999 void disableSurfaceTrace() {
1000 mSurfaceTraceEnabled = false;
1001 mRemoteEventTrace = null;
1002 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001003 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
1004 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001005 dc.disableSurfaceTrace();
1006 }
1007 }
1008
1009 void dumpDisplayContents(PrintWriter pw) {
1010 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
1011 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001012 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001013 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001014 final DisplayContent displayContent = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001015 displayContent.dump(" ", pw);
1016 }
1017 } else {
1018 pw.println(" NO DISPLAY");
1019 }
1020 }
1021
1022 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001023 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001024 return;
1025 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001026 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001027 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001028 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001029 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001030 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001031 pw.print(displayContent.getDisplayId());
1032 }
1033 }
1034 pw.println();
1035 }
1036
1037 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaled1880962016-11-08 10:31:59 -08001038 final int[] index = new int[1];
1039 forAllWindows((w) -> {
1040 if (windows == null || windows.contains(w)) {
1041 pw.println(" Window #" + index[0] + " " + w + ":");
1042 w.dump(pw, " ", dumpAll || windows != null);
1043 index[0] = index[0] + 1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001044 }
Wale Ogunwaled1880962016-11-08 10:31:59 -08001045 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001046 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001047
Wale Ogunwale02319a62016-09-26 15:21:22 -07001048 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1049 pw.println(" All tokens:");
1050 for (int i = mChildren.size() - 1; i >= 0; --i) {
1051 mChildren.get(i).dumpTokens(pw, dumpAll);
1052 }
1053 }
1054
Steven Timotiusaf03df62017-07-18 16:56:43 -07001055 void writeToProto(ProtoOutputStream proto) {
1056 if (mService.mDisplayReady) {
1057 final int count = mChildren.size();
1058 for (int i = 0; i < count; ++i) {
1059 final DisplayContent displayContent = mChildren.get(i);
1060 displayContent.writeToProto(proto, DISPLAYS);
1061 }
1062 }
1063 forAllWindows((w) -> {
1064 w.writeIdentifierToProto(proto, WINDOWS);
1065 }, true);
1066 }
1067
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001068 @Override
1069 String getName() {
1070 return "ROOT";
1071 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001072}