blob: a4f20b012576f170693e3a6c1b02297fc1807b33 [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;
32import android.os.SystemClock;
33import android.os.UserHandle;
34import android.provider.Settings;
David Stevensf833ba92017-03-16 19:00:20 -070035import android.util.ArraySet;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070036import android.util.EventLog;
37import android.util.Slog;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070038import android.util.SparseIntArray;
Steven Timotiusaf03df62017-07-18 16:56:43 -070039import android.util.proto.ProtoOutputStream;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070040import android.view.Display;
41import android.view.DisplayInfo;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070042import android.view.WindowManager;
Jorim Jaggi86c39f92017-05-02 18:02:46 +020043
Wale Ogunwalee05f5012016-09-16 16:27:29 -070044import com.android.internal.util.ArrayUtils;
45import com.android.server.EventLogTags;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070046
47import java.io.FileDescriptor;
48import java.io.PrintWriter;
49import java.util.ArrayList;
Bryce Leeaea60d22018-01-31 14:42:15 -080050import java.util.List;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080051import java.util.function.Consumer;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070052
Wale Ogunwalef7cab102016-10-25 15:25:14 -070053import static android.app.AppOpsManager.MODE_ALLOWED;
54import static android.app.AppOpsManager.MODE_DEFAULT;
55import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwale02319a62016-09-26 15:21:22 -070056import static android.view.Display.DEFAULT_DISPLAY;
Andrii Kulian48146fd2017-08-07 11:22:50 -070057import static android.view.Display.INVALID_DISPLAY;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070058import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070059import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070060import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
61import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
62import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Jorim Jaggi879ff722016-11-04 18:08:17 -070063
Adrian Roose99bc052017-11-20 17:55:31 +010064import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
65import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
66import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070067import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
68import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070069import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
70import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
71import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070072import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
73import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
74import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
75import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
76import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
77import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
78import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
79import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
80import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070081import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
82import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070083import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
84import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
85import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
86import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
87import static com.android.server.wm.WindowManagerService.logSurface;
88import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
89import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070090import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
91import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
92import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070093import static com.android.server.wm.proto.RootWindowContainerProto.DISPLAYS;
94import static com.android.server.wm.proto.RootWindowContainerProto.WINDOWS;
95import static com.android.server.wm.proto.RootWindowContainerProto.WINDOW_CONTAINER;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070096
97/** Root {@link WindowContainer} for the device. */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -070098class RootWindowContainer extends WindowContainer<DisplayContent> {
Wale Ogunwalee05f5012016-09-16 16:27:29 -070099 private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM;
100
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200101 private static final int SET_SCREEN_BRIGHTNESS_OVERRIDE = 1;
102 private static final int SET_USER_ACTIVITY_TIMEOUT = 2;
103
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700104 private boolean mWallpaperForceHidingChanged = false;
105 private Object mLastWindowFreezeSource = null;
106 private Session mHoldScreen = null;
107 private float mScreenBrightness = -1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700108 private long mUserActivityTimeout = -1;
109 private boolean mUpdateRotation = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700110 // Following variables are for debugging screen wakelock only.
111 // Last window that requires screen wakelock
112 WindowState mHoldScreenWindow = null;
113 // Last window that obscures all windows below
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700114 WindowState mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700115 // Only set while traversing the default display based on its content.
116 // Affects the behavior of mirroring on secondary displays.
117 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
118
119 private boolean mSustainedPerformanceModeEnabled = false;
120 private boolean mSustainedPerformanceModeCurrent = false;
121
122 boolean mWallpaperMayChange = false;
Robert Carr11c26c22016-09-23 12:40:27 -0700123 // During an orientation change, we track whether all windows have rendered
124 // at the new orientation, and this will be false from changing orientation until that occurs.
125 // For seamless rotation cases this always stays true, as the windows complete their orientation
126 // changes 1 by 1 without disturbing global state.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700127 boolean mOrientationChangeComplete = true;
128 boolean mWallpaperActionPending = false;
129
Bryce Leeaea60d22018-01-31 14:42:15 -0800130 private final ArrayList<TaskStack> mTmpStackList = new ArrayList();
131 private final ArrayList<Integer> mTmpStackIds = new ArrayList<>();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700132
133 // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
134 // instances will be replaced with an instance that writes a binary representation of all
135 // commands to mSurfaceTraceFd.
136 boolean mSurfaceTraceEnabled;
137 ParcelFileDescriptor mSurfaceTraceFd;
138 RemoteEventTrace mRemoteEventTrace;
139
Wale Ogunwale0303c572016-10-20 10:16:29 -0700140 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700141
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200142 private final Handler mHandler;
143
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800144 private String mCloseSystemDialogsReason;
145 private final Consumer<WindowState> mCloseSystemDialogsConsumer = w -> {
146 if (w.mHasSurface) {
147 try {
148 w.mClient.closeSystemDialogs(mCloseSystemDialogsReason);
149 } catch (RemoteException e) {
150 }
151 }
152 };
153
154 private static final Consumer<WindowState> sRemoveReplacedWindowsConsumer = w -> {
155 final AppWindowToken aToken = w.mAppToken;
156 if (aToken != null) {
157 aToken.removeReplacedWindowIfNeeded(w);
158 }
159 };
160
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700161 RootWindowContainer(WindowManagerService service) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100162 super(service);
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200163 mHandler = new MyHandler(service.mH.getLooper());
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
Wale Ogunwale02319a62016-09-26 15:21:22 -0700196 DisplayContent getDisplayContent(int displayId) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700197 for (int i = mChildren.size() - 1; i >= 0; --i) {
198 final DisplayContent current = mChildren.get(i);
199 if (current.getDisplayId() == displayId) {
200 return current;
201 }
202 }
203 return null;
204 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700205
Bryce Leef19cbe22018-02-02 15:09:21 -0800206 DisplayContent createDisplayContent(final Display display, DisplayWindowController controller) {
Bryce Lee1cddfdc2018-02-20 10:41:58 -0800207 final int displayId = display.getDisplayId();
208
209 // In select scenarios, it is possible that a DisplayContent will be created on demand
210 // rather than waiting for the controller. In this case, associate the controller and return
211 // the existing display.
212 final DisplayContent existing = getDisplayContent(displayId);
213
214 if (existing != null) {
215 existing.setController(controller);
216 return existing;
217 }
218
Bryce Leef19cbe22018-02-02 15:09:21 -0800219 final DisplayContent dc =
220 new DisplayContent(display, mService, mWallpaperController, controller);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700221
222 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700223
224 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700225 final Rect rect = new Rect();
226 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
227 displayInfo.overscanLeft = rect.left;
228 displayInfo.overscanTop = rect.top;
229 displayInfo.overscanRight = rect.right;
230 displayInfo.overscanBottom = rect.bottom;
231 if (mService.mDisplayManagerInternal != null) {
232 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
233 displayId, displayInfo);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000234 dc.configureDisplayPolicy();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700235
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700236 // Tap Listeners are supported for:
237 // 1. All physical displays (multi-display).
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -0700238 // 2. VirtualDisplays on VR, AA (and everything else).
239 if (mService.canDispatchPointerEvents()) {
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700240 if (DEBUG_DISPLAY) {
241 Slog.d(TAG,
242 "Registering PointerEventListener for DisplayId: " + displayId);
243 }
244 dc.mTapDetector = new TaskTapPointerEventListener(mService, dc);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700245 mService.registerPointerEventListener(dc.mTapDetector);
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700246 if (displayId == DEFAULT_DISPLAY) {
247 mService.registerPointerEventListener(mService.mMousePositionTracker);
248 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700249 }
250 }
251
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700252 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700253 }
254
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700255 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700256 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700257 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700258 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700259 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700260 return true;
261 }
262 }
263 return false;
264 }
265
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000266 void getWindowsByName(ArrayList<WindowState> output, String name) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700267 int objectId = 0;
268 // See if this is an object ID.
269 try {
270 objectId = Integer.parseInt(name, 16);
271 name = null;
272 } catch (RuntimeException e) {
273 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800274
275 getWindowsByName(output, name, objectId);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700276 }
277
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000278 private void getWindowsByName(ArrayList<WindowState> output, String name, int objectId) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800279 forAllWindows((w) -> {
280 if (name != null) {
281 if (w.mAttrs.getTitle().toString().contains(name)) {
282 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700283 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800284 } else if (System.identityHashCode(w) == objectId) {
285 output.add(w);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700286 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800287 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700288 }
289
Wale Ogunwale02319a62016-09-26 15:21:22 -0700290 /**
291 * Returns the app window token for the input binder if it exist in the system.
292 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
293 * AppWindowToken represents an activity which can only exist on one display.
294 */
295 AppWindowToken getAppWindowToken(IBinder binder) {
296 for (int i = mChildren.size() - 1; i >= 0; --i) {
297 final DisplayContent dc = mChildren.get(i);
298 final AppWindowToken atoken = dc.getAppWindowToken(binder);
299 if (atoken != null) {
300 return atoken;
301 }
302 }
303 return null;
304 }
305
306 /** Returns the display object the input window token is currently mapped on. */
307 DisplayContent getWindowTokenDisplay(WindowToken token) {
308 if (token == null) {
309 return null;
310 }
311
312 for (int i = mChildren.size() - 1; i >= 0; --i) {
313 final DisplayContent dc = mChildren.get(i);
314 final WindowToken current = dc.getWindowToken(token.token);
315 if (current == token) {
316 return dc;
317 }
318 }
319
320 return null;
321 }
322
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700323 /**
324 * Set new display override config and return array of ids of stacks that were changed during
Bryce Leeaea60d22018-01-31 14:42:15 -0800325 * update. If called for the default display, global configuration will also be updated. Stacks
326 * that are marked for deferred removal are excluded from the returned array.
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700327 */
328 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
329 final DisplayContent displayContent = getDisplayContent(displayId);
330 if (displayContent == null) {
331 throw new IllegalArgumentException("Display not found for id: " + displayId);
332 }
333
334 final Configuration currentConfig = displayContent.getOverrideConfiguration();
335 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
336 if (!configChanged) {
337 return null;
338 }
Bryce Leeaea60d22018-01-31 14:42:15 -0800339
Andrii Kuliand68501e2017-01-10 22:57:27 -0800340 displayContent.onOverrideConfigurationChanged(newConfiguration);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700341
Bryce Leeaea60d22018-01-31 14:42:15 -0800342 mTmpStackList.clear();
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700343 if (displayId == DEFAULT_DISPLAY) {
344 // Override configuration of the default display duplicates global config. In this case
345 // we also want to update the global config.
Bryce Leeaea60d22018-01-31 14:42:15 -0800346 setGlobalConfigurationIfNeeded(newConfiguration, mTmpStackList);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700347 } else {
Bryce Leeaea60d22018-01-31 14:42:15 -0800348 updateStackBoundsAfterConfigChange(displayId, mTmpStackList);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700349 }
Bryce Leeaea60d22018-01-31 14:42:15 -0800350
351 mTmpStackIds.clear();
352 final int stackCount = mTmpStackList.size();
353
354 for (int i = 0; i < stackCount; ++i) {
355 final TaskStack stack = mTmpStackList.get(i);
356
357 // We only include stacks that are not marked for removal as they do not exist outside
358 // of WindowManager at this point.
359 if (!stack.mDeferRemoval) {
360 mTmpStackIds.add(stack.mStackId);
361 }
362 }
363
364 return mTmpStackIds.isEmpty() ? null : ArrayUtils.convertToIntArray(mTmpStackIds);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700365 }
366
Bryce Leeaea60d22018-01-31 14:42:15 -0800367 private void setGlobalConfigurationIfNeeded(Configuration newConfiguration,
368 List<TaskStack> changedStacks) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700369 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
370 if (!configChanged) {
Bryce Leeaea60d22018-01-31 14:42:15 -0800371 return;
Andrii Kulian441e4492016-09-29 15:25:00 -0700372 }
373 onConfigurationChanged(newConfiguration);
Bryce Leeaea60d22018-01-31 14:42:15 -0800374 updateStackBoundsAfterConfigChange(changedStacks);
Andrii Kulian441e4492016-09-29 15:25:00 -0700375 }
376
377 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -0700378 public void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700379 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700380 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700381
382 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700383 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700384
Andrii Kulian441e4492016-09-29 15:25:00 -0700385 /**
386 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
387 * bounds were updated.
388 */
Bryce Leeaea60d22018-01-31 14:42:15 -0800389 private void updateStackBoundsAfterConfigChange(List<TaskStack> changedStacks) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700390 final int numDisplays = mChildren.size();
391 for (int i = 0; i < numDisplays; ++i) {
392 final DisplayContent dc = mChildren.get(i);
Bryce Leeaea60d22018-01-31 14:42:15 -0800393 dc.updateStackBoundsAfterConfigChange(changedStacks);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700394 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700395 }
396
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700397 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
Bryce Leeaea60d22018-01-31 14:42:15 -0800398 private void updateStackBoundsAfterConfigChange(int displayId, List<TaskStack> changedStacks) {
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700399 final DisplayContent dc = getDisplayContent(displayId);
Bryce Leeaea60d22018-01-31 14:42:15 -0800400 dc.updateStackBoundsAfterConfigChange(changedStacks);
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700401 }
402
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700403 private void prepareFreezingTaskBounds() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700404 for (int i = mChildren.size() - 1; i >= 0; i--) {
405 mChildren.get(i).prepareFreezingTaskBounds();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700406 }
407 }
408
Wale Ogunwale68278562017-09-23 17:13:55 -0700409 TaskStack getStack(int windowingMode, int activityType) {
410 for (int i = mChildren.size() - 1; i >= 0; i--) {
411 final DisplayContent dc = mChildren.get(i);
412 final TaskStack stack = dc.getStack(windowingMode, activityType);
413 if (stack != null) {
414 return stack;
415 }
416 }
417 return null;
418 }
419
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700420 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800421 forAllWindows((w) -> {
422 if (w.mHasSurface && userId == UserHandle.getUserId(w.mOwnerUid)) {
423 w.mWinAnimator.setSecureLocked(disabled);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700424 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800425 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700426 }
427
428 void updateAppOpsState() {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800429 forAllWindows((w) -> {
430 if (w.mAppOp == OP_NONE) {
431 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700432 }
Peter Visontay96449f62017-12-11 18:50:03 +0000433 final int mode = mService.mAppOps.noteOpNoThrow(w.mAppOp, w.getOwningUid(),
Wale Ogunwaled1880962016-11-08 10:31:59 -0800434 w.getOwningPackage());
435 w.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
436 }, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700437 }
438
439 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800440 final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw());
441 return win != null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700442 }
443
444 void closeSystemDialogs(String reason) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800445 mCloseSystemDialogsReason = reason;
446 forAllWindows(mCloseSystemDialogsConsumer, false /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700447 }
448
449 void removeReplacedWindows() {
450 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
451 mService.openSurfaceTransaction();
452 try {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800453 forAllWindows(sRemoveReplacedWindowsConsumer, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700454 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200455 mService.closeSurfaceTransaction("removeReplacedWindows");
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700456 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
457 }
458 }
459
460 boolean hasPendingLayoutChanges(WindowAnimator animator) {
461 boolean hasChanges = false;
462
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700463 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700464 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700465 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700466 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
467 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
468 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
469 }
470 if (pendingChanges != 0) {
471 hasChanges = true;
472 }
473 }
474
475 return hasChanges;
476 }
477
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700478 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
479 boolean secure) {
480 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
481 boolean leakedSurface = false;
482 boolean killedApps = false;
483
484 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
485 winAnimator.mSession.mPid, operation);
486
487 final long callingIdentity = Binder.clearCallingIdentity();
488 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700489 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700490 // we haven't left any dangling surfaces around.
491
492 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700493 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700494 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700495 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700496 }
497
498 if (!leakedSurface) {
499 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700500 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700501 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaled1880962016-11-08 10:31:59 -0800502 mChildren.get(displayNdx).forAllWindows((w) -> {
503 if (mService.mForceRemoves.contains(w)) {
504 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700505 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800506 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700507 if (wsa.mSurfaceController != null) {
508 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
509 }
Wale Ogunwaled1880962016-11-08 10:31:59 -0800510 }, false /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700511
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700512 if (pidCandidates.size() > 0) {
513 int[] pids = new int[pidCandidates.size()];
514 for (int i = 0; i < pids.length; i++) {
515 pids[i] = pidCandidates.keyAt(i);
516 }
517 try {
518 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
519 killedApps = true;
520 }
521 } catch (RemoteException e) {
522 }
523 }
524 }
525 }
526
527 if (leakedSurface || killedApps) {
528 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
529 // app to request another one.
530 Slog.w(TAG_WM,
531 "Looks like we have reclaimed some memory, clearing surface for retry.");
532 if (surfaceController != null) {
533 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
534 "RECOVER DESTROY", false);
535 winAnimator.destroySurface();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800536 if (winAnimator.mWin.mAppToken != null
537 && winAnimator.mWin.mAppToken.getController() != null) {
538 winAnimator.mWin.mAppToken.getController().removeStartingWindow();
539 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700540 }
541
542 try {
543 winAnimator.mWin.mClient.dispatchGetNewSurface();
544 } catch (RemoteException e) {
545 }
546 }
547 } finally {
548 Binder.restoreCallingIdentity(callingIdentity);
549 }
550
551 return leakedSurface || killedApps;
552 }
553
554 // "Something has changed! Let's make it correct now."
555 // TODO: Super crazy long method that should be broken down...
556 void performSurfacePlacement(boolean recoveringMemory) {
557 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
558 + Debug.getCallers(3));
559
560 int i;
561 boolean updateInputWindowsNeeded = false;
562
563 if (mService.mFocusMayChange) {
564 mService.mFocusMayChange = false;
565 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
566 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
567 }
568
569 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700570 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700571 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700572 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800573 displayContent.setExitingTokensHasVisible(false);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700574 }
575
576 mHoldScreen = null;
577 mScreenBrightness = -1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700578 mUserActivityTimeout = -1;
579 mObscureApplicationContentOnSecondaryDisplays = false;
580 mSustainedPerformanceModeCurrent = false;
581 mService.mTransactionSequence++;
582
583 // TODO(multi-display):
584 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
585 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
586 final int defaultDw = defaultInfo.logicalWidth;
587 final int defaultDh = defaultInfo.logicalHeight;
588
589 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
590 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
591 mService.openSurfaceTransaction();
592 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700593 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700594 } catch (RuntimeException e) {
595 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
596 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200597 mService.closeSurfaceTransaction("performLayoutAndPlaceSurfaces");
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700598 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
599 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
600 }
601
Chavi Weingarten16d0d072018-02-12 23:50:28 +0000602 mService.mAnimator.executeAfterPrepareSurfacesRunnables();
603
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700604 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
605
606 // If we are ready to perform an app transition, check through all of the app tokens to be
607 // shown and see if they are ready to go.
608 if (mService.mAppTransition.isReady()) {
609 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700610 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700611 if (DEBUG_LAYOUT_REPEATS)
612 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
613 defaultDisplay.pendingLayoutChanges);
614 }
615
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200616 if (!isAppAnimating() && mService.mAppTransition.isRunning()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700617 // We have finished the animation of an app transition. To do this, we have delayed a
618 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
619 // token list reflects the correct Z-order, but the window list may now be out of sync
620 // with it. So here we will just rebuild the entire app window list. Fun!
621 defaultDisplay.pendingLayoutChanges |=
622 mService.handleAnimatingStoppedAndTransitionLocked();
623 if (DEBUG_LAYOUT_REPEATS)
624 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
625 defaultDisplay.pendingLayoutChanges);
626 }
627
Winson Chunge2d72172018-01-25 17:46:20 +0000628 // Defer starting the recents animation until the wallpaper has drawn
629 final RecentsAnimationController recentsAnimationController =
630 mService.getRecentsAnimationController();
631 if (recentsAnimationController != null) {
632 recentsAnimationController.checkAnimationReady(mWallpaperController);
633 }
634
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700635 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
636 && !mService.mAppTransition.isReady()) {
637 // At this point, there was a window with a wallpaper that was force hiding other
638 // windows behind it, but now it is going away. This may be simple -- just animate away
639 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
640 // shown behind something that was hidden.
641 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
642 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
643 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
644 }
645 mWallpaperForceHidingChanged = false;
646
647 if (mWallpaperMayChange) {
648 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
649 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
650 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
651 defaultDisplay.pendingLayoutChanges);
652 }
653
654 if (mService.mFocusMayChange) {
655 mService.mFocusMayChange = false;
656 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
657 false /*updateInputWindows*/)) {
658 updateInputWindowsNeeded = true;
659 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
660 }
661 }
662
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700663 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700664 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
665 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
666 defaultDisplay.pendingLayoutChanges);
667 }
668
David Stevensf833ba92017-03-16 19:00:20 -0700669 final ArraySet<DisplayContent> touchExcludeRegionUpdateDisplays = handleResizingWindows();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700670
671 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
672 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
673 if (mOrientationChangeComplete) {
674 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
675 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
676 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
677 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
678 }
679 mService.stopFreezingDisplayLocked();
680 }
681
682 // Destroy the surface of any windows that are no longer visible.
683 boolean wallpaperDestroyed = false;
684 i = mService.mDestroySurface.size();
685 if (i > 0) {
686 do {
687 i--;
688 WindowState win = mService.mDestroySurface.get(i);
689 win.mDestroying = false;
690 if (mService.mInputMethodWindow == win) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000691 mService.setInputMethodWindowLocked(null);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700692 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700693 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700694 wallpaperDestroyed = true;
695 }
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200696 win.destroySurfaceUnchecked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700697 } while (i > 0);
698 mService.mDestroySurface.clear();
699 }
700
701 // Time to remove any exiting tokens?
702 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700703 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800704 displayContent.removeExistingTokensIfPossible();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700705 }
706
707 if (wallpaperDestroyed) {
708 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700709 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700710 }
711
712 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700713 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700714 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700715 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700716 }
717 }
718
719 // Finally update all input windows now that the window changes have stabilized.
720 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
721
722 mService.setHoldScreenLocked(mHoldScreen);
723 if (!mService.mDisplayFrozen) {
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200724 final int brightness = mScreenBrightness < 0 || mScreenBrightness > 1.0f
725 ? -1 : toBrightnessOverride(mScreenBrightness);
726
727 // Post these on a handler such that we don't call into power manager service while
728 // holding the window manager lock to avoid lock contention with power manager lock.
729 mHandler.obtainMessage(SET_SCREEN_BRIGHTNESS_OVERRIDE, brightness, 0).sendToTarget();
730 mHandler.obtainMessage(SET_USER_ACTIVITY_TIMEOUT, mUserActivityTimeout).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700731 }
732
733 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
734 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
735 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700736 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700737 (mSustainedPerformanceModeEnabled ? 1 : 0));
738 }
739
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700740 if (mUpdateRotation) {
741 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian48146fd2017-08-07 11:22:50 -0700742 // TODO(multi-display): Update rotation for different displays separately.
743 final int displayId = defaultDisplay.getDisplayId();
744 if (defaultDisplay.updateRotationUnchecked(false /* inTransaction */)) {
745 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
746 } else {
747 mUpdateRotation = false;
748 }
749 // Update rotation of VR virtual display separately. Currently this is the only kind of
750 // secondary display that can be rotated because of the single-display limitations in
751 // PhoneWindowManager.
752 final DisplayContent vrDisplay = mService.mVr2dDisplayId != INVALID_DISPLAY
753 ? getDisplayContent(mService.mVr2dDisplayId) : null;
754 if (vrDisplay != null && vrDisplay.updateRotationUnchecked(false /* inTransaction */)) {
755 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mService.mVr2dDisplayId)
756 .sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700757 }
758 }
759
760 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700761 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
762 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700763 mService.checkDrawnWindowsLocked();
764 }
765
766 final int N = mService.mPendingRemove.size();
767 if (N > 0) {
768 if (mService.mPendingRemoveTmp.length < N) {
769 mService.mPendingRemoveTmp = new WindowState[N+10];
770 }
771 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
772 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700773 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700774 for (i = 0; i < N; i++) {
775 final WindowState w = mService.mPendingRemoveTmp[i];
776 w.removeImmediately();
777 final DisplayContent displayContent = w.getDisplayContent();
778 if (displayContent != null && !displayList.contains(displayContent)) {
779 displayList.add(displayContent);
780 }
781 }
782
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700783 for (int j = displayList.size() - 1; j >= 0; --j) {
784 final DisplayContent dc = displayList.get(j);
785 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700786 }
787 }
788
789 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700790 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
791 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700792 }
793
794 if (updateInputWindowsNeeded) {
795 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
796 }
David Stevensee9e2772017-02-09 16:30:27 -0800797 mService.setFocusTaskRegionLocked(null);
David Stevensf833ba92017-03-16 19:00:20 -0700798 if (touchExcludeRegionUpdateDisplays != null) {
799 final DisplayContent focusedDc = mService.mFocusedApp != null
800 ? mService.mFocusedApp.getDisplayContent() : null;
801 for (DisplayContent dc : touchExcludeRegionUpdateDisplays) {
802 // The focused DisplayContent was recalcuated in setFocusTaskRegionLocked
803 if (focusedDc != dc) {
804 dc.setTouchExcludeRegion(null /* focusedTask */);
805 }
806 }
807 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700808
809 // Check to see if we are now in a state where the screen should
810 // be enabled, because the window obscured flags have changed.
811 mService.enableScreenIfNeededLocked();
812
813 mService.scheduleAnimationLocked();
Chavi Weingarten38804382018-02-15 21:00:15 +0000814 mService.mWindowPlacerLocked.destroyPendingSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700815
816 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
817 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
818 }
819
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700820 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
821 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700822 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700823 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700824
Andrii Kulian8ee72852017-03-10 10:36:45 -0800825 // TODO(multi-display): Support these features on secondary screens.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700826 if (mService.mWatermark != null) {
827 mService.mWatermark.positionSurface(defaultDw, defaultDh);
828 }
829 if (mService.mStrictModeFlash != null) {
830 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
831 }
832 if (mService.mCircularDisplayMask != null) {
Andrii Kulian8ee72852017-03-10 10:36:45 -0800833 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh,
834 mService.getDefaultDisplayRotation());
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700835 }
836 if (mService.mEmulatorDisplayOverlay != null) {
837 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
Andrii Kulian8ee72852017-03-10 10:36:45 -0800838 mService.getDefaultDisplayRotation());
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700839 }
840
841 boolean focusDisplayed = false;
842
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700843 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700844 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700845 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700846 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700847 }
848
849 if (focusDisplayed) {
850 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
851 }
852
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700853 // Give the display manager a chance to adjust properties like display rotation if it needs
854 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700855 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
856 }
857
858 /**
David Stevensf833ba92017-03-16 19:00:20 -0700859 * Handles resizing windows during surface placement.
860 *
861 * @return A set of any DisplayContent whose touch exclude region needs to be recalculated due
862 * to a tap-exclude window resizing, or null if no such DisplayContents were found.
863 */
864 private ArraySet<DisplayContent> handleResizingWindows() {
865 ArraySet<DisplayContent> touchExcludeRegionUpdateSet = null;
866 for (int i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
867 WindowState win = mService.mResizingWindows.get(i);
868 if (win.mAppFreezing) {
869 // Don't remove this window until rotation has completed.
870 continue;
871 }
872 win.reportResized();
873 mService.mResizingWindows.remove(i);
874 if (WindowManagerService.excludeWindowTypeFromTapOutTask(win.mAttrs.type)) {
875 final DisplayContent dc = win.getDisplayContent();
876 if (touchExcludeRegionUpdateSet == null) {
877 touchExcludeRegionUpdateSet = new ArraySet<>();
878 }
879 touchExcludeRegionUpdateSet.add(dc);
880 }
881 }
882 return touchExcludeRegionUpdateSet;
883 }
884
885 /**
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700886 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700887 * @param obscured True if there is a window on top of this obscuring the display.
888 * @param syswin System window?
889 * @return True when the display contains content to show the user. When false, the display
890 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700891 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700892 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700893 final WindowManager.LayoutParams attrs = w.mAttrs;
894 final int attrFlags = attrs.flags;
Aaron Whyte8cbdf042018-01-23 12:06:02 -0800895 final boolean onScreen = w.isOnScreen();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700896 final boolean canBeSeen = w.isDisplayedLw();
897 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700898 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700899
Aaron Whyte8cbdf042018-01-23 12:06:02 -0800900 if (DEBUG_KEEP_SCREEN_ON) {
901 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked w: " + w
902 + ", w.mHasSurface: " + w.mHasSurface
903 + ", w.isOnScreen(): " + onScreen
904 + ", w.isDisplayedLw(): " + w.isDisplayedLw()
905 + ", w.mAttrs.userActivityTimeout: " + w.mAttrs.userActivityTimeout);
906 }
907 if (w.mHasSurface && onScreen) {
908 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
909 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
910 if (DEBUG_KEEP_SCREEN_ON) {
911 Slog.d(TAG, "mUserActivityTimeout set to " + mUserActivityTimeout);
912 }
913 }
914 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700915 if (w.mHasSurface && canBeSeen) {
916 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
917 mHoldScreen = w.mSession;
918 mHoldScreenWindow = w;
919 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
920 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
Wale Ogunwale743fcc12017-06-06 21:36:50 +0000921 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
922 + Debug.getCallers(10));
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700923 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700924 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700925 mScreenBrightness = w.mAttrs.screenBrightness;
926 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700927
928 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700929 // This function assumes that the contents of the default display are processed first
930 // before secondary displays.
931 final DisplayContent displayContent = w.getDisplayContent();
932 if (displayContent != null && displayContent.isDefaultDisplay) {
933 // While a dream or keyguard is showing, obscure ordinary application content on
934 // secondary displays (by forcibly enabling mirroring unless there is other content
935 // we want to show) but still allow opaque keyguard dialogs to be shown.
936 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
937 mObscureApplicationContentOnSecondaryDisplays = true;
938 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700939 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700940 } else if (displayContent != null &&
941 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700942 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700943 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700944 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700945 }
946 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
947 mSustainedPerformanceModeCurrent = true;
948 }
949 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700950
951 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700952 }
953
954 boolean copyAnimToLayoutParams() {
955 boolean doRequest = false;
956
957 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
958 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
959 mUpdateRotation = true;
960 doRequest = true;
961 }
962 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
963 mWallpaperMayChange = true;
964 doRequest = true;
965 }
966 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
967 mWallpaperForceHidingChanged = true;
968 doRequest = true;
969 }
970 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
971 mOrientationChangeComplete = false;
972 } else {
973 mOrientationChangeComplete = true;
974 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
975 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
976 doRequest = true;
977 }
978 }
chaviw042059d2018-01-11 11:24:08 -0800979
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700980 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
981 mWallpaperActionPending = true;
982 }
983
984 return doRequest;
985 }
986
987 private static int toBrightnessOverride(float value) {
988 return (int)(value * PowerManager.BRIGHTNESS_ON);
989 }
990
Jorim Jaggi86c39f92017-05-02 18:02:46 +0200991 private final class MyHandler extends Handler {
992
993 public MyHandler(Looper looper) {
994 super(looper);
995 }
996
997 @Override
998 public void handleMessage(Message msg) {
999 switch (msg.what) {
1000 case SET_SCREEN_BRIGHTNESS_OVERRIDE:
1001 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
1002 msg.arg1);
1003 break;
1004 case SET_USER_ACTIVITY_TIMEOUT:
1005 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
1006 (Long) msg.obj);
1007 break;
1008 default:
1009 break;
1010 }
1011 }
1012 }
1013
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001014 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
1015 final FileDescriptor fd = pfd.getFileDescriptor();
1016 if (mSurfaceTraceEnabled) {
1017 disableSurfaceTrace();
1018 }
1019 mSurfaceTraceEnabled = true;
1020 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
1021 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001022 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
1023 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001024 dc.enableSurfaceTrace(fd);
1025 }
1026 }
1027
1028 void disableSurfaceTrace() {
1029 mSurfaceTraceEnabled = false;
1030 mRemoteEventTrace = null;
1031 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001032 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
1033 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001034 dc.disableSurfaceTrace();
1035 }
1036 }
1037
1038 void dumpDisplayContents(PrintWriter pw) {
1039 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
1040 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001041 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001042 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001043 final DisplayContent displayContent = mChildren.get(i);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001044 displayContent.dump(pw, " ", true /* dumpAll */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001045 }
1046 } else {
1047 pw.println(" NO DISPLAY");
1048 }
1049 }
1050
1051 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001052 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001053 return;
1054 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001055 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001056 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001057 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001058 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001059 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001060 pw.print(displayContent.getDisplayId());
1061 }
1062 }
1063 pw.println();
1064 }
1065
1066 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaled1880962016-11-08 10:31:59 -08001067 final int[] index = new int[1];
1068 forAllWindows((w) -> {
1069 if (windows == null || windows.contains(w)) {
1070 pw.println(" Window #" + index[0] + " " + w + ":");
1071 w.dump(pw, " ", dumpAll || windows != null);
1072 index[0] = index[0] + 1;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001073 }
Wale Ogunwaled1880962016-11-08 10:31:59 -08001074 }, true /* traverseTopToBottom */);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001075 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001076
Wale Ogunwale02319a62016-09-26 15:21:22 -07001077 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1078 pw.println(" All tokens:");
1079 for (int i = mChildren.size() - 1; i >= 0; --i) {
1080 mChildren.get(i).dumpTokens(pw, dumpAll);
1081 }
1082 }
1083
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001084 @CallSuper
1085 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001086 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001087 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001088 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001089 if (mService.mDisplayReady) {
1090 final int count = mChildren.size();
1091 for (int i = 0; i < count; ++i) {
1092 final DisplayContent displayContent = mChildren.get(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001093 displayContent.writeToProto(proto, DISPLAYS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001094 }
1095 }
Adrian Roos4921ccf2017-09-28 16:54:06 +02001096 if (!trim) {
1097 forAllWindows((w) -> {
1098 w.writeIdentifierToProto(proto, WINDOWS);
1099 }, true);
1100 }
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001101 proto.end(token);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001102 }
1103
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001104 @Override
1105 String getName() {
1106 return "ROOT";
1107 }
Robert Carrb1579c82017-09-05 14:54:47 -07001108
1109 @Override
1110 void scheduleAnimation() {
1111 mService.scheduleAnimationLocked();
1112 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001113}