blob: 50d0d0a5f1f9b2a1a034ca39101e74518e4b292a [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 Ogunwale0d5609b2017-09-13 05:55:07 -070019import android.annotation.CallSuper;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070020import android.content.res.Configuration;
21import android.graphics.Rect;
Ruchi Kandoi0d434042016-10-03 09:12:02 -070022import android.hardware.power.V1_0.PowerHint;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070023import android.os.Binder;
24import android.os.Debug;
Jorim Jaggi86c39f92017-05-02 18:02:46 +020025import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -070026import android.os.IBinder;
Jorim Jaggi86c39f92017-05-02 18:02:46 +020027import android.os.Looper;
28import android.os.Message;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070029import android.os.ParcelFileDescriptor;
30import android.os.PowerManager;
31import android.os.RemoteException;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070032import android.os.UserHandle;
David Stevensf833ba92017-03-16 19:00:20 -070033import android.util.ArraySet;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070034import 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;
Robert Carrae606b42018-02-15 15:36:23 -080040import android.view.SurfaceControl;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070041import android.view.WindowManager;
Jorim Jaggi86c39f92017-05-02 18:02:46 +020042
Wale Ogunwalee05f5012016-09-16 16:27:29 -070043import com.android.internal.util.ArrayUtils;
44import com.android.server.EventLogTags;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070045
46import java.io.FileDescriptor;
47import java.io.PrintWriter;
48import java.util.ArrayList;
Bryce Leeaea60d22018-01-31 14:42:15 -080049import java.util.List;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080050import java.util.function.Consumer;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070051
Wale Ogunwale02319a62016-09-26 15:21:22 -070052import static android.view.Display.DEFAULT_DISPLAY;
Andrii Kulian48146fd2017-08-07 11:22:50 -070053import static android.view.Display.INVALID_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;
Jorim Jaggi879ff722016-11-04 18:08:17 -070059
Adrian Roose99bc052017-11-20 17:55:31 +010060import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
61import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
62import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
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;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070067import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
68import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
69import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
70import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
71import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
72import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
73import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
74import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070075import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
76import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070077import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
78import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
79import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
80import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
81import static com.android.server.wm.WindowManagerService.logSurface;
82import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
83import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070084import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
85import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
86import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070087import static com.android.server.wm.RootWindowContainerProto.DISPLAYS;
88import static com.android.server.wm.RootWindowContainerProto.WINDOWS;
89import static com.android.server.wm.RootWindowContainerProto.WINDOW_CONTAINER;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070090
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 private boolean mWallpaperForceHidingChanged = false;
99 private Object mLastWindowFreezeSource = null;
100 private Session mHoldScreen = null;
101 private float mScreenBrightness = -1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700102 private long mUserActivityTimeout = -1;
103 private boolean mUpdateRotation = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700104 // Following variables are for debugging screen wakelock only.
105 // Last window that requires screen wakelock
106 WindowState mHoldScreenWindow = null;
107 // Last window that obscures all windows below
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700108 WindowState mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700109 // Only set while traversing the default display based on its content.
110 // Affects the behavior of mirroring on secondary displays.
111 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
112
113 private boolean mSustainedPerformanceModeEnabled = false;
114 private boolean mSustainedPerformanceModeCurrent = false;
115
116 boolean mWallpaperMayChange = false;
Robert Carr11c26c22016-09-23 12:40:27 -0700117 // During an orientation change, we track whether all windows have rendered
118 // at the new orientation, and this will be false from changing orientation until that occurs.
119 // For seamless rotation cases this always stays true, as the windows complete their orientation
120 // changes 1 by 1 without disturbing global state.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700121 boolean mOrientationChangeComplete = true;
122 boolean mWallpaperActionPending = false;
123
Bryce Leeaea60d22018-01-31 14:42:15 -0800124 private final ArrayList<TaskStack> mTmpStackList = new ArrayList();
125 private final ArrayList<Integer> mTmpStackIds = new ArrayList<>();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700126
Wale Ogunwale0303c572016-10-20 10:16:29 -0700127 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700128
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200129 private final Handler mHandler;
130
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800131 private String mCloseSystemDialogsReason;
Robert Carrae606b42018-02-15 15:36:23 -0800132
133 // Only a seperate transaction until we seperate the apply surface changes
134 // transaction from the global transaction.
135 private final SurfaceControl.Transaction mDisplayTransaction = new SurfaceControl.Transaction();
136
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800137 private final Consumer<WindowState> mCloseSystemDialogsConsumer = w -> {
138 if (w.mHasSurface) {
139 try {
140 w.mClient.closeSystemDialogs(mCloseSystemDialogsReason);
141 } catch (RemoteException e) {
142 }
143 }
144 };
145
146 private static final Consumer<WindowState> sRemoveReplacedWindowsConsumer = w -> {
147 final AppWindowToken aToken = w.mAppToken;
148 if (aToken != null) {
149 aToken.removeReplacedWindowIfNeeded(w);
150 }
151 };
152
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700153 RootWindowContainer(WindowManagerService service) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100154 super(service);
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200155 mHandler = new MyHandler(service.mH.getLooper());
Wale Ogunwale0303c572016-10-20 10:16:29 -0700156 mWallpaperController = new WallpaperController(mService);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700157 }
158
159 WindowState computeFocusedWindow() {
David Stevens46939562017-03-24 13:04:00 -0700160 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700161 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700162 final WindowState win = dc.findFocusedWindow();
163 if (win != null) {
164 return win;
165 }
166 }
167 return null;
168 }
169
170 /**
Andrii Kulian7fc22812016-12-28 13:04:11 -0800171 * Get an array with display ids ordered by focus priority - last items should be given
172 * focus first. Sparse array just maps position to displayId.
173 */
174 void getDisplaysInFocusOrder(SparseIntArray displaysInFocusOrder) {
175 displaysInFocusOrder.clear();
176
177 final int size = mChildren.size();
178 for (int i = 0; i < size; ++i) {
Andrii Kulian0214ed92017-05-16 13:44:05 -0700179 final DisplayContent displayContent = mChildren.get(i);
180 if (displayContent.isRemovalDeferred()) {
181 // Don't report displays that are going to be removed soon.
182 continue;
183 }
184 displaysInFocusOrder.put(i, displayContent.getDisplayId());
Andrii Kulian7fc22812016-12-28 13:04:11 -0800185 }
186 }
187
Wale Ogunwale02319a62016-09-26 15:21:22 -0700188 DisplayContent getDisplayContent(int displayId) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700189 for (int i = mChildren.size() - 1; i >= 0; --i) {
190 final DisplayContent current = mChildren.get(i);
191 if (current.getDisplayId() == displayId) {
192 return current;
193 }
194 }
195 return null;
196 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700197
Bryce Leef19cbe22018-02-02 15:09:21 -0800198 DisplayContent createDisplayContent(final Display display, DisplayWindowController controller) {
Bryce Lee1cddfdc2018-02-20 10:41:58 -0800199 final int displayId = display.getDisplayId();
200
201 // In select scenarios, it is possible that a DisplayContent will be created on demand
202 // rather than waiting for the controller. In this case, associate the controller and return
203 // the existing display.
204 final DisplayContent existing = getDisplayContent(displayId);
205
206 if (existing != null) {
207 existing.setController(controller);
208 return existing;
209 }
210
Bryce Leef19cbe22018-02-02 15:09:21 -0800211 final DisplayContent dc =
212 new DisplayContent(display, mService, mWallpaperController, controller);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700213
214 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700215
216 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700217 final Rect rect = new Rect();
218 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
219 displayInfo.overscanLeft = rect.left;
220 displayInfo.overscanTop = rect.top;
221 displayInfo.overscanRight = rect.right;
222 displayInfo.overscanBottom = rect.bottom;
223 if (mService.mDisplayManagerInternal != null) {
224 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
225 displayId, displayInfo);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000226 dc.configureDisplayPolicy();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700227
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700228 // Tap Listeners are supported for:
229 // 1. All physical displays (multi-display).
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -0700230 // 2. VirtualDisplays on VR, AA (and everything else).
231 if (mService.canDispatchPointerEvents()) {
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700232 if (DEBUG_DISPLAY) {
233 Slog.d(TAG,
234 "Registering PointerEventListener for DisplayId: " + displayId);
235 }
236 dc.mTapDetector = new TaskTapPointerEventListener(mService, dc);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700237 mService.registerPointerEventListener(dc.mTapDetector);
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700238 if (displayId == DEFAULT_DISPLAY) {
239 mService.registerPointerEventListener(mService.mMousePositionTracker);
240 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700241 }
242 }
243
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700244 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700245 }
246
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700247 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700248 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700249 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700250 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700251 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700252 return true;
253 }
254 }
255 return false;
256 }
257
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000258 void getWindowsByName(ArrayList<WindowState> output, String name) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700259 int objectId = 0;
260 // See if this is an object ID.
261 try {
262 objectId = Integer.parseInt(name, 16);
263 name = null;
264 } catch (RuntimeException e) {
265 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800266
267 getWindowsByName(output, name, objectId);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700268 }
269
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000270 private void getWindowsByName(ArrayList<WindowState> output, String name, int objectId) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800271 forAllWindows((w) -> {
272 if (name != null) {
273 if (w.mAttrs.getTitle().toString().contains(name)) {
274 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700275 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800276 } else if (System.identityHashCode(w) == objectId) {
277 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700278 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800279 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700280 }
281
Wale Ogunwale02319a62016-09-26 15:21:22 -0700282 /**
283 * Returns the app window token for the input binder if it exist in the system.
284 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
285 * AppWindowToken represents an activity which can only exist on one display.
286 */
287 AppWindowToken getAppWindowToken(IBinder binder) {
288 for (int i = mChildren.size() - 1; i >= 0; --i) {
289 final DisplayContent dc = mChildren.get(i);
290 final AppWindowToken atoken = dc.getAppWindowToken(binder);
291 if (atoken != null) {
292 return atoken;
293 }
294 }
295 return null;
296 }
297
298 /** Returns the display object the input window token is currently mapped on. */
299 DisplayContent getWindowTokenDisplay(WindowToken token) {
300 if (token == null) {
301 return null;
302 }
303
304 for (int i = mChildren.size() - 1; i >= 0; --i) {
305 final DisplayContent dc = mChildren.get(i);
306 final WindowToken current = dc.getWindowToken(token.token);
307 if (current == token) {
308 return dc;
309 }
310 }
311
312 return null;
313 }
314
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700315 /**
316 * Set new display override config and return array of ids of stacks that were changed during
Bryce Leeaea60d22018-01-31 14:42:15 -0800317 * update. If called for the default display, global configuration will also be updated. Stacks
318 * that are marked for deferred removal are excluded from the returned array.
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700319 */
320 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
321 final DisplayContent displayContent = getDisplayContent(displayId);
322 if (displayContent == null) {
323 throw new IllegalArgumentException("Display not found for id: " + displayId);
324 }
325
326 final Configuration currentConfig = displayContent.getOverrideConfiguration();
327 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
328 if (!configChanged) {
329 return null;
330 }
Bryce Leeaea60d22018-01-31 14:42:15 -0800331
Andrii Kuliand68501e2017-01-10 22:57:27 -0800332 displayContent.onOverrideConfigurationChanged(newConfiguration);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700333
Bryce Leeaea60d22018-01-31 14:42:15 -0800334 mTmpStackList.clear();
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700335 if (displayId == DEFAULT_DISPLAY) {
336 // Override configuration of the default display duplicates global config. In this case
337 // we also want to update the global config.
Bryce Leeaea60d22018-01-31 14:42:15 -0800338 setGlobalConfigurationIfNeeded(newConfiguration, mTmpStackList);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700339 } else {
Bryce Leeaea60d22018-01-31 14:42:15 -0800340 updateStackBoundsAfterConfigChange(displayId, mTmpStackList);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700341 }
Bryce Leeaea60d22018-01-31 14:42:15 -0800342
343 mTmpStackIds.clear();
344 final int stackCount = mTmpStackList.size();
345
346 for (int i = 0; i < stackCount; ++i) {
347 final TaskStack stack = mTmpStackList.get(i);
348
349 // We only include stacks that are not marked for removal as they do not exist outside
350 // of WindowManager at this point.
351 if (!stack.mDeferRemoval) {
352 mTmpStackIds.add(stack.mStackId);
353 }
354 }
355
356 return mTmpStackIds.isEmpty() ? null : ArrayUtils.convertToIntArray(mTmpStackIds);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700357 }
358
Bryce Leeaea60d22018-01-31 14:42:15 -0800359 private void setGlobalConfigurationIfNeeded(Configuration newConfiguration,
360 List<TaskStack> changedStacks) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700361 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
362 if (!configChanged) {
Bryce Leeaea60d22018-01-31 14:42:15 -0800363 return;
Andrii Kulian441e4492016-09-29 15:25:00 -0700364 }
365 onConfigurationChanged(newConfiguration);
Bryce Leeaea60d22018-01-31 14:42:15 -0800366 updateStackBoundsAfterConfigChange(changedStacks);
Andrii Kulian441e4492016-09-29 15:25:00 -0700367 }
368
369 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -0700370 public void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700371 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700372 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700373
374 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700375 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700376
Andrii Kulian441e4492016-09-29 15:25:00 -0700377 /**
378 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
379 * bounds were updated.
380 */
Bryce Leeaea60d22018-01-31 14:42:15 -0800381 private void updateStackBoundsAfterConfigChange(List<TaskStack> changedStacks) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700382 final int numDisplays = mChildren.size();
383 for (int i = 0; i < numDisplays; ++i) {
384 final DisplayContent dc = mChildren.get(i);
Bryce Leeaea60d22018-01-31 14:42:15 -0800385 dc.updateStackBoundsAfterConfigChange(changedStacks);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700386 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700387 }
388
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700389 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
Bryce Leeaea60d22018-01-31 14:42:15 -0800390 private void updateStackBoundsAfterConfigChange(int displayId, List<TaskStack> changedStacks) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700391 final DisplayContent dc = getDisplayContent(displayId);
Bryce Leeaea60d22018-01-31 14:42:15 -0800392 dc.updateStackBoundsAfterConfigChange(changedStacks);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700393 }
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 Ogunwale68278562017-09-23 17:13:55 -0700401 TaskStack getStack(int windowingMode, int activityType) {
402 for (int i = mChildren.size() - 1; i >= 0; i--) {
403 final DisplayContent dc = mChildren.get(i);
404 final TaskStack stack = dc.getStack(windowingMode, activityType);
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
Suprabh Shukla69c71422018-04-02 18:39:01 -0700420 void updateHiddenWhileSuspendedState(final ArraySet<String> packages, final boolean suspended) {
421 forAllWindows((w) -> {
422 if (packages.contains(w.getOwningPackage())) {
423 w.setHiddenWhileSuspended(suspended);
424 }
425 }, false);
426 }
427
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700428 void updateAppOpsState() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800429 forAllWindows((w) -> {
Svet Ganovf7b47252018-02-26 11:11:27 -0800430 w.updateAppOpsState();
Wale Ogunwaled1880962016-11-08 10:31:59 -0800431 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700432 }
433
434 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800435 final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw());
436 return win != null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700437 }
438
439 void closeSystemDialogs(String reason) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800440 mCloseSystemDialogsReason = reason;
441 forAllWindows(mCloseSystemDialogsConsumer, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700442 }
443
444 void removeReplacedWindows() {
445 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
446 mService.openSurfaceTransaction();
447 try {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800448 forAllWindows(sRemoveReplacedWindowsConsumer, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700449 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200450 mService.closeSurfaceTransaction("removeReplacedWindows");
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700451 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
452 }
453 }
454
455 boolean hasPendingLayoutChanges(WindowAnimator animator) {
456 boolean hasChanges = false;
457
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700458 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700459 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700460 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700461 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
462 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
463 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
464 }
465 if (pendingChanges != 0) {
466 hasChanges = true;
467 }
468 }
469
470 return hasChanges;
471 }
472
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700473 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
474 boolean secure) {
475 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
476 boolean leakedSurface = false;
477 boolean killedApps = false;
478
479 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
480 winAnimator.mSession.mPid, operation);
481
482 final long callingIdentity = Binder.clearCallingIdentity();
483 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700484 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700485 // we haven't left any dangling surfaces around.
486
487 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700488 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700489 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700490 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700491 }
492
493 if (!leakedSurface) {
494 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700495 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700496 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800497 mChildren.get(displayNdx).forAllWindows((w) -> {
498 if (mService.mForceRemoves.contains(w)) {
499 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700500 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800501 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700502 if (wsa.mSurfaceController != null) {
503 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
504 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800505 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700506
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700507 if (pidCandidates.size() > 0) {
508 int[] pids = new int[pidCandidates.size()];
509 for (int i = 0; i < pids.length; i++) {
510 pids[i] = pidCandidates.keyAt(i);
511 }
512 try {
513 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
514 killedApps = true;
515 }
516 } catch (RemoteException e) {
517 }
518 }
519 }
520 }
521
522 if (leakedSurface || killedApps) {
523 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
524 // app to request another one.
525 Slog.w(TAG_WM,
526 "Looks like we have reclaimed some memory, clearing surface for retry.");
527 if (surfaceController != null) {
528 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
529 "RECOVER DESTROY", false);
530 winAnimator.destroySurface();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800531 if (winAnimator.mWin.mAppToken != null
532 && winAnimator.mWin.mAppToken.getController() != null) {
533 winAnimator.mWin.mAppToken.getController().removeStartingWindow();
534 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700535 }
536
537 try {
538 winAnimator.mWin.mClient.dispatchGetNewSurface();
539 } catch (RemoteException e) {
540 }
541 }
542 } finally {
543 Binder.restoreCallingIdentity(callingIdentity);
544 }
545
546 return leakedSurface || killedApps;
547 }
548
549 // "Something has changed! Let's make it correct now."
550 // TODO: Super crazy long method that should be broken down...
551 void performSurfacePlacement(boolean recoveringMemory) {
552 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
553 + Debug.getCallers(3));
554
555 int i;
556 boolean updateInputWindowsNeeded = false;
557
558 if (mService.mFocusMayChange) {
559 mService.mFocusMayChange = false;
560 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
561 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
562 }
563
564 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700565 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700566 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700567 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800568 displayContent.setExitingTokensHasVisible(false);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700569 }
570
571 mHoldScreen = null;
572 mScreenBrightness = -1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700573 mUserActivityTimeout = -1;
574 mObscureApplicationContentOnSecondaryDisplays = false;
575 mSustainedPerformanceModeCurrent = false;
576 mService.mTransactionSequence++;
577
578 // TODO(multi-display):
579 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
580 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
581 final int defaultDw = defaultInfo.logicalWidth;
582 final int defaultDh = defaultInfo.logicalHeight;
583
584 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
585 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
586 mService.openSurfaceTransaction();
587 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700588 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700589 } catch (RuntimeException e) {
590 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
591 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200592 mService.closeSurfaceTransaction("performLayoutAndPlaceSurfaces");
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700593 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
594 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
595 }
596
Chavi Weingarten16d0d072018-02-12 23:50:28 +0000597 mService.mAnimator.executeAfterPrepareSurfacesRunnables();
598
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700599 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
600
601 // If we are ready to perform an app transition, check through all of the app tokens to be
602 // shown and see if they are ready to go.
603 if (mService.mAppTransition.isReady()) {
Jorim Jaggi82c17862018-02-21 17:50:18 +0100604 // This needs to be split into two expressions, as handleAppTransitionReadyLocked may
605 // modify dc.pendingLayoutChanges, which would get lost when writing
606 // defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked()
607 final int layoutChanges = surfacePlacer.handleAppTransitionReadyLocked();
608 defaultDisplay.pendingLayoutChanges |= layoutChanges;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700609 if (DEBUG_LAYOUT_REPEATS)
610 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
611 defaultDisplay.pendingLayoutChanges);
612 }
613
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200614 if (!isAppAnimating() && mService.mAppTransition.isRunning()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700615 // We have finished the animation of an app transition. To do this, we have delayed a
616 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
617 // token list reflects the correct Z-order, but the window list may now be out of sync
618 // with it. So here we will just rebuild the entire app window list. Fun!
619 defaultDisplay.pendingLayoutChanges |=
620 mService.handleAnimatingStoppedAndTransitionLocked();
621 if (DEBUG_LAYOUT_REPEATS)
622 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
623 defaultDisplay.pendingLayoutChanges);
624 }
625
Winson Chunge2d72172018-01-25 17:46:20 +0000626 // Defer starting the recents animation until the wallpaper has drawn
627 final RecentsAnimationController recentsAnimationController =
628 mService.getRecentsAnimationController();
629 if (recentsAnimationController != null) {
630 recentsAnimationController.checkAnimationReady(mWallpaperController);
631 }
632
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700633 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
David Stevensf833ba92017-03-16 19:00:20 -0700667 final ArraySet<DisplayContent> touchExcludeRegionUpdateDisplays = handleResizingWindows();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700668
669 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
670 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
671 if (mOrientationChangeComplete) {
672 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
673 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
674 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
675 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
676 }
677 mService.stopFreezingDisplayLocked();
678 }
679
680 // Destroy the surface of any windows that are no longer visible.
681 boolean wallpaperDestroyed = false;
682 i = mService.mDestroySurface.size();
683 if (i > 0) {
684 do {
685 i--;
686 WindowState win = mService.mDestroySurface.get(i);
687 win.mDestroying = false;
688 if (mService.mInputMethodWindow == win) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000689 mService.setInputMethodWindowLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700690 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700691 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700692 wallpaperDestroyed = true;
693 }
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200694 win.destroySurfaceUnchecked();
Robert Carrfa8edf82018-04-19 12:38:47 -0700695 win.mWinAnimator.destroyPreservedSurfaceLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700696 } while (i > 0);
697 mService.mDestroySurface.clear();
698 }
699
700 // Time to remove any exiting tokens?
701 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700702 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800703 displayContent.removeExistingTokensIfPossible();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700704 }
705
706 if (wallpaperDestroyed) {
707 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700708 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700709 }
710
711 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700712 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700713 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700714 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700715 }
716 }
717
718 // Finally update all input windows now that the window changes have stabilized.
719 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
720
721 mService.setHoldScreenLocked(mHoldScreen);
722 if (!mService.mDisplayFrozen) {
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200723 final int brightness = mScreenBrightness < 0 || mScreenBrightness > 1.0f
724 ? -1 : toBrightnessOverride(mScreenBrightness);
725
726 // Post these on a handler such that we don't call into power manager service while
727 // holding the window manager lock to avoid lock contention with power manager lock.
728 mHandler.obtainMessage(SET_SCREEN_BRIGHTNESS_OVERRIDE, brightness, 0).sendToTarget();
729 mHandler.obtainMessage(SET_USER_ACTIVITY_TIMEOUT, mUserActivityTimeout).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700730 }
731
732 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
733 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
734 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700735 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700736 (mSustainedPerformanceModeEnabled ? 1 : 0));
737 }
738
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700739 if (mUpdateRotation) {
740 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian48146fd2017-08-07 11:22:50 -0700741 // TODO(multi-display): Update rotation for different displays separately.
742 final int displayId = defaultDisplay.getDisplayId();
Robert Carrae606b42018-02-15 15:36:23 -0800743 if (defaultDisplay.updateRotationUnchecked()) {
Andrii Kulian48146fd2017-08-07 11:22:50 -0700744 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
745 } else {
746 mUpdateRotation = false;
747 }
748 // Update rotation of VR virtual display separately. Currently this is the only kind of
749 // secondary display that can be rotated because of the single-display limitations in
750 // PhoneWindowManager.
751 final DisplayContent vrDisplay = mService.mVr2dDisplayId != INVALID_DISPLAY
752 ? getDisplayContent(mService.mVr2dDisplayId) : null;
Robert Carrae606b42018-02-15 15:36:23 -0800753 if (vrDisplay != null && vrDisplay.updateRotationUnchecked()) {
Andrii Kulian48146fd2017-08-07 11:22:50 -0700754 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mService.mVr2dDisplayId)
755 .sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700756 }
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);
David Stevensf833ba92017-03-16 19:00:20 -0700797 if (touchExcludeRegionUpdateDisplays != null) {
798 final DisplayContent focusedDc = mService.mFocusedApp != null
799 ? mService.mFocusedApp.getDisplayContent() : null;
800 for (DisplayContent dc : touchExcludeRegionUpdateDisplays) {
801 // The focused DisplayContent was recalcuated in setFocusTaskRegionLocked
802 if (focusedDc != dc) {
803 dc.setTouchExcludeRegion(null /* focusedTask */);
804 }
805 }
806 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700807
808 // Check to see if we are now in a state where the screen should
809 // be enabled, because the window obscured flags have changed.
810 mService.enableScreenIfNeededLocked();
811
812 mService.scheduleAnimationLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700813
814 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
815 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
816 }
817
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700818 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
819 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700820 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700821 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700822
Andrii Kulian8ee72852017-03-10 10:36:45 -0800823 // TODO(multi-display): Support these features on secondary screens.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700824 if (mService.mWatermark != null) {
825 mService.mWatermark.positionSurface(defaultDw, defaultDh);
826 }
827 if (mService.mStrictModeFlash != null) {
828 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
829 }
830 if (mService.mCircularDisplayMask != null) {
Andrii Kulian8ee72852017-03-10 10:36:45 -0800831 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh,
832 mService.getDefaultDisplayRotation());
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700833 }
834 if (mService.mEmulatorDisplayOverlay != null) {
835 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
Andrii Kulian8ee72852017-03-10 10:36:45 -0800836 mService.getDefaultDisplayRotation());
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700837 }
838
839 boolean focusDisplayed = false;
840
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700841 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700842 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700843 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700844 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700845 }
846
847 if (focusDisplayed) {
848 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
849 }
850
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700851 // Give the display manager a chance to adjust properties like display rotation if it needs
852 // to.
Robert Carrae606b42018-02-15 15:36:23 -0800853 mService.mDisplayManagerInternal.performTraversal(mDisplayTransaction);
854 SurfaceControl.mergeToGlobalTransaction(mDisplayTransaction);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700855 }
856
857 /**
David Stevensf833ba92017-03-16 19:00:20 -0700858 * Handles resizing windows during surface placement.
859 *
860 * @return A set of any DisplayContent whose touch exclude region needs to be recalculated due
861 * to a tap-exclude window resizing, or null if no such DisplayContents were found.
862 */
863 private ArraySet<DisplayContent> handleResizingWindows() {
864 ArraySet<DisplayContent> touchExcludeRegionUpdateSet = null;
865 for (int i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
866 WindowState win = mService.mResizingWindows.get(i);
867 if (win.mAppFreezing) {
868 // Don't remove this window until rotation has completed.
869 continue;
870 }
871 win.reportResized();
872 mService.mResizingWindows.remove(i);
873 if (WindowManagerService.excludeWindowTypeFromTapOutTask(win.mAttrs.type)) {
874 final DisplayContent dc = win.getDisplayContent();
875 if (touchExcludeRegionUpdateSet == null) {
876 touchExcludeRegionUpdateSet = new ArraySet<>();
877 }
878 touchExcludeRegionUpdateSet.add(dc);
879 }
880 }
881 return touchExcludeRegionUpdateSet;
882 }
883
884 /**
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700885 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700886 * @param obscured True if there is a window on top of this obscuring the display.
887 * @param syswin System window?
888 * @return True when the display contains content to show the user. When false, the display
889 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700890 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700891 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700892 final WindowManager.LayoutParams attrs = w.mAttrs;
893 final int attrFlags = attrs.flags;
Aaron Whyte8cbdf042018-01-23 12:06:02 -0800894 final boolean onScreen = w.isOnScreen();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700895 final boolean canBeSeen = w.isDisplayedLw();
896 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700897 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700898
Aaron Whyte8cbdf042018-01-23 12:06:02 -0800899 if (DEBUG_KEEP_SCREEN_ON) {
900 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked w: " + w
901 + ", w.mHasSurface: " + w.mHasSurface
902 + ", w.isOnScreen(): " + onScreen
903 + ", w.isDisplayedLw(): " + w.isDisplayedLw()
904 + ", w.mAttrs.userActivityTimeout: " + w.mAttrs.userActivityTimeout);
905 }
906 if (w.mHasSurface && onScreen) {
907 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
908 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
909 if (DEBUG_KEEP_SCREEN_ON) {
910 Slog.d(TAG, "mUserActivityTimeout set to " + mUserActivityTimeout);
911 }
912 }
913 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700914 if (w.mHasSurface && canBeSeen) {
915 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
916 mHoldScreen = w.mSession;
917 mHoldScreenWindow = w;
918 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
919 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
Wale Ogunwale743fcc12017-06-06 21:36:50 +0000920 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
921 + Debug.getCallers(10));
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700922 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700923 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700924 mScreenBrightness = w.mAttrs.screenBrightness;
925 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700926
927 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700928 // This function assumes that the contents of the default display are processed first
929 // before secondary displays.
930 final DisplayContent displayContent = w.getDisplayContent();
931 if (displayContent != null && displayContent.isDefaultDisplay) {
932 // While a dream or keyguard is showing, obscure ordinary application content on
933 // secondary displays (by forcibly enabling mirroring unless there is other content
934 // we want to show) but still allow opaque keyguard dialogs to be shown.
935 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
936 mObscureApplicationContentOnSecondaryDisplays = true;
937 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700938 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700939 } else if (displayContent != null &&
940 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700941 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700942 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700943 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700944 }
945 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
946 mSustainedPerformanceModeCurrent = true;
947 }
948 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700949
950 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700951 }
952
953 boolean copyAnimToLayoutParams() {
954 boolean doRequest = false;
955
956 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
957 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
958 mUpdateRotation = true;
959 doRequest = true;
960 }
961 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
962 mWallpaperMayChange = true;
963 doRequest = true;
964 }
965 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
966 mWallpaperForceHidingChanged = true;
967 doRequest = true;
968 }
969 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
970 mOrientationChangeComplete = false;
971 } else {
972 mOrientationChangeComplete = true;
973 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
974 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
975 doRequest = true;
976 }
977 }
chaviw042059d2018-01-11 11:24:08 -0800978
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700979 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
980 mWallpaperActionPending = true;
981 }
982
983 return doRequest;
984 }
985
986 private static int toBrightnessOverride(float value) {
987 return (int)(value * PowerManager.BRIGHTNESS_ON);
988 }
989
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200990 private final class MyHandler extends Handler {
991
992 public MyHandler(Looper looper) {
993 super(looper);
994 }
995
996 @Override
997 public void handleMessage(Message msg) {
998 switch (msg.what) {
999 case SET_SCREEN_BRIGHTNESS_OVERRIDE:
1000 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
1001 msg.arg1);
1002 break;
1003 case SET_USER_ACTIVITY_TIMEOUT:
1004 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
1005 (Long) msg.obj);
1006 break;
1007 default:
1008 break;
1009 }
1010 }
1011 }
1012
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001013 void dumpDisplayContents(PrintWriter pw) {
1014 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
1015 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001016 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001017 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001018 final DisplayContent displayContent = mChildren.get(i);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001019 displayContent.dump(pw, " ", true /* dumpAll */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001020 }
1021 } else {
1022 pw.println(" NO DISPLAY");
1023 }
1024 }
1025
1026 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001027 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001028 return;
1029 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001030 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001031 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001032 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001033 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001034 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001035 pw.print(displayContent.getDisplayId());
1036 }
1037 }
1038 pw.println();
1039 }
1040
1041 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaled1880962016-11-08 10:31:59 -08001042 final int[] index = new int[1];
1043 forAllWindows((w) -> {
1044 if (windows == null || windows.contains(w)) {
1045 pw.println(" Window #" + index[0] + " " + w + ":");
1046 w.dump(pw, " ", dumpAll || windows != null);
1047 index[0] = index[0] + 1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001048 }
Wale Ogunwaled1880962016-11-08 10:31:59 -08001049 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001050 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001051
Wale Ogunwale02319a62016-09-26 15:21:22 -07001052 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1053 pw.println(" All tokens:");
1054 for (int i = mChildren.size() - 1; i >= 0; --i) {
1055 mChildren.get(i).dumpTokens(pw, dumpAll);
1056 }
1057 }
1058
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001059 @CallSuper
1060 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001061 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001062 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001063 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001064 if (mService.mDisplayReady) {
1065 final int count = mChildren.size();
1066 for (int i = 0; i < count; ++i) {
1067 final DisplayContent displayContent = mChildren.get(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001068 displayContent.writeToProto(proto, DISPLAYS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001069 }
1070 }
Adrian Roos4921ccf2017-09-28 16:54:06 +02001071 if (!trim) {
1072 forAllWindows((w) -> {
1073 w.writeIdentifierToProto(proto, WINDOWS);
1074 }, true);
1075 }
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001076 proto.end(token);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001077 }
1078
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001079 @Override
1080 String getName() {
1081 return "ROOT";
1082 }
Robert Carrb1579c82017-09-05 14:54:47 -07001083
1084 @Override
1085 void scheduleAnimation() {
1086 mService.scheduleAnimationLocked();
1087 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001088}