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