Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
| 19 | import android.app.AppOpsManager; |
| 20 | import android.content.res.Configuration; |
| 21 | import android.graphics.Rect; |
| 22 | import android.os.Binder; |
| 23 | import android.os.Debug; |
| 24 | import android.os.ParcelFileDescriptor; |
| 25 | import android.os.PowerManager; |
| 26 | import android.os.RemoteException; |
| 27 | import android.os.SystemClock; |
| 28 | import android.os.UserHandle; |
| 29 | import android.provider.Settings; |
| 30 | import android.util.EventLog; |
| 31 | import android.util.Slog; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 32 | import android.util.SparseIntArray; |
| 33 | import android.view.Display; |
| 34 | import android.view.DisplayInfo; |
| 35 | import android.view.InputChannel; |
| 36 | import android.view.WindowManager; |
| 37 | import com.android.internal.util.ArrayUtils; |
| 38 | import com.android.server.EventLogTags; |
| 39 | import com.android.server.input.InputWindowHandle; |
| 40 | |
| 41 | import java.io.FileDescriptor; |
| 42 | import java.io.PrintWriter; |
| 43 | import java.util.ArrayList; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 44 | import java.util.LinkedList; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 45 | |
| 46 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 47 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 48 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 49 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 50 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE; |
| 51 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
| 52 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; |
| 53 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 54 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
| 55 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 56 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 57 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 58 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 59 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
| 60 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 61 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
| 62 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON; |
| 63 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
| 64 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
| 65 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 66 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER; |
| 67 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 68 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT; |
| 69 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 70 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
| 71 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE; |
| 72 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 73 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC; |
| 74 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 75 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON; |
| 76 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 77 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 78 | import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS; |
| 79 | import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION; |
| 80 | import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD; |
| 81 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES; |
| 82 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
| 83 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE; |
| 84 | import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT; |
| 85 | import static com.android.server.wm.WindowManagerService.logSurface; |
| 86 | import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED; |
| 87 | import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE; |
| 88 | import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN; |
| 89 | import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION; |
| 90 | import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING; |
| 91 | import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE; |
| 92 | |
| 93 | /** Root {@link WindowContainer} for the device. */ |
| 94 | // TODO: Several methods in here are accessing children of this container's children through various |
| 95 | // references (WindowList I am looking at you :/). See if we can delegate instead. |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 96 | class RootWindowContainer extends WindowContainer<DisplayContent> { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 97 | private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM; |
| 98 | |
| 99 | WindowManagerService mService; |
| 100 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 101 | private boolean mWallpaperForceHidingChanged = false; |
| 102 | private Object mLastWindowFreezeSource = null; |
| 103 | private Session mHoldScreen = null; |
| 104 | private float mScreenBrightness = -1; |
| 105 | private float mButtonBrightness = -1; |
| 106 | private long mUserActivityTimeout = -1; |
| 107 | private boolean mUpdateRotation = false; |
| 108 | private boolean mObscured = false; |
| 109 | boolean mSyswin = false; |
| 110 | // Set to true when the display contains content to show the user. |
| 111 | // When false, the display manager may choose to mirror or blank the display. |
| 112 | private boolean mDisplayHasContent = false; |
| 113 | private float mPreferredRefreshRate = 0; |
| 114 | private int mPreferredModeId = 0; |
| 115 | // Following variables are for debugging screen wakelock only. |
| 116 | // Last window that requires screen wakelock |
| 117 | WindowState mHoldScreenWindow = null; |
| 118 | // Last window that obscures all windows below |
| 119 | WindowState mObsuringWindow = null; |
| 120 | // Only set while traversing the default display based on its content. |
| 121 | // Affects the behavior of mirroring on secondary displays. |
| 122 | private boolean mObscureApplicationContentOnSecondaryDisplays = false; |
| 123 | |
| 124 | private boolean mSustainedPerformanceModeEnabled = false; |
| 125 | private boolean mSustainedPerformanceModeCurrent = false; |
| 126 | |
| 127 | boolean mWallpaperMayChange = false; |
Robert Carr | 11c26c2 | 2016-09-23 12:40:27 -0700 | [diff] [blame] | 128 | // During an orientation change, we track whether all windows have rendered |
| 129 | // at the new orientation, and this will be false from changing orientation until that occurs. |
| 130 | // For seamless rotation cases this always stays true, as the windows complete their orientation |
| 131 | // changes 1 by 1 without disturbing global state. |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 132 | boolean mOrientationChangeComplete = true; |
| 133 | boolean mWallpaperActionPending = false; |
| 134 | |
| 135 | private final ArrayList<Integer> mChangedStackList = new ArrayList(); |
| 136 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 137 | private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList(); |
| 138 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 139 | // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl |
| 140 | // instances will be replaced with an instance that writes a binary representation of all |
| 141 | // commands to mSurfaceTraceFd. |
| 142 | boolean mSurfaceTraceEnabled; |
| 143 | ParcelFileDescriptor mSurfaceTraceFd; |
| 144 | RemoteEventTrace mRemoteEventTrace; |
| 145 | |
| 146 | RootWindowContainer(WindowManagerService service) { |
| 147 | mService = service; |
| 148 | } |
| 149 | |
| 150 | WindowState computeFocusedWindow() { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 151 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 152 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 153 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 154 | final WindowState win = dc.findFocusedWindow(); |
| 155 | if (win != null) { |
| 156 | return win; |
| 157 | } |
| 158 | } |
| 159 | return null; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if |
| 164 | * there is a Display for the displayId. |
| 165 | * |
| 166 | * @param displayId The display the caller is interested in. |
| 167 | * @return The DisplayContent associated with displayId or null if there is no Display for it. |
| 168 | */ |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 169 | DisplayContent getDisplayContentOrCreate(int displayId) { |
| 170 | DisplayContent dc = getDisplayContent(displayId); |
| 171 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 172 | if (dc == null) { |
| 173 | final Display display = mService.mDisplayManager.getDisplay(displayId); |
| 174 | if (display != null) { |
| 175 | dc = createDisplayContent(display); |
| 176 | } |
| 177 | } |
| 178 | return dc; |
| 179 | } |
| 180 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 181 | private DisplayContent getDisplayContent(int displayId) { |
| 182 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 183 | final DisplayContent current = mChildren.get(i); |
| 184 | if (current.getDisplayId() == displayId) { |
| 185 | return current; |
| 186 | } |
| 187 | } |
| 188 | return null; |
| 189 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 190 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 191 | private DisplayContent createDisplayContent(final Display display) { |
| 192 | final DisplayContent dc = new DisplayContent(display, mService); |
| 193 | final int displayId = display.getDisplayId(); |
| 194 | |
| 195 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display); |
| 196 | addChild(dc, null); |
| 197 | |
| 198 | final DisplayInfo displayInfo = dc.getDisplayInfo(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 199 | final Rect rect = new Rect(); |
| 200 | mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect); |
| 201 | displayInfo.overscanLeft = rect.left; |
| 202 | displayInfo.overscanTop = rect.top; |
| 203 | displayInfo.overscanRight = rect.right; |
| 204 | displayInfo.overscanBottom = rect.bottom; |
| 205 | if (mService.mDisplayManagerInternal != null) { |
| 206 | mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager( |
| 207 | displayId, displayInfo); |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 208 | mService.configureDisplayPolicyLocked(dc); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 209 | |
| 210 | // TODO(multi-display): Create an input channel for each display with touch capability. |
| 211 | if (displayId == Display.DEFAULT_DISPLAY) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 212 | dc.mTapDetector = new TaskTapPointerEventListener( |
| 213 | mService, dc); |
| 214 | mService.registerPointerEventListener(dc.mTapDetector); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 215 | mService.registerPointerEventListener(mService.mMousePositionTracker); |
| 216 | } |
| 217 | } |
| 218 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 219 | return dc; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /** Adds the input stack id to the input display id and returns the bounds of the added stack.*/ |
| 223 | Rect addStackToDisplay(int stackId, int displayId, boolean onTop) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 224 | final DisplayContent dc = getDisplayContent(displayId); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 225 | if (dc == null) { |
| 226 | Slog.w(TAG_WM, "addStackToDisplay: Trying to add stackId=" + stackId |
| 227 | + " to unknown displayId=" + displayId + " callers=" + Debug.getCallers(6)); |
| 228 | return null; |
| 229 | } |
| 230 | |
| 231 | boolean attachedToDisplay = false; |
| 232 | TaskStack stack = mService.mStackIdToStack.get(stackId); |
| 233 | if (stack == null) { |
| 234 | if (DEBUG_STACK) Slog.d(TAG_WM, "attachStack: stackId=" + stackId); |
| 235 | |
| 236 | stack = dc.getStackById(stackId); |
| 237 | if (stack != null) { |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 238 | // It's already attached to the display...clear mDeferRemoval and move stack to |
| 239 | // appropriate z-order on display as needed. |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 240 | stack.mDeferRemoval = false; |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 241 | dc.moveStack(stack, onTop); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 242 | attachedToDisplay = true; |
| 243 | } else { |
| 244 | stack = new TaskStack(mService, stackId); |
| 245 | } |
| 246 | |
| 247 | mService.mStackIdToStack.put(stackId, stack); |
| 248 | if (stackId == DOCKED_STACK_ID) { |
| 249 | mService.getDefaultDisplayContentLocked().mDividerControllerLocked |
| 250 | .notifyDockedStackExistsChanged(true); |
| 251 | } |
| 252 | } |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 253 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 254 | if (!attachedToDisplay) { |
| 255 | stack.attachDisplayContent(dc); |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 256 | dc.attachStack(stack, onTop); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 257 | } |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 258 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 259 | if (stack.getRawFullscreen()) { |
| 260 | return null; |
| 261 | } |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 262 | final Rect bounds = new Rect(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 263 | stack.getRawBounds(bounds); |
| 264 | return bounds; |
| 265 | } |
| 266 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 267 | boolean isLayoutNeeded() { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 268 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 269 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 270 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 271 | if (displayContent.isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 272 | return true; |
| 273 | } |
| 274 | } |
| 275 | return false; |
| 276 | } |
| 277 | |
| 278 | void getWindows(WindowList output) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 279 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 280 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 281 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 282 | output.addAll(dc.getWindowList()); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void getWindows(WindowList output, boolean visibleOnly, boolean appsOnly) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 287 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 288 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 289 | final WindowList windowList = mChildren.get(displayNdx).getWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 290 | for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) { |
| 291 | final WindowState w = windowList.get(winNdx); |
| 292 | if ((!visibleOnly || w.mWinAnimator.getShown()) |
| 293 | && (!appsOnly || w.mAppToken != null)) { |
| 294 | output.add(w); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | void getWindowsByName(WindowList output, String name) { |
| 301 | int objectId = 0; |
| 302 | // See if this is an object ID. |
| 303 | try { |
| 304 | objectId = Integer.parseInt(name, 16); |
| 305 | name = null; |
| 306 | } catch (RuntimeException e) { |
| 307 | } |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 308 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 309 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 310 | final WindowList windowList = mChildren.get(displayNdx).getWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 311 | for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) { |
| 312 | final WindowState w = windowList.get(winNdx); |
| 313 | if (name != null) { |
| 314 | if (w.mAttrs.getTitle().toString().contains(name)) { |
| 315 | output.add(w); |
| 316 | } |
| 317 | } else if (System.identityHashCode(w) == objectId) { |
| 318 | output.add(w); |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | WindowState findWindow(int hashCode) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 325 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 326 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 327 | final WindowList windows = mChildren.get(displayNdx).getWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 328 | final int numWindows = windows.size(); |
| 329 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 330 | final WindowState w = windows.get(winNdx); |
| 331 | if (System.identityHashCode(w) == hashCode) { |
| 332 | return w; |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | return null; |
| 338 | } |
| 339 | |
| 340 | // TODO: Users would have their own window containers under the display container? |
| 341 | void switchUser() { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 342 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 343 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 344 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 345 | dc.switchUser(); |
| 346 | } |
| 347 | } |
| 348 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 349 | /** Set new config and return array of ids of stacks that were changed during update. */ |
| 350 | int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) { |
| 351 | final boolean configChanged = getConfiguration().diff(newConfiguration) != 0; |
| 352 | if (!configChanged) { |
| 353 | return null; |
| 354 | } |
| 355 | onConfigurationChanged(newConfiguration); |
| 356 | return updateStackBoundsAfterConfigChange(); |
| 357 | } |
| 358 | |
| 359 | @Override |
| 360 | void onConfigurationChanged(Configuration newParentConfig) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 361 | prepareFreezingTaskBounds(); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 362 | super.onConfigurationChanged(newParentConfig); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 363 | |
| 364 | mService.mPolicy.onConfigurationChanged(); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 365 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 366 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 367 | /** |
| 368 | * Callback used to trigger bounds update after configuration change and get ids of stacks whose |
| 369 | * bounds were updated. |
| 370 | */ |
| 371 | int[] updateStackBoundsAfterConfigChange() { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 372 | mChangedStackList.clear(); |
| 373 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 374 | final int numDisplays = mChildren.size(); |
| 375 | for (int i = 0; i < numDisplays; ++i) { |
| 376 | final DisplayContent dc = mChildren.get(i); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 377 | dc.updateStackBoundsAfterConfigChange(mChangedStackList); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList); |
| 381 | } |
| 382 | |
| 383 | private void prepareFreezingTaskBounds() { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 384 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 385 | mChildren.get(i).prepareFreezingTaskBounds(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
| 389 | void setSecureSurfaceState(int userId, boolean disabled) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 390 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 391 | final WindowList windows = mChildren.get(i).getWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 392 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 393 | final WindowState win = windows.get(winNdx); |
| 394 | if (win.mHasSurface && userId == UserHandle.getUserId(win.mOwnerUid)) { |
| 395 | win.mWinAnimator.setSecureLocked(disabled); |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | void updateAppOpsState() { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 402 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 403 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 404 | final WindowList windows = mChildren.get(i).getWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 405 | final int numWindows = windows.size(); |
| 406 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 407 | final WindowState win = windows.get(winNdx); |
| 408 | if (win.mAppOp == AppOpsManager.OP_NONE) { |
| 409 | continue; |
| 410 | } |
| 411 | final int mode = mService.mAppOps.checkOpNoThrow(win.mAppOp, win.getOwningUid(), |
| 412 | win.getOwningPackage()); |
| 413 | win.setAppOpVisibilityLw(mode == AppOpsManager.MODE_ALLOWED || |
| 414 | mode == AppOpsManager.MODE_DEFAULT); |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | boolean canShowStrictModeViolation(int pid) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 420 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 421 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 422 | final WindowList windows = mChildren.get(i).getWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 423 | final int numWindows = windows.size(); |
| 424 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 425 | final WindowState ws = windows.get(winNdx); |
| 426 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 427 | return true; |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | return false; |
| 432 | } |
| 433 | |
| 434 | void closeSystemDialogs(String reason) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 435 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 436 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 437 | final WindowList windows = mChildren.get(i).getWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 438 | final int numWindows = windows.size(); |
| 439 | for (int j = 0; j < numWindows; ++j) { |
| 440 | final WindowState w = windows.get(j); |
| 441 | if (w.mHasSurface) { |
| 442 | try { |
| 443 | w.mClient.closeSystemDialogs(reason); |
| 444 | } catch (RemoteException e) { |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | void removeReplacedWindows() { |
| 452 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows"); |
| 453 | mService.openSurfaceTransaction(); |
| 454 | try { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 455 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 456 | DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 457 | final WindowList windows = dc.getWindowList(); |
| 458 | for (int j = windows.size() - 1; j >= 0; j--) { |
| 459 | final WindowState win = windows.get(j); |
| 460 | final AppWindowToken aToken = win.mAppToken; |
| 461 | if (aToken != null) { |
| 462 | aToken.removeReplacedWindowIfNeeded(win); |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | } finally { |
| 467 | mService.closeSurfaceTransaction(); |
| 468 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows"); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | boolean hasPendingLayoutChanges(WindowAnimator animator) { |
| 473 | boolean hasChanges = false; |
| 474 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 475 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 476 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 477 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 478 | final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId()); |
| 479 | if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 480 | animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING; |
| 481 | } |
| 482 | if (pendingChanges != 0) { |
| 483 | hasChanges = true; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | return hasChanges; |
| 488 | } |
| 489 | |
| 490 | void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) { |
| 491 | boolean addInputConsumerHandle = mService.mInputConsumer != null; |
| 492 | boolean addWallpaperInputConsumerHandle = mService.mWallpaperInputConsumer != null; |
| 493 | final WallpaperController wallpaperController = mService.mWallpaperControllerLocked; |
| 494 | boolean disableWallpaperTouchEvents = false; |
| 495 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 496 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 497 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 498 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 499 | final WindowList windows = dc.getWindowList(); |
| 500 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 501 | final WindowState child = windows.get(winNdx); |
| 502 | final InputChannel inputChannel = child.mInputChannel; |
| 503 | final InputWindowHandle inputWindowHandle = child.mInputWindowHandle; |
| 504 | if (inputChannel == null || inputWindowHandle == null || child.mRemoved |
| 505 | || child.isAdjustedForMinimizedDock()) { |
| 506 | // Skip this window because it cannot possibly receive input. |
| 507 | continue; |
| 508 | } |
| 509 | if (addInputConsumerHandle |
| 510 | && inputWindowHandle.layer <= mService.mInputConsumer.mWindowHandle.layer) { |
| 511 | inputMonitor.addInputWindowHandle(mService.mInputConsumer.mWindowHandle); |
| 512 | addInputConsumerHandle = false; |
| 513 | } |
| 514 | |
| 515 | if (addWallpaperInputConsumerHandle) { |
| 516 | if (child.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER && |
| 517 | child.isVisibleLw()) { |
| 518 | // Add the wallpaper input consumer above the first visible wallpaper. |
| 519 | inputMonitor.addInputWindowHandle( |
| 520 | mService.mWallpaperInputConsumer.mWindowHandle); |
| 521 | addWallpaperInputConsumerHandle = false; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | final int flags = child.mAttrs.flags; |
| 526 | final int privateFlags = child.mAttrs.privateFlags; |
| 527 | final int type = child.mAttrs.type; |
| 528 | |
| 529 | final boolean hasFocus = child == inputFocus; |
| 530 | final boolean isVisible = child.isVisibleLw(); |
| 531 | if ((privateFlags |
| 532 | & WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) |
| 533 | != 0) { |
| 534 | disableWallpaperTouchEvents = true; |
| 535 | } |
| 536 | final boolean hasWallpaper = wallpaperController.isWallpaperTarget(child) |
| 537 | && (privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD) == 0 |
| 538 | && !disableWallpaperTouchEvents; |
| 539 | final boolean onDefaultDisplay = (child.getDisplayId() == Display.DEFAULT_DISPLAY); |
| 540 | |
| 541 | // If there's a drag in progress and 'child' is a potential drop target, |
| 542 | // make sure it's been told about the drag |
| 543 | if (inDrag && isVisible && onDefaultDisplay) { |
| 544 | mService.mDragState.sendDragStartedIfNeededLw(child); |
| 545 | } |
| 546 | |
| 547 | inputMonitor.addInputWindowHandle( |
| 548 | inputWindowHandle, child, flags, type, isVisible, hasFocus, hasWallpaper); |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | if (addWallpaperInputConsumerHandle) { |
| 553 | // No visible wallpaper found, add the wallpaper input consumer at the end. |
| 554 | inputMonitor.addInputWindowHandle(mService.mWallpaperInputConsumer.mWindowHandle); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation, |
| 559 | boolean secure) { |
| 560 | final WindowSurfaceController surfaceController = winAnimator.mSurfaceController; |
| 561 | boolean leakedSurface = false; |
| 562 | boolean killedApps = false; |
| 563 | |
| 564 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(), |
| 565 | winAnimator.mSession.mPid, operation); |
| 566 | |
| 567 | final long callingIdentity = Binder.clearCallingIdentity(); |
| 568 | try { |
| 569 | // There was some problem... first, do a sanity check of the window list to make sure |
| 570 | // we haven't left any dangling surfaces around. |
| 571 | |
| 572 | Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks..."); |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 573 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 574 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 575 | final WindowList windows = mChildren.get(displayNdx).getWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 576 | final int numWindows = windows.size(); |
| 577 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 578 | final WindowState ws = windows.get(winNdx); |
| 579 | final WindowStateAnimator wsa = ws.mWinAnimator; |
| 580 | if (wsa.mSurfaceController == null) { |
| 581 | continue; |
| 582 | } |
| 583 | if (!mService.mSessions.contains(wsa.mSession)) { |
| 584 | Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): " |
| 585 | + ws + " surface=" + wsa.mSurfaceController |
| 586 | + " token=" + ws.mToken |
| 587 | + " pid=" + ws.mSession.mPid |
| 588 | + " uid=" + ws.mSession.mUid); |
| 589 | wsa.destroySurface(); |
| 590 | mService.mForceRemoves.add(ws); |
| 591 | leakedSurface = true; |
| 592 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
| 593 | Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): " |
| 594 | + ws + " surface=" + wsa.mSurfaceController |
| 595 | + " token=" + ws.mAppToken |
| 596 | + " saved=" + ws.hasSavedSurface()); |
| 597 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", false); |
| 598 | wsa.destroySurface(); |
| 599 | leakedSurface = true; |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | if (!leakedSurface) { |
| 605 | Slog.w(TAG_WM, "No leaked surfaces; killing applications!"); |
| 606 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 607 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 608 | final WindowList windows = mChildren.get(displayNdx).getWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 609 | final int numWindows = windows.size(); |
| 610 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 611 | final WindowState ws = windows.get(winNdx); |
| 612 | if (mService.mForceRemoves.contains(ws)) { |
| 613 | continue; |
| 614 | } |
| 615 | WindowStateAnimator wsa = ws.mWinAnimator; |
| 616 | if (wsa.mSurfaceController != null) { |
| 617 | pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid); |
| 618 | } |
| 619 | } |
| 620 | if (pidCandidates.size() > 0) { |
| 621 | int[] pids = new int[pidCandidates.size()]; |
| 622 | for (int i = 0; i < pids.length; i++) { |
| 623 | pids[i] = pidCandidates.keyAt(i); |
| 624 | } |
| 625 | try { |
| 626 | if (mService.mActivityManager.killPids(pids, "Free memory", secure)) { |
| 627 | killedApps = true; |
| 628 | } |
| 629 | } catch (RemoteException e) { |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | if (leakedSurface || killedApps) { |
| 636 | // We managed to reclaim some memory, so get rid of the trouble surface and ask the |
| 637 | // app to request another one. |
| 638 | Slog.w(TAG_WM, |
| 639 | "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 640 | if (surfaceController != null) { |
| 641 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin, |
| 642 | "RECOVER DESTROY", false); |
| 643 | winAnimator.destroySurface(); |
| 644 | mService.scheduleRemoveStartingWindowLocked(winAnimator.mWin.mAppToken); |
| 645 | } |
| 646 | |
| 647 | try { |
| 648 | winAnimator.mWin.mClient.dispatchGetNewSurface(); |
| 649 | } catch (RemoteException e) { |
| 650 | } |
| 651 | } |
| 652 | } finally { |
| 653 | Binder.restoreCallingIdentity(callingIdentity); |
| 654 | } |
| 655 | |
| 656 | return leakedSurface || killedApps; |
| 657 | } |
| 658 | |
| 659 | // "Something has changed! Let's make it correct now." |
| 660 | // TODO: Super crazy long method that should be broken down... |
| 661 | void performSurfacePlacement(boolean recoveringMemory) { |
| 662 | if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by " |
| 663 | + Debug.getCallers(3)); |
| 664 | |
| 665 | int i; |
| 666 | boolean updateInputWindowsNeeded = false; |
| 667 | |
| 668 | if (mService.mFocusMayChange) { |
| 669 | mService.mFocusMayChange = false; |
| 670 | updateInputWindowsNeeded = mService.updateFocusedWindowLocked( |
| 671 | UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/); |
| 672 | } |
| 673 | |
| 674 | // Initialize state of exiting tokens. |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 675 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 676 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 677 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 678 | for (i = displayContent.mExitingTokens.size() - 1; i >= 0; i--) { |
| 679 | displayContent.mExitingTokens.get(i).hasVisible = false; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) { |
| 684 | // Initialize state of exiting applications. |
| 685 | final AppTokenList exitingAppTokens = |
| 686 | mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens; |
| 687 | for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 688 | exitingAppTokens.get(tokenNdx).hasVisible = false; |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | mHoldScreen = null; |
| 693 | mScreenBrightness = -1; |
| 694 | mButtonBrightness = -1; |
| 695 | mUserActivityTimeout = -1; |
| 696 | mObscureApplicationContentOnSecondaryDisplays = false; |
| 697 | mSustainedPerformanceModeCurrent = false; |
| 698 | mService.mTransactionSequence++; |
| 699 | |
| 700 | // TODO(multi-display): |
| 701 | final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked(); |
| 702 | final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo(); |
| 703 | final int defaultDw = defaultInfo.logicalWidth; |
| 704 | final int defaultDh = defaultInfo.logicalHeight; |
| 705 | |
| 706 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 707 | ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
| 708 | mService.openSurfaceTransaction(); |
| 709 | try { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 710 | applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 711 | } catch (RuntimeException e) { |
| 712 | Slog.wtf(TAG, "Unhandled exception in Window Manager", e); |
| 713 | } finally { |
| 714 | mService.closeSurfaceTransaction(); |
| 715 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 716 | "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 717 | } |
| 718 | |
| 719 | final WindowList defaultWindows = defaultDisplay.getWindowList(); |
| 720 | final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked; |
| 721 | |
| 722 | // If we are ready to perform an app transition, check through all of the app tokens to be |
| 723 | // shown and see if they are ready to go. |
| 724 | if (mService.mAppTransition.isReady()) { |
| 725 | defaultDisplay.pendingLayoutChanges |= |
| 726 | surfacePlacer.handleAppTransitionReadyLocked(defaultWindows); |
| 727 | if (DEBUG_LAYOUT_REPEATS) |
| 728 | surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked", |
| 729 | defaultDisplay.pendingLayoutChanges); |
| 730 | } |
| 731 | |
| 732 | if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) { |
| 733 | // We have finished the animation of an app transition. To do this, we have delayed a |
| 734 | // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app |
| 735 | // token list reflects the correct Z-order, but the window list may now be out of sync |
| 736 | // with it. So here we will just rebuild the entire app window list. Fun! |
| 737 | defaultDisplay.pendingLayoutChanges |= |
| 738 | mService.handleAnimatingStoppedAndTransitionLocked(); |
| 739 | if (DEBUG_LAYOUT_REPEATS) |
| 740 | surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock", |
| 741 | defaultDisplay.pendingLayoutChanges); |
| 742 | } |
| 743 | |
| 744 | if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0 |
| 745 | && !mService.mAppTransition.isReady()) { |
| 746 | // At this point, there was a window with a wallpaper that was force hiding other |
| 747 | // windows behind it, but now it is going away. This may be simple -- just animate away |
| 748 | // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be |
| 749 | // shown behind something that was hidden. |
| 750 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 751 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 752 | "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges); |
| 753 | } |
| 754 | mWallpaperForceHidingChanged = false; |
| 755 | |
| 756 | if (mWallpaperMayChange) { |
| 757 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting"); |
| 758 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 759 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange", |
| 760 | defaultDisplay.pendingLayoutChanges); |
| 761 | } |
| 762 | |
| 763 | if (mService.mFocusMayChange) { |
| 764 | mService.mFocusMayChange = false; |
| 765 | if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 766 | false /*updateInputWindows*/)) { |
| 767 | updateInputWindowsNeeded = true; |
| 768 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 769 | } |
| 770 | } |
| 771 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 772 | if (isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 773 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 774 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded", |
| 775 | defaultDisplay.pendingLayoutChanges); |
| 776 | } |
| 777 | |
| 778 | for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) { |
| 779 | WindowState win = mService.mResizingWindows.get(i); |
| 780 | if (win.mAppFreezing) { |
| 781 | // Don't remove this window until rotation has completed. |
| 782 | continue; |
| 783 | } |
| 784 | // Discard the saved surface if window size is changed, it can't be reused. |
| 785 | if (win.mAppToken != null) { |
| 786 | win.mAppToken.destroySavedSurfaces(); |
| 787 | } |
| 788 | win.reportResized(); |
| 789 | mService.mResizingWindows.remove(i); |
| 790 | } |
| 791 | |
| 792 | if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG, |
| 793 | "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete); |
| 794 | if (mOrientationChangeComplete) { |
| 795 | if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) { |
| 796 | mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE; |
| 797 | mService.mLastFinishedFreezeSource = mLastWindowFreezeSource; |
| 798 | mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT); |
| 799 | } |
| 800 | mService.stopFreezingDisplayLocked(); |
| 801 | } |
| 802 | |
| 803 | // Destroy the surface of any windows that are no longer visible. |
| 804 | boolean wallpaperDestroyed = false; |
| 805 | i = mService.mDestroySurface.size(); |
| 806 | if (i > 0) { |
| 807 | do { |
| 808 | i--; |
| 809 | WindowState win = mService.mDestroySurface.get(i); |
| 810 | win.mDestroying = false; |
| 811 | if (mService.mInputMethodWindow == win) { |
| 812 | mService.mInputMethodWindow = null; |
| 813 | } |
| 814 | if (mService.mWallpaperControllerLocked.isWallpaperTarget(win)) { |
| 815 | wallpaperDestroyed = true; |
| 816 | } |
| 817 | win.destroyOrSaveSurface(); |
| 818 | } while (i > 0); |
| 819 | mService.mDestroySurface.clear(); |
| 820 | } |
| 821 | |
| 822 | // Time to remove any exiting tokens? |
| 823 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 824 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 825 | ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens; |
| 826 | for (i = exitingTokens.size() - 1; i >= 0; i--) { |
| 827 | WindowToken token = exitingTokens.get(i); |
| 828 | if (!token.hasVisible) { |
| 829 | exitingTokens.remove(i); |
| 830 | if (token.windowType == TYPE_WALLPAPER) { |
| 831 | mService.mWallpaperControllerLocked.removeWallpaperToken(token); |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | // Time to remove any exiting applications? |
| 838 | for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) { |
| 839 | // Initialize state of exiting applications. |
| 840 | final AppTokenList exitingAppTokens = |
| 841 | mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens; |
| 842 | for (i = exitingAppTokens.size() - 1; i >= 0; i--) { |
| 843 | final AppWindowToken token = exitingAppTokens.get(i); |
| 844 | if (!token.hasVisible && !mService.mClosingApps.contains(token) && |
| 845 | (!token.mIsExiting || token.isEmpty())) { |
| 846 | // Make sure there is no animation running on this token, so any windows |
| 847 | // associated with it will be removed as soon as their animations are complete |
| 848 | token.mAppAnimator.clearAnimation(); |
| 849 | token.mAppAnimator.animating = false; |
| 850 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 851 | "performLayout: App token exiting now removed" + token); |
| 852 | token.removeIfPossible(); |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | if (wallpaperDestroyed) { |
| 858 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 859 | defaultDisplay.setLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 863 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 864 | if (displayContent.pendingLayoutChanges != 0) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 865 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
| 869 | // Finally update all input windows now that the window changes have stabilized. |
| 870 | mService.mInputMonitor.updateInputWindowsLw(true /*force*/); |
| 871 | |
| 872 | mService.setHoldScreenLocked(mHoldScreen); |
| 873 | if (!mService.mDisplayFrozen) { |
| 874 | if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) { |
| 875 | mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1); |
| 876 | } else { |
| 877 | mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager( |
| 878 | toBrightnessOverride(mScreenBrightness)); |
| 879 | } |
| 880 | if (mButtonBrightness < 0 || mButtonBrightness > 1.0f) { |
| 881 | mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1); |
| 882 | } else { |
| 883 | mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager( |
| 884 | toBrightnessOverride(mButtonBrightness)); |
| 885 | } |
| 886 | mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager( |
| 887 | mUserActivityTimeout); |
| 888 | } |
| 889 | |
| 890 | if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) { |
| 891 | mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent; |
| 892 | mService.mPowerManagerInternal.powerHint( |
| 893 | mService.mPowerManagerInternal.POWER_HINT_SUSTAINED_PERFORMANCE_MODE, |
| 894 | (mSustainedPerformanceModeEnabled ? 1 : 0)); |
| 895 | } |
| 896 | |
| 897 | if (mService.mTurnOnScreen) { |
| 898 | if (mService.mAllowTheaterModeWakeFromLayout |
| 899 | || Settings.Global.getInt(mService.mContext.getContentResolver(), |
| 900 | Settings.Global.THEATER_MODE_ON, 0) == 0) { |
| 901 | if (DEBUG_VISIBILITY || DEBUG_POWER) { |
| 902 | Slog.v(TAG, "Turning screen on after layout!"); |
| 903 | } |
| 904 | mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(), |
| 905 | "android.server.wm:TURN_ON"); |
| 906 | } |
| 907 | mService.mTurnOnScreen = false; |
| 908 | } |
| 909 | |
| 910 | if (mUpdateRotation) { |
| 911 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| 912 | if (mService.updateRotationUncheckedLocked(false)) { |
| 913 | mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION); |
| 914 | } else { |
| 915 | mUpdateRotation = false; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | if (mService.mWaitingForDrawnCallback != null || |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 920 | (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded() |
| 921 | && !mUpdateRotation)) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 922 | mService.checkDrawnWindowsLocked(); |
| 923 | } |
| 924 | |
| 925 | final int N = mService.mPendingRemove.size(); |
| 926 | if (N > 0) { |
| 927 | if (mService.mPendingRemoveTmp.length < N) { |
| 928 | mService.mPendingRemoveTmp = new WindowState[N+10]; |
| 929 | } |
| 930 | mService.mPendingRemove.toArray(mService.mPendingRemoveTmp); |
| 931 | mService.mPendingRemove.clear(); |
| 932 | DisplayContentList displayList = new DisplayContentList(); |
| 933 | for (i = 0; i < N; i++) { |
| 934 | final WindowState w = mService.mPendingRemoveTmp[i]; |
| 935 | w.removeImmediately(); |
| 936 | final DisplayContent displayContent = w.getDisplayContent(); |
| 937 | if (displayContent != null && !displayList.contains(displayContent)) { |
| 938 | displayList.add(displayContent); |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | for (DisplayContent displayContent : displayList) { |
| 943 | mService.mLayersController.assignLayersLocked(displayContent.getWindowList()); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 944 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | |
| 948 | // Remove all deferred displays stacks, tasks, and activities. |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 949 | for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) { |
| 950 | mChildren.get(displayNdx).checkCompleteDeferredRemoval(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | if (updateInputWindowsNeeded) { |
| 954 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 955 | } |
| 956 | mService.setFocusTaskRegionLocked(); |
| 957 | |
| 958 | // Check to see if we are now in a state where the screen should |
| 959 | // be enabled, because the window obscured flags have changed. |
| 960 | mService.enableScreenIfNeededLocked(); |
| 961 | |
| 962 | mService.scheduleAnimationLocked(); |
| 963 | mService.mWindowPlacerLocked.destroyPendingSurfaces(); |
| 964 | |
| 965 | if (DEBUG_WINDOW_TRACE) Slog.e(TAG, |
| 966 | "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating()); |
| 967 | } |
| 968 | |
| 969 | // TODO: Super crazy long method that should be broken down... |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 970 | private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw, int defaultDh) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 971 | mHoldScreenWindow = null; |
| 972 | mObsuringWindow = null; |
| 973 | |
| 974 | if (mService.mWatermark != null) { |
| 975 | mService.mWatermark.positionSurface(defaultDw, defaultDh); |
| 976 | } |
| 977 | if (mService.mStrictModeFlash != null) { |
| 978 | mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh); |
| 979 | } |
| 980 | if (mService.mCircularDisplayMask != null) { |
| 981 | mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh, mService.mRotation); |
| 982 | } |
| 983 | if (mService.mEmulatorDisplayOverlay != null) { |
| 984 | mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh, |
| 985 | mService.mRotation); |
| 986 | } |
| 987 | |
| 988 | boolean focusDisplayed = false; |
| 989 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 990 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 991 | for (int j = 0; j < count; ++j) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 992 | final DisplayContent dc = mChildren.get(j); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 993 | WindowList windows = dc.getWindowList(); |
| 994 | DisplayInfo displayInfo = dc.getDisplayInfo(); |
| 995 | final int displayId = dc.getDisplayId(); |
| 996 | final int dw = displayInfo.logicalWidth; |
| 997 | final int dh = displayInfo.logicalHeight; |
| 998 | final boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY); |
| 999 | final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked; |
| 1000 | |
| 1001 | // Reset for each display. |
| 1002 | mDisplayHasContent = false; |
| 1003 | mPreferredRefreshRate = 0; |
| 1004 | mPreferredModeId = 0; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1005 | mTmpUpdateAllDrawn.clear(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1006 | |
| 1007 | int repeats = 0; |
| 1008 | do { |
| 1009 | repeats++; |
| 1010 | if (repeats > 6) { |
| 1011 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1012 | dc.clearLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1013 | break; |
| 1014 | } |
| 1015 | |
| 1016 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 1017 | "On entry to LockedInner", dc.pendingLayoutChanges); |
| 1018 | |
| 1019 | if ((dc.pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0 |
| 1020 | && mService.mWallpaperControllerLocked.adjustWallpaperWindows()) { |
| 1021 | mService.mLayersController.assignLayersLocked(windows); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1022 | dc.setLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | if (isDefaultDisplay |
| 1026 | && (dc.pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 1027 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 1028 | if (mService.updateOrientationFromAppTokensLocked(true)) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1029 | dc.setLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1030 | mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | if ((dc.pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1035 | dc.setLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | // FIRST LOOP: Perform a layout, if needed. |
| 1039 | if (repeats < LAYOUT_REPEAT_THRESHOLD) { |
| 1040 | surfacePlacer.performLayoutLockedInner(dc, repeats == 1, |
| 1041 | false /* updateInputWindows */); |
| 1042 | } else { |
| 1043 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 1044 | } |
| 1045 | |
| 1046 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think |
| 1047 | // it is animating. |
| 1048 | dc.pendingLayoutChanges = 0; |
| 1049 | |
| 1050 | if (isDefaultDisplay) { |
| 1051 | mService.mPolicy.beginPostLayoutPolicyLw(dw, dh); |
| 1052 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 1053 | WindowState w = windows.get(i); |
| 1054 | if (w.mHasSurface) { |
| 1055 | mService.mPolicy.applyPostLayoutPolicyLw( |
| 1056 | w, w.mAttrs, w.getParentWindow()); |
| 1057 | } |
| 1058 | } |
| 1059 | dc.pendingLayoutChanges |= |
| 1060 | mService.mPolicy.finishPostLayoutPolicyLw(); |
| 1061 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 1062 | "after finishPostLayoutPolicyLw", dc.pendingLayoutChanges); |
| 1063 | } |
| 1064 | } while (dc.pendingLayoutChanges != 0); |
| 1065 | |
| 1066 | mObscured = false; |
| 1067 | mSyswin = false; |
| 1068 | dc.resetDimming(); |
| 1069 | |
| 1070 | // Only used if default window |
| 1071 | final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty(); |
| 1072 | |
| 1073 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 1074 | WindowState w = windows.get(i); |
| 1075 | final Task task = w.getTask(); |
| 1076 | final boolean obscuredChanged = w.mObscured != mObscured; |
| 1077 | |
| 1078 | // Update effect. |
| 1079 | w.mObscured = mObscured; |
| 1080 | if (!mObscured) { |
| 1081 | handleNotObscuredLocked(w, displayInfo); |
| 1082 | } |
| 1083 | |
| 1084 | w.applyDimLayerIfNeeded(); |
| 1085 | |
| 1086 | if (isDefaultDisplay && obscuredChanged && w.isVisibleLw() |
| 1087 | && mService.mWallpaperControllerLocked.isWallpaperTarget(w)) { |
| 1088 | // This is the wallpaper target and its obscured state changed... make sure the |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1089 | // current wallpaper's visibility has been updated accordingly. |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1090 | mService.mWallpaperControllerLocked.updateWallpaperVisibility(); |
| 1091 | } |
| 1092 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1093 | w.handleWindowMovedIfNeeded(); |
| 1094 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1095 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 1096 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1097 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 1098 | w.mContentChanged = false; |
| 1099 | |
| 1100 | // Moved from updateWindowsAndWallpaperLocked(). |
| 1101 | if (w.mHasSurface) { |
| 1102 | // Take care of the window being ready to display. |
| 1103 | final boolean committed = winAnimator.commitFinishDrawingLocked(); |
| 1104 | if (isDefaultDisplay && committed) { |
| 1105 | if (w.mAttrs.type == TYPE_DREAM) { |
| 1106 | // HACK: When a dream is shown, it may at that point hide the lock |
| 1107 | // screen. So we need to redo the layout to let the phone window manager |
| 1108 | // make this happen. |
| 1109 | dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 1110 | if (DEBUG_LAYOUT_REPEATS) { |
| 1111 | surfacePlacer.debugLayoutRepeats( |
| 1112 | "dream and commitFinishDrawingLocked true", |
| 1113 | dc.pendingLayoutChanges); |
| 1114 | } |
| 1115 | } |
| 1116 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 1117 | if (DEBUG_WALLPAPER_LIGHT) |
| 1118 | Slog.v(TAG, "First draw done in potential wallpaper target " + w); |
| 1119 | mWallpaperMayChange = true; |
| 1120 | dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 1121 | if (DEBUG_LAYOUT_REPEATS) { |
| 1122 | surfacePlacer.debugLayoutRepeats( |
| 1123 | "wallpaper and commitFinishDrawingLocked true", |
| 1124 | dc.pendingLayoutChanges); |
| 1125 | } |
| 1126 | } |
| 1127 | } |
| 1128 | if (!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) { |
| 1129 | // Updates the shown frame before we set up the surface. This is needed |
| 1130 | // because the resizing could change the top-left position (in addition to |
| 1131 | // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to |
| 1132 | // position the surface. |
| 1133 | // |
| 1134 | // If an animation is being started, we can't call this method because the |
| 1135 | // animation hasn't processed its initial transformation yet, but in general |
| 1136 | // we do want to update the position if the window is animating. |
| 1137 | winAnimator.computeShownFrameLocked(); |
| 1138 | } |
| 1139 | winAnimator.setSurfaceBoundariesLocked(recoveringMemory); |
| 1140 | } |
| 1141 | |
| 1142 | final AppWindowToken atoken = w.mAppToken; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1143 | if (atoken != null) { |
| 1144 | final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w); |
| 1145 | if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) { |
| 1146 | mTmpUpdateAllDrawn.add(atoken); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus |
| 1151 | && w.isDisplayedLw()) { |
| 1152 | focusDisplayed = true; |
| 1153 | } |
| 1154 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1155 | w.updateResizingWindowIfNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | mService.mDisplayManagerInternal.setDisplayProperties(displayId, |
| 1159 | mDisplayHasContent, |
| 1160 | mPreferredRefreshRate, |
| 1161 | mPreferredModeId, |
| 1162 | true /* inTraversal, must call performTraversalInTrans... below */); |
| 1163 | |
| 1164 | dc.stopDimmingIfNeeded(); |
| 1165 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1166 | while (!mTmpUpdateAllDrawn.isEmpty()) { |
| 1167 | final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1168 | // See if any windows have been drawn, so they (and others associated with them) |
| 1169 | // can now be shown. |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1170 | atoken.updateAllDrawn(dc); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | if (focusDisplayed) { |
| 1175 | mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS); |
| 1176 | } |
| 1177 | |
| 1178 | // Give the display manager a chance to adjust properties |
| 1179 | // like display rotation if it needs to. |
| 1180 | mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager(); |
| 1181 | } |
| 1182 | |
| 1183 | /** |
| 1184 | * @param w WindowState this method is applied to. |
| 1185 | * @param dispInfo info of the display that the window's obscuring state is checked against. |
| 1186 | */ |
| 1187 | private void handleNotObscuredLocked(final WindowState w, final DisplayInfo dispInfo) { |
| 1188 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 1189 | final int attrFlags = attrs.flags; |
| 1190 | final boolean canBeSeen = w.isDisplayedLw(); |
| 1191 | final int privateflags = attrs.privateFlags; |
| 1192 | |
| 1193 | if (canBeSeen && w.isObscuringFullscreen(dispInfo)) { |
| 1194 | // This window completely covers everything behind it, |
| 1195 | // so we want to leave all of them as undimmed (for |
| 1196 | // performance reasons). |
| 1197 | if (!mObscured) { |
| 1198 | mObsuringWindow = w; |
| 1199 | } |
| 1200 | |
| 1201 | mObscured = true; |
| 1202 | } |
| 1203 | |
| 1204 | if (w.mHasSurface && canBeSeen) { |
| 1205 | if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) { |
| 1206 | mHoldScreen = w.mSession; |
| 1207 | mHoldScreenWindow = w; |
| 1208 | } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) { |
| 1209 | Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding " |
| 1210 | + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by" |
| 1211 | + Debug.getCallers(10)); |
| 1212 | } |
| 1213 | if (!mSyswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) { |
| 1214 | mScreenBrightness = w.mAttrs.screenBrightness; |
| 1215 | } |
| 1216 | if (!mSyswin && w.mAttrs.buttonBrightness >= 0 && mButtonBrightness < 0) { |
| 1217 | mButtonBrightness = w.mAttrs.buttonBrightness; |
| 1218 | } |
| 1219 | if (!mSyswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) { |
| 1220 | mUserActivityTimeout = w.mAttrs.userActivityTimeout; |
| 1221 | } |
| 1222 | |
| 1223 | final int type = attrs.type; |
| 1224 | if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR |
| 1225 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 1226 | mSyswin = true; |
| 1227 | } |
| 1228 | |
| 1229 | // This function assumes that the contents of the default display are processed first |
| 1230 | // before secondary displays. |
| 1231 | final DisplayContent displayContent = w.getDisplayContent(); |
| 1232 | if (displayContent != null && displayContent.isDefaultDisplay) { |
| 1233 | // While a dream or keyguard is showing, obscure ordinary application content on |
| 1234 | // secondary displays (by forcibly enabling mirroring unless there is other content |
| 1235 | // we want to show) but still allow opaque keyguard dialogs to be shown. |
| 1236 | if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 1237 | mObscureApplicationContentOnSecondaryDisplays = true; |
| 1238 | } |
| 1239 | mDisplayHasContent = true; |
| 1240 | } else if (displayContent != null && |
| 1241 | (!mObscureApplicationContentOnSecondaryDisplays |
| 1242 | || (mObscured && type == TYPE_KEYGUARD_DIALOG))) { |
| 1243 | // Allow full screen keyguard presentation dialogs to be seen. |
| 1244 | mDisplayHasContent = true; |
| 1245 | } |
| 1246 | if (mPreferredRefreshRate == 0 && w.mAttrs.preferredRefreshRate != 0) { |
| 1247 | mPreferredRefreshRate = w.mAttrs.preferredRefreshRate; |
| 1248 | } |
| 1249 | if (mPreferredModeId == 0 && w.mAttrs.preferredDisplayModeId != 0) { |
| 1250 | mPreferredModeId = w.mAttrs.preferredDisplayModeId; |
| 1251 | } |
| 1252 | if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) { |
| 1253 | mSustainedPerformanceModeCurrent = true; |
| 1254 | } |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | boolean copyAnimToLayoutParams() { |
| 1259 | boolean doRequest = false; |
| 1260 | |
| 1261 | final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams; |
| 1262 | if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) { |
| 1263 | mUpdateRotation = true; |
| 1264 | doRequest = true; |
| 1265 | } |
| 1266 | if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) { |
| 1267 | mWallpaperMayChange = true; |
| 1268 | doRequest = true; |
| 1269 | } |
| 1270 | if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) { |
| 1271 | mWallpaperForceHidingChanged = true; |
| 1272 | doRequest = true; |
| 1273 | } |
| 1274 | if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) { |
| 1275 | mOrientationChangeComplete = false; |
| 1276 | } else { |
| 1277 | mOrientationChangeComplete = true; |
| 1278 | mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource; |
| 1279 | if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) { |
| 1280 | doRequest = true; |
| 1281 | } |
| 1282 | } |
| 1283 | if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) { |
| 1284 | mService.mTurnOnScreen = true; |
| 1285 | } |
| 1286 | if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) { |
| 1287 | mWallpaperActionPending = true; |
| 1288 | } |
| 1289 | |
| 1290 | return doRequest; |
| 1291 | } |
| 1292 | |
| 1293 | private static int toBrightnessOverride(float value) { |
| 1294 | return (int)(value * PowerManager.BRIGHTNESS_ON); |
| 1295 | } |
| 1296 | |
| 1297 | void enableSurfaceTrace(ParcelFileDescriptor pfd) { |
| 1298 | final FileDescriptor fd = pfd.getFileDescriptor(); |
| 1299 | if (mSurfaceTraceEnabled) { |
| 1300 | disableSurfaceTrace(); |
| 1301 | } |
| 1302 | mSurfaceTraceEnabled = true; |
| 1303 | mRemoteEventTrace = new RemoteEventTrace(mService, fd); |
| 1304 | mSurfaceTraceFd = pfd; |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1305 | for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1306 | final DisplayContent dc = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1307 | dc.enableSurfaceTrace(fd); |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | void disableSurfaceTrace() { |
| 1312 | mSurfaceTraceEnabled = false; |
| 1313 | mRemoteEventTrace = null; |
| 1314 | mSurfaceTraceFd = null; |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1315 | for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1316 | final DisplayContent dc = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1317 | dc.disableSurfaceTrace(); |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | void dumpDisplayContents(PrintWriter pw) { |
| 1322 | pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)"); |
| 1323 | if (mService.mDisplayReady) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1324 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1325 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1326 | final DisplayContent displayContent = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1327 | displayContent.dump(" ", pw); |
| 1328 | } |
| 1329 | } else { |
| 1330 | pw.println(" NO DISPLAY"); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | void dumpLayoutNeededDisplayIds(PrintWriter pw) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1335 | if (!isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1336 | return; |
| 1337 | } |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1338 | pw.print(" mLayoutNeeded on displays="); |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1339 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1340 | for (int displayNdx = 0; displayNdx < count; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1341 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1342 | if (displayContent.isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1343 | pw.print(displayContent.getDisplayId()); |
| 1344 | } |
| 1345 | } |
| 1346 | pw.println(); |
| 1347 | } |
| 1348 | |
| 1349 | void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1350 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1351 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1352 | final WindowList windowList = mChildren.get(displayNdx).getWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1353 | for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) { |
| 1354 | final WindowState w = windowList.get(winNdx); |
| 1355 | if (windows == null || windows.contains(w)) { |
| 1356 | pw.println(" Window #" + winNdx + " " + w + ":"); |
| 1357 | w.dump(pw, " ", dumpAll || windows != null); |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | } |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1362 | |
| 1363 | @Override |
| 1364 | String getName() { |
| 1365 | return "ROOT"; |
| 1366 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1367 | } |