blob: 299fa05d0ed95d2efc3056badcd9e72da34ac099 [file] [log] [blame]
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.server.wm;
18
Wale Ogunwalee05f5012016-09-16 16:27:29 -070019import android.content.res.Configuration;
20import android.graphics.Rect;
Ruchi Kandoi0d434042016-10-03 09:12:02 -070021import android.hardware.power.V1_0.PowerHint;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070022import android.os.Binder;
23import android.os.Debug;
Wale Ogunwale02319a62016-09-26 15:21:22 -070024import android.os.IBinder;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070025import android.os.ParcelFileDescriptor;
26import android.os.PowerManager;
27import android.os.RemoteException;
28import android.os.SystemClock;
29import android.os.UserHandle;
30import android.provider.Settings;
31import android.util.EventLog;
32import android.util.Slog;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070033import android.util.SparseIntArray;
34import android.view.Display;
35import android.view.DisplayInfo;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070036import android.view.WindowManager;
37import com.android.internal.util.ArrayUtils;
38import com.android.server.EventLogTags;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070039
40import java.io.FileDescriptor;
41import java.io.PrintWriter;
42import java.util.ArrayList;
43
Wale Ogunwalef7cab102016-10-25 15:25:14 -070044import static android.app.AppOpsManager.MODE_ALLOWED;
45import static android.app.AppOpsManager.MODE_DEFAULT;
46import static android.app.AppOpsManager.OP_NONE;
Wale Ogunwale02319a62016-09-26 15:21:22 -070047import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070048import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070049import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070050import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE;
51import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
52import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070053import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070054import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
55import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi879ff722016-11-04 18:08:17 -070056
Wale Ogunwalee05f5012016-09-16 16:27:29 -070057import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
58import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
59import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070060import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
61import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
62import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070063import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
64import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
65import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
66import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
67import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
68import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
69import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
70import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
71import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
72import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070073import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
74import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee05f5012016-09-16 16:27:29 -070075import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
76import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
77import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
78import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT;
79import static com.android.server.wm.WindowManagerService.logSurface;
80import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
81import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
82import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
83import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
84import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING;
85import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
86
87/** Root {@link WindowContainer} for the device. */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -070088class RootWindowContainer extends WindowContainer<DisplayContent> {
Wale Ogunwalee05f5012016-09-16 16:27:29 -070089 private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM;
90
91 WindowManagerService mService;
92
Wale Ogunwalee05f5012016-09-16 16:27:29 -070093 private boolean mWallpaperForceHidingChanged = false;
94 private Object mLastWindowFreezeSource = null;
95 private Session mHoldScreen = null;
96 private float mScreenBrightness = -1;
97 private float mButtonBrightness = -1;
98 private long mUserActivityTimeout = -1;
99 private boolean mUpdateRotation = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700100 // Following variables are for debugging screen wakelock only.
101 // Last window that requires screen wakelock
102 WindowState mHoldScreenWindow = null;
103 // Last window that obscures all windows below
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700104 WindowState mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700105 // Only set while traversing the default display based on its content.
106 // Affects the behavior of mirroring on secondary displays.
107 private boolean mObscureApplicationContentOnSecondaryDisplays = false;
108
109 private boolean mSustainedPerformanceModeEnabled = false;
110 private boolean mSustainedPerformanceModeCurrent = false;
111
112 boolean mWallpaperMayChange = false;
Robert Carr11c26c22016-09-23 12:40:27 -0700113 // During an orientation change, we track whether all windows have rendered
114 // at the new orientation, and this will be false from changing orientation until that occurs.
115 // For seamless rotation cases this always stays true, as the windows complete their orientation
116 // changes 1 by 1 without disturbing global state.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700117 boolean mOrientationChangeComplete = true;
118 boolean mWallpaperActionPending = false;
119
120 private final ArrayList<Integer> mChangedStackList = new ArrayList();
121
122 // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
123 // instances will be replaced with an instance that writes a binary representation of all
124 // commands to mSurfaceTraceFd.
125 boolean mSurfaceTraceEnabled;
126 ParcelFileDescriptor mSurfaceTraceFd;
127 RemoteEventTrace mRemoteEventTrace;
128
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700129 private final WindowLayersController mLayersController;
Wale Ogunwale0303c572016-10-20 10:16:29 -0700130 final WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700131
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700132 RootWindowContainer(WindowManagerService service) {
133 mService = service;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700134 mLayersController = new WindowLayersController(mService);
Wale Ogunwale0303c572016-10-20 10:16:29 -0700135 mWallpaperController = new WallpaperController(mService);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700136 }
137
138 WindowState computeFocusedWindow() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700139 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700140 for (int i = 0; i < count; i++) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700141 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700142 final WindowState win = dc.findFocusedWindow();
143 if (win != null) {
144 return win;
145 }
146 }
147 return null;
148 }
149
150 /**
151 * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
152 * there is a Display for the displayId.
153 *
154 * @param displayId The display the caller is interested in.
155 * @return The DisplayContent associated with displayId or null if there is no Display for it.
156 */
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700157 DisplayContent getDisplayContentOrCreate(int displayId) {
158 DisplayContent dc = getDisplayContent(displayId);
159
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700160 if (dc == null) {
161 final Display display = mService.mDisplayManager.getDisplay(displayId);
162 if (display != null) {
163 dc = createDisplayContent(display);
164 }
165 }
166 return dc;
167 }
168
Wale Ogunwale02319a62016-09-26 15:21:22 -0700169 DisplayContent getDisplayContent(int displayId) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700170 for (int i = mChildren.size() - 1; i >= 0; --i) {
171 final DisplayContent current = mChildren.get(i);
172 if (current.getDisplayId() == displayId) {
173 return current;
174 }
175 }
176 return null;
177 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700178
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700179 private DisplayContent createDisplayContent(final Display display) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700180 final DisplayContent dc = new DisplayContent(display, mService, mLayersController,
181 mWallpaperController);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700182 final int displayId = display.getDisplayId();
183
184 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display);
185 addChild(dc, null);
186
187 final DisplayInfo displayInfo = dc.getDisplayInfo();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700188 final Rect rect = new Rect();
189 mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect);
190 displayInfo.overscanLeft = rect.left;
191 displayInfo.overscanTop = rect.top;
192 displayInfo.overscanRight = rect.right;
193 displayInfo.overscanBottom = rect.bottom;
194 if (mService.mDisplayManagerInternal != null) {
195 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
196 displayId, displayInfo);
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700197 mService.configureDisplayPolicyLocked(dc);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700198
199 // TODO(multi-display): Create an input channel for each display with touch capability.
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700200 if (displayId == DEFAULT_DISPLAY) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700201 dc.mTapDetector = new TaskTapPointerEventListener(
202 mService, dc);
203 mService.registerPointerEventListener(dc.mTapDetector);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700204 mService.registerPointerEventListener(mService.mMousePositionTracker);
205 }
206 }
207
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700208 return dc;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700209 }
210
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700211 boolean isLayoutNeeded() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700212 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700213 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700214 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700215 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700216 return true;
217 }
218 }
219 return false;
220 }
221
222 void getWindows(WindowList output) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700223 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700224 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700225 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700226 dc.getWindows(output);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700227 }
228 }
229
230 void getWindows(WindowList output, boolean visibleOnly, boolean appsOnly) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700231 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700232 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700233 final ReadOnlyWindowList windowList = mChildren.get(displayNdx).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700234 for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
235 final WindowState w = windowList.get(winNdx);
236 if ((!visibleOnly || w.mWinAnimator.getShown())
237 && (!appsOnly || w.mAppToken != null)) {
238 output.add(w);
239 }
240 }
241 }
242 }
243
244 void getWindowsByName(WindowList output, String name) {
245 int objectId = 0;
246 // See if this is an object ID.
247 try {
248 objectId = Integer.parseInt(name, 16);
249 name = null;
250 } catch (RuntimeException e) {
251 }
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700252 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700253 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700254 final ReadOnlyWindowList windowList = mChildren.get(displayNdx).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700255 for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
256 final WindowState w = windowList.get(winNdx);
257 if (name != null) {
258 if (w.mAttrs.getTitle().toString().contains(name)) {
259 output.add(w);
260 }
261 } else if (System.identityHashCode(w) == objectId) {
262 output.add(w);
263 }
264 }
265 }
266 }
267
268 WindowState findWindow(int hashCode) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700269 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700270 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700271 final ReadOnlyWindowList windows = mChildren.get(displayNdx).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700272 final int numWindows = windows.size();
273 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
274 final WindowState w = windows.get(winNdx);
275 if (System.identityHashCode(w) == hashCode) {
276 return w;
277 }
278 }
279 }
280
281 return null;
282 }
283
Wale Ogunwale02319a62016-09-26 15:21:22 -0700284 /**
285 * Returns the app window token for the input binder if it exist in the system.
286 * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
287 * AppWindowToken represents an activity which can only exist on one display.
288 */
289 AppWindowToken getAppWindowToken(IBinder binder) {
290 for (int i = mChildren.size() - 1; i >= 0; --i) {
291 final DisplayContent dc = mChildren.get(i);
292 final AppWindowToken atoken = dc.getAppWindowToken(binder);
293 if (atoken != null) {
294 return atoken;
295 }
296 }
297 return null;
298 }
299
300 /** Returns the display object the input window token is currently mapped on. */
301 DisplayContent getWindowTokenDisplay(WindowToken token) {
302 if (token == null) {
303 return null;
304 }
305
306 for (int i = mChildren.size() - 1; i >= 0; --i) {
307 final DisplayContent dc = mChildren.get(i);
308 final WindowToken current = dc.getWindowToken(token.token);
309 if (current == token) {
310 return dc;
311 }
312 }
313
314 return null;
315 }
316
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700317 // TODO: Users would have their own window containers under the display container?
318 void switchUser() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700319 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700320 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700321 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700322 dc.switchUser();
323 }
324 }
325
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700326 /**
327 * Set new display override config and return array of ids of stacks that were changed during
328 * update. If called for the default display, global configuration will also be updated.
329 */
330 int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) {
331 final DisplayContent displayContent = getDisplayContent(displayId);
332 if (displayContent == null) {
333 throw new IllegalArgumentException("Display not found for id: " + displayId);
334 }
335
336 final Configuration currentConfig = displayContent.getOverrideConfiguration();
337 final boolean configChanged = currentConfig.diff(newConfiguration) != 0;
338 if (!configChanged) {
339 return null;
340 }
341 displayContent.onOverrideConfigurationChanged(currentConfig);
342
343 if (displayId == DEFAULT_DISPLAY) {
344 // Override configuration of the default display duplicates global config. In this case
345 // we also want to update the global config.
346 return setGlobalConfigurationIfNeeded(newConfiguration);
347 } else {
348 return updateStackBoundsAfterConfigChange(displayId);
349 }
350 }
351
352 private int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) {
Andrii Kulian441e4492016-09-29 15:25:00 -0700353 final boolean configChanged = getConfiguration().diff(newConfiguration) != 0;
354 if (!configChanged) {
355 return null;
356 }
357 onConfigurationChanged(newConfiguration);
358 return updateStackBoundsAfterConfigChange();
359 }
360
361 @Override
362 void onConfigurationChanged(Configuration newParentConfig) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700363 prepareFreezingTaskBounds();
Andrii Kulian441e4492016-09-29 15:25:00 -0700364 super.onConfigurationChanged(newParentConfig);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700365
366 mService.mPolicy.onConfigurationChanged();
Andrii Kulian441e4492016-09-29 15:25:00 -0700367 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700368
Andrii Kulian441e4492016-09-29 15:25:00 -0700369 /**
370 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
371 * bounds were updated.
372 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700373 private int[] updateStackBoundsAfterConfigChange() {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700374 mChangedStackList.clear();
375
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700376 final int numDisplays = mChildren.size();
377 for (int i = 0; i < numDisplays; ++i) {
378 final DisplayContent dc = mChildren.get(i);
Andrii Kulian441e4492016-09-29 15:25:00 -0700379 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700380 }
381
382 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
383 }
384
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700385 /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */
386 private int[] updateStackBoundsAfterConfigChange(int displayId) {
387 mChangedStackList.clear();
388
389 final DisplayContent dc = getDisplayContent(displayId);
390 dc.updateStackBoundsAfterConfigChange(mChangedStackList);
391
392 return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList);
393 }
394
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700395 private void prepareFreezingTaskBounds() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700396 for (int i = mChildren.size() - 1; i >= 0; i--) {
397 mChildren.get(i).prepareFreezingTaskBounds();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700398 }
399 }
400
401 void setSecureSurfaceState(int userId, boolean disabled) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700402 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700403 final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700404 for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
405 final WindowState win = windows.get(winNdx);
406 if (win.mHasSurface && userId == UserHandle.getUserId(win.mOwnerUid)) {
407 win.mWinAnimator.setSecureLocked(disabled);
408 }
409 }
410 }
411 }
412
413 void updateAppOpsState() {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700414 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700415 for (int i = 0; i < count; ++i) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700416 final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700417 final int numWindows = windows.size();
418 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
419 final WindowState win = windows.get(winNdx);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700420 if (win.mAppOp == OP_NONE) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700421 continue;
422 }
423 final int mode = mService.mAppOps.checkOpNoThrow(win.mAppOp, win.getOwningUid(),
424 win.getOwningPackage());
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700425 win.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700426 }
427 }
428 }
429
430 boolean canShowStrictModeViolation(int pid) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700431 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700432 for (int i = 0; i < count; ++i) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700433 final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700434 final int numWindows = windows.size();
435 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
436 final WindowState ws = windows.get(winNdx);
437 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
438 return true;
439 }
440 }
441 }
442 return false;
443 }
444
445 void closeSystemDialogs(String reason) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700446 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700447 for (int i = 0; i < count; ++i) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700448 final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700449 final int numWindows = windows.size();
450 for (int j = 0; j < numWindows; ++j) {
451 final WindowState w = windows.get(j);
452 if (w.mHasSurface) {
453 try {
454 w.mClient.closeSystemDialogs(reason);
455 } catch (RemoteException e) {
456 }
457 }
458 }
459 }
460 }
461
462 void removeReplacedWindows() {
463 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows");
464 mService.openSurfaceTransaction();
465 try {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700466 for (int i = mChildren.size() - 1; i >= 0; i--) {
467 DisplayContent dc = mChildren.get(i);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700468 final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700469 for (int j = windows.size() - 1; j >= 0; j--) {
470 final WindowState win = windows.get(j);
471 final AppWindowToken aToken = win.mAppToken;
472 if (aToken != null) {
473 aToken.removeReplacedWindowIfNeeded(win);
474 }
475 }
476 }
477 } finally {
478 mService.closeSurfaceTransaction();
479 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows");
480 }
481 }
482
483 boolean hasPendingLayoutChanges(WindowAnimator animator) {
484 boolean hasChanges = false;
485
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700486 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700487 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700488 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700489 final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId());
490 if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
491 animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
492 }
493 if (pendingChanges != 0) {
494 hasChanges = true;
495 }
496 }
497
498 return hasChanges;
499 }
500
501 void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700502 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700503 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700504 final DisplayContent dc = mChildren.get(i);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700505 dc.updateInputWindows(inputMonitor, inputFocus, inDrag);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700506 }
507 }
508
509 boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation,
510 boolean secure) {
511 final WindowSurfaceController surfaceController = winAnimator.mSurfaceController;
512 boolean leakedSurface = false;
513 boolean killedApps = false;
514
515 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
516 winAnimator.mSession.mPid, operation);
517
518 final long callingIdentity = Binder.clearCallingIdentity();
519 try {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700520 // There was some problem...first, do a sanity check of the window list to make sure
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700521 // we haven't left any dangling surfaces around.
522
523 Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks...");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700524 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700525 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700526 leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700527 }
528
529 if (!leakedSurface) {
530 Slog.w(TAG_WM, "No leaked surfaces; killing applications!");
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700531 final SparseIntArray pidCandidates = new SparseIntArray();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700532 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700533 final ReadOnlyWindowList windows =
534 mChildren.get(displayNdx).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700535 final int numWindows = windows.size();
536 for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
537 final WindowState ws = windows.get(winNdx);
538 if (mService.mForceRemoves.contains(ws)) {
539 continue;
540 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700541 final WindowStateAnimator wsa = ws.mWinAnimator;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700542 if (wsa.mSurfaceController != null) {
543 pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
544 }
545 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700546
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700547 if (pidCandidates.size() > 0) {
548 int[] pids = new int[pidCandidates.size()];
549 for (int i = 0; i < pids.length; i++) {
550 pids[i] = pidCandidates.keyAt(i);
551 }
552 try {
553 if (mService.mActivityManager.killPids(pids, "Free memory", secure)) {
554 killedApps = true;
555 }
556 } catch (RemoteException e) {
557 }
558 }
559 }
560 }
561
562 if (leakedSurface || killedApps) {
563 // We managed to reclaim some memory, so get rid of the trouble surface and ask the
564 // app to request another one.
565 Slog.w(TAG_WM,
566 "Looks like we have reclaimed some memory, clearing surface for retry.");
567 if (surfaceController != null) {
568 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
569 "RECOVER DESTROY", false);
570 winAnimator.destroySurface();
571 mService.scheduleRemoveStartingWindowLocked(winAnimator.mWin.mAppToken);
572 }
573
574 try {
575 winAnimator.mWin.mClient.dispatchGetNewSurface();
576 } catch (RemoteException e) {
577 }
578 }
579 } finally {
580 Binder.restoreCallingIdentity(callingIdentity);
581 }
582
583 return leakedSurface || killedApps;
584 }
585
586 // "Something has changed! Let's make it correct now."
587 // TODO: Super crazy long method that should be broken down...
588 void performSurfacePlacement(boolean recoveringMemory) {
589 if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by "
590 + Debug.getCallers(3));
591
592 int i;
593 boolean updateInputWindowsNeeded = false;
594
595 if (mService.mFocusMayChange) {
596 mService.mFocusMayChange = false;
597 updateInputWindowsNeeded = mService.updateFocusedWindowLocked(
598 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
599 }
600
601 // Initialize state of exiting tokens.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700602 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700603 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700604 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700605 for (i = displayContent.mExitingTokens.size() - 1; i >= 0; i--) {
606 displayContent.mExitingTokens.get(i).hasVisible = false;
607 }
608 }
609
610 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
611 // Initialize state of exiting applications.
612 final AppTokenList exitingAppTokens =
613 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
614 for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
615 exitingAppTokens.get(tokenNdx).hasVisible = false;
616 }
617 }
618
619 mHoldScreen = null;
620 mScreenBrightness = -1;
621 mButtonBrightness = -1;
622 mUserActivityTimeout = -1;
623 mObscureApplicationContentOnSecondaryDisplays = false;
624 mSustainedPerformanceModeCurrent = false;
625 mService.mTransactionSequence++;
626
627 // TODO(multi-display):
628 final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked();
629 final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
630 final int defaultDw = defaultInfo.logicalWidth;
631 final int defaultDh = defaultInfo.logicalHeight;
632
633 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
634 ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
635 mService.openSurfaceTransaction();
636 try {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700637 applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700638 } catch (RuntimeException e) {
639 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
640 } finally {
641 mService.closeSurfaceTransaction();
642 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
643 "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
644 }
645
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700646 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
647
648 // If we are ready to perform an app transition, check through all of the app tokens to be
649 // shown and see if they are ready to go.
650 if (mService.mAppTransition.isReady()) {
651 defaultDisplay.pendingLayoutChanges |=
Wale Ogunwale0303c572016-10-20 10:16:29 -0700652 surfacePlacer.handleAppTransitionReadyLocked();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700653 if (DEBUG_LAYOUT_REPEATS)
654 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
655 defaultDisplay.pendingLayoutChanges);
656 }
657
658 if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) {
659 // We have finished the animation of an app transition. To do this, we have delayed a
660 // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app
661 // token list reflects the correct Z-order, but the window list may now be out of sync
662 // with it. So here we will just rebuild the entire app window list. Fun!
663 defaultDisplay.pendingLayoutChanges |=
664 mService.handleAnimatingStoppedAndTransitionLocked();
665 if (DEBUG_LAYOUT_REPEATS)
666 surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock",
667 defaultDisplay.pendingLayoutChanges);
668 }
669
670 if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
671 && !mService.mAppTransition.isReady()) {
672 // At this point, there was a window with a wallpaper that was force hiding other
673 // windows behind it, but now it is going away. This may be simple -- just animate away
674 // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be
675 // shown behind something that was hidden.
676 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
677 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
678 "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges);
679 }
680 mWallpaperForceHidingChanged = false;
681
682 if (mWallpaperMayChange) {
683 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting");
684 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
685 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange",
686 defaultDisplay.pendingLayoutChanges);
687 }
688
689 if (mService.mFocusMayChange) {
690 mService.mFocusMayChange = false;
691 if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
692 false /*updateInputWindows*/)) {
693 updateInputWindowsNeeded = true;
694 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
695 }
696 }
697
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700698 if (isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700699 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
700 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded",
701 defaultDisplay.pendingLayoutChanges);
702 }
703
704 for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) {
705 WindowState win = mService.mResizingWindows.get(i);
706 if (win.mAppFreezing) {
707 // Don't remove this window until rotation has completed.
708 continue;
709 }
710 // Discard the saved surface if window size is changed, it can't be reused.
711 if (win.mAppToken != null) {
712 win.mAppToken.destroySavedSurfaces();
713 }
714 win.reportResized();
715 mService.mResizingWindows.remove(i);
716 }
717
718 if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG,
719 "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete);
720 if (mOrientationChangeComplete) {
721 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
722 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE;
723 mService.mLastFinishedFreezeSource = mLastWindowFreezeSource;
724 mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT);
725 }
726 mService.stopFreezingDisplayLocked();
727 }
728
729 // Destroy the surface of any windows that are no longer visible.
730 boolean wallpaperDestroyed = false;
731 i = mService.mDestroySurface.size();
732 if (i > 0) {
733 do {
734 i--;
735 WindowState win = mService.mDestroySurface.get(i);
736 win.mDestroying = false;
737 if (mService.mInputMethodWindow == win) {
738 mService.mInputMethodWindow = null;
739 }
Wale Ogunwale0303c572016-10-20 10:16:29 -0700740 if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700741 wallpaperDestroyed = true;
742 }
743 win.destroyOrSaveSurface();
744 } while (i > 0);
745 mService.mDestroySurface.clear();
746 }
747
748 // Time to remove any exiting tokens?
749 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700750 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700751 ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens;
752 for (i = exitingTokens.size() - 1; i >= 0; i--) {
753 WindowToken token = exitingTokens.get(i);
754 if (!token.hasVisible) {
755 exitingTokens.remove(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700756 }
757 }
758 }
759
760 // Time to remove any exiting applications?
761 for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
762 // Initialize state of exiting applications.
763 final AppTokenList exitingAppTokens =
764 mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
765 for (i = exitingAppTokens.size() - 1; i >= 0; i--) {
766 final AppWindowToken token = exitingAppTokens.get(i);
767 if (!token.hasVisible && !mService.mClosingApps.contains(token) &&
768 (!token.mIsExiting || token.isEmpty())) {
769 // Make sure there is no animation running on this token, so any windows
770 // associated with it will be removed as soon as their animations are complete
771 token.mAppAnimator.clearAnimation();
772 token.mAppAnimator.animating = false;
773 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
774 "performLayout: App token exiting now removed" + token);
775 token.removeIfPossible();
776 }
777 }
778 }
779
780 if (wallpaperDestroyed) {
781 defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700782 defaultDisplay.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700783 }
784
785 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700786 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700787 if (displayContent.pendingLayoutChanges != 0) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700788 displayContent.setLayoutNeeded();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700789 }
790 }
791
792 // Finally update all input windows now that the window changes have stabilized.
793 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
794
795 mService.setHoldScreenLocked(mHoldScreen);
796 if (!mService.mDisplayFrozen) {
797 if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) {
798 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
799 } else {
800 mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
801 toBrightnessOverride(mScreenBrightness));
802 }
803 if (mButtonBrightness < 0 || mButtonBrightness > 1.0f) {
804 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
805 } else {
806 mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
807 toBrightnessOverride(mButtonBrightness));
808 }
809 mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
810 mUserActivityTimeout);
811 }
812
813 if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
814 mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
815 mService.mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700816 PowerHint.SUSTAINED_PERFORMANCE,
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700817 (mSustainedPerformanceModeEnabled ? 1 : 0));
818 }
819
820 if (mService.mTurnOnScreen) {
821 if (mService.mAllowTheaterModeWakeFromLayout
822 || Settings.Global.getInt(mService.mContext.getContentResolver(),
823 Settings.Global.THEATER_MODE_ON, 0) == 0) {
824 if (DEBUG_VISIBILITY || DEBUG_POWER) {
825 Slog.v(TAG, "Turning screen on after layout!");
826 }
827 mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(),
828 "android.server.wm:TURN_ON");
829 }
830 mService.mTurnOnScreen = false;
831 }
832
833 if (mUpdateRotation) {
834 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700835 // TODO(multi-display): Update rotation for different displays separately.
836 final int displayId = defaultDisplay.getDisplayId();
837 if (mService.updateRotationUncheckedLocked(false, displayId)) {
838 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700839 } else {
840 mUpdateRotation = false;
841 }
842 }
843
844 if (mService.mWaitingForDrawnCallback != null ||
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700845 (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded()
846 && !mUpdateRotation)) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700847 mService.checkDrawnWindowsLocked();
848 }
849
850 final int N = mService.mPendingRemove.size();
851 if (N > 0) {
852 if (mService.mPendingRemoveTmp.length < N) {
853 mService.mPendingRemoveTmp = new WindowState[N+10];
854 }
855 mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
856 mService.mPendingRemove.clear();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700857 ArrayList<DisplayContent> displayList = new ArrayList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700858 for (i = 0; i < N; i++) {
859 final WindowState w = mService.mPendingRemoveTmp[i];
860 w.removeImmediately();
861 final DisplayContent displayContent = w.getDisplayContent();
862 if (displayContent != null && !displayList.contains(displayContent)) {
863 displayList.add(displayContent);
864 }
865 }
866
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700867 for (int j = displayList.size() - 1; j >= 0; --j) {
868 final DisplayContent dc = displayList.get(j);
869 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700870 }
871 }
872
873 // Remove all deferred displays stacks, tasks, and activities.
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700874 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
875 mChildren.get(displayNdx).checkCompleteDeferredRemoval();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700876 }
877
878 if (updateInputWindowsNeeded) {
879 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
880 }
881 mService.setFocusTaskRegionLocked();
882
883 // Check to see if we are now in a state where the screen should
884 // be enabled, because the window obscured flags have changed.
885 mService.enableScreenIfNeededLocked();
886
887 mService.scheduleAnimationLocked();
888 mService.mWindowPlacerLocked.destroyPendingSurfaces();
889
890 if (DEBUG_WINDOW_TRACE) Slog.e(TAG,
891 "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating());
892 }
893
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700894 private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw,
895 int defaultDh) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700896 mHoldScreenWindow = null;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700897 mObscuringWindow = null;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700898
899 if (mService.mWatermark != null) {
900 mService.mWatermark.positionSurface(defaultDw, defaultDh);
901 }
902 if (mService.mStrictModeFlash != null) {
903 mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh);
904 }
905 if (mService.mCircularDisplayMask != null) {
906 mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh, mService.mRotation);
907 }
908 if (mService.mEmulatorDisplayOverlay != null) {
909 mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh,
910 mService.mRotation);
911 }
912
913 boolean focusDisplayed = false;
914
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700915 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700916 for (int j = 0; j < count; ++j) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -0700917 final DisplayContent dc = mChildren.get(j);
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700918 focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory);
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700919 }
920
921 if (focusDisplayed) {
922 mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS);
923 }
924
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700925 // Give the display manager a chance to adjust properties like display rotation if it needs
926 // to.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700927 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
928 }
929
930 /**
931 * @param w WindowState this method is applied to.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700932 * @param obscured True if there is a window on top of this obscuring the display.
933 * @param syswin System window?
934 * @return True when the display contains content to show the user. When false, the display
935 * manager may choose to mirror or blank the display.
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700936 */
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700937 boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700938 final WindowManager.LayoutParams attrs = w.mAttrs;
939 final int attrFlags = attrs.flags;
940 final boolean canBeSeen = w.isDisplayedLw();
941 final int privateflags = attrs.privateFlags;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700942 boolean displayHasContent = false;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700943
944 if (w.mHasSurface && canBeSeen) {
945 if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) {
946 mHoldScreen = w.mSession;
947 mHoldScreenWindow = w;
948 } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) {
949 Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding "
950 + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by"
951 + Debug.getCallers(10));
952 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700953 if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700954 mScreenBrightness = w.mAttrs.screenBrightness;
955 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700956 if (!syswin && w.mAttrs.buttonBrightness >= 0 && mButtonBrightness < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700957 mButtonBrightness = w.mAttrs.buttonBrightness;
958 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700959 if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700960 mUserActivityTimeout = w.mAttrs.userActivityTimeout;
961 }
962
963 final int type = attrs.type;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700964 // This function assumes that the contents of the default display are processed first
965 // before secondary displays.
966 final DisplayContent displayContent = w.getDisplayContent();
967 if (displayContent != null && displayContent.isDefaultDisplay) {
968 // While a dream or keyguard is showing, obscure ordinary application content on
969 // secondary displays (by forcibly enabling mirroring unless there is other content
970 // we want to show) but still allow opaque keyguard dialogs to be shown.
971 if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
972 mObscureApplicationContentOnSecondaryDisplays = true;
973 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700974 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700975 } else if (displayContent != null &&
976 (!mObscureApplicationContentOnSecondaryDisplays
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700977 || (obscured && type == TYPE_KEYGUARD_DIALOG))) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700978 // Allow full screen keyguard presentation dialogs to be seen.
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700979 displayHasContent = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700980 }
981 if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) {
982 mSustainedPerformanceModeCurrent = true;
983 }
984 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700985
986 return displayHasContent;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700987 }
988
989 boolean copyAnimToLayoutParams() {
990 boolean doRequest = false;
991
992 final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams;
993 if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) {
994 mUpdateRotation = true;
995 doRequest = true;
996 }
997 if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) {
998 mWallpaperMayChange = true;
999 doRequest = true;
1000 }
1001 if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) {
1002 mWallpaperForceHidingChanged = true;
1003 doRequest = true;
1004 }
1005 if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
1006 mOrientationChangeComplete = false;
1007 } else {
1008 mOrientationChangeComplete = true;
1009 mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource;
1010 if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) {
1011 doRequest = true;
1012 }
1013 }
1014 if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) {
1015 mService.mTurnOnScreen = true;
1016 }
1017 if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) {
1018 mWallpaperActionPending = true;
1019 }
1020
1021 return doRequest;
1022 }
1023
1024 private static int toBrightnessOverride(float value) {
1025 return (int)(value * PowerManager.BRIGHTNESS_ON);
1026 }
1027
1028 void enableSurfaceTrace(ParcelFileDescriptor pfd) {
1029 final FileDescriptor fd = pfd.getFileDescriptor();
1030 if (mSurfaceTraceEnabled) {
1031 disableSurfaceTrace();
1032 }
1033 mSurfaceTraceEnabled = true;
1034 mRemoteEventTrace = new RemoteEventTrace(mService, fd);
1035 mSurfaceTraceFd = pfd;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001036 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
1037 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001038 dc.enableSurfaceTrace(fd);
1039 }
1040 }
1041
1042 void disableSurfaceTrace() {
1043 mSurfaceTraceEnabled = false;
1044 mRemoteEventTrace = null;
1045 mSurfaceTraceFd = null;
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001046 for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
1047 final DisplayContent dc = mChildren.get(displayNdx);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001048 dc.disableSurfaceTrace();
1049 }
1050 }
1051
1052 void dumpDisplayContents(PrintWriter pw) {
1053 pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
1054 if (mService.mDisplayReady) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001055 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001056 for (int i = 0; i < count; ++i) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001057 final DisplayContent displayContent = mChildren.get(i);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001058 displayContent.dump(" ", pw);
1059 }
1060 } else {
1061 pw.println(" NO DISPLAY");
1062 }
1063 }
1064
1065 void dumpLayoutNeededDisplayIds(PrintWriter pw) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001066 if (!isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001067 return;
1068 }
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001069 pw.print(" mLayoutNeeded on displays=");
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001070 final int count = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001071 for (int displayNdx = 0; displayNdx < count; ++displayNdx) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001072 final DisplayContent displayContent = mChildren.get(displayNdx);
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001073 if (displayContent.isLayoutNeeded()) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001074 pw.print(displayContent.getDisplayId());
1075 }
1076 }
1077 pw.println();
1078 }
1079
1080 void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) {
Wale Ogunwaleeaabfab2016-09-16 17:19:52 -07001081 final int numDisplays = mChildren.size();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001082 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07001083 final ReadOnlyWindowList windowList = mChildren.get(displayNdx).getReadOnlyWindowList();
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001084 for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
1085 final WindowState w = windowList.get(winNdx);
1086 if (windows == null || windows.contains(w)) {
1087 pw.println(" Window #" + winNdx + " " + w + ":");
1088 w.dump(pw, " ", dumpAll || windows != null);
1089 }
1090 }
1091 }
1092 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001093
Wale Ogunwale02319a62016-09-26 15:21:22 -07001094 void dumpTokens(PrintWriter pw, boolean dumpAll) {
1095 pw.println(" All tokens:");
1096 for (int i = mChildren.size() - 1; i >= 0; --i) {
1097 mChildren.get(i).dumpTokens(pw, dumpAll);
1098 }
1099 }
1100
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001101 @Override
1102 String getName() {
1103 return "ROOT";
1104 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001105}