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 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 19 | import android.content.res.Configuration; |
| 20 | import android.graphics.Rect; |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 21 | import android.hardware.power.V1_0.PowerHint; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 22 | import android.os.Binder; |
| 23 | import android.os.Debug; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 24 | import android.os.IBinder; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 25 | import android.os.ParcelFileDescriptor; |
| 26 | import android.os.PowerManager; |
| 27 | import android.os.RemoteException; |
| 28 | import android.os.SystemClock; |
| 29 | import android.os.UserHandle; |
| 30 | import android.provider.Settings; |
| 31 | import android.util.EventLog; |
| 32 | import android.util.Slog; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 33 | import android.util.SparseIntArray; |
| 34 | import android.view.Display; |
| 35 | import android.view.DisplayInfo; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 36 | import android.view.WindowManager; |
| 37 | import com.android.internal.util.ArrayUtils; |
| 38 | import com.android.server.EventLogTags; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 39 | |
| 40 | import java.io.FileDescriptor; |
| 41 | import java.io.PrintWriter; |
| 42 | import java.util.ArrayList; |
| 43 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 44 | import static android.app.AppOpsManager.MODE_ALLOWED; |
| 45 | import static android.app.AppOpsManager.MODE_DEFAULT; |
| 46 | import static android.app.AppOpsManager.OP_NONE; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 47 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 48 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 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; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 53 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 54 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
| 55 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | 879ff72 | 2016-11-04 18:08:17 -0700 | [diff] [blame^] | 56 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 57 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 58 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
| 59 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 60 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
| 61 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 62 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 63 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT; |
| 64 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 65 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
| 66 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE; |
| 67 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 68 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC; |
| 69 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 70 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON; |
| 71 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 72 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 73 | import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS; |
| 74 | import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 75 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES; |
| 76 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
| 77 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE; |
| 78 | import static com.android.server.wm.WindowManagerService.H.WINDOW_FREEZE_TIMEOUT; |
| 79 | import static com.android.server.wm.WindowManagerService.logSurface; |
| 80 | import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED; |
| 81 | import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE; |
| 82 | import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN; |
| 83 | import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION; |
| 84 | import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_ACTION_PENDING; |
| 85 | import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE; |
| 86 | |
| 87 | /** Root {@link WindowContainer} for the device. */ |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 88 | class RootWindowContainer extends WindowContainer<DisplayContent> { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 89 | private static final String TAG = TAG_WITH_CLASS_NAME ? "RootWindowContainer" : TAG_WM; |
| 90 | |
| 91 | WindowManagerService mService; |
| 92 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 93 | private boolean mWallpaperForceHidingChanged = false; |
| 94 | private Object mLastWindowFreezeSource = null; |
| 95 | private Session mHoldScreen = null; |
| 96 | private float mScreenBrightness = -1; |
| 97 | private float mButtonBrightness = -1; |
| 98 | private long mUserActivityTimeout = -1; |
| 99 | private boolean mUpdateRotation = false; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 100 | // Following variables are for debugging screen wakelock only. |
| 101 | // Last window that requires screen wakelock |
| 102 | WindowState mHoldScreenWindow = null; |
| 103 | // Last window that obscures all windows below |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 104 | WindowState mObscuringWindow = null; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 105 | // Only set while traversing the default display based on its content. |
| 106 | // Affects the behavior of mirroring on secondary displays. |
| 107 | private boolean mObscureApplicationContentOnSecondaryDisplays = false; |
| 108 | |
| 109 | private boolean mSustainedPerformanceModeEnabled = false; |
| 110 | private boolean mSustainedPerformanceModeCurrent = false; |
| 111 | |
| 112 | boolean mWallpaperMayChange = false; |
Robert Carr | 11c26c2 | 2016-09-23 12:40:27 -0700 | [diff] [blame] | 113 | // During an orientation change, we track whether all windows have rendered |
| 114 | // at the new orientation, and this will be false from changing orientation until that occurs. |
| 115 | // For seamless rotation cases this always stays true, as the windows complete their orientation |
| 116 | // changes 1 by 1 without disturbing global state. |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 117 | boolean mOrientationChangeComplete = true; |
| 118 | boolean mWallpaperActionPending = false; |
| 119 | |
| 120 | private final ArrayList<Integer> mChangedStackList = new ArrayList(); |
| 121 | |
| 122 | // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl |
| 123 | // instances will be replaced with an instance that writes a binary representation of all |
| 124 | // commands to mSurfaceTraceFd. |
| 125 | boolean mSurfaceTraceEnabled; |
| 126 | ParcelFileDescriptor mSurfaceTraceFd; |
| 127 | RemoteEventTrace mRemoteEventTrace; |
| 128 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 129 | private final WindowLayersController mLayersController; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 130 | final WallpaperController mWallpaperController; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 131 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 132 | RootWindowContainer(WindowManagerService service) { |
| 133 | mService = service; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 134 | mLayersController = new WindowLayersController(mService); |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 135 | mWallpaperController = new WallpaperController(mService); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | WindowState computeFocusedWindow() { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 139 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 140 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 141 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 142 | final WindowState win = dc.findFocusedWindow(); |
| 143 | if (win != null) { |
| 144 | return win; |
| 145 | } |
| 146 | } |
| 147 | return null; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if |
| 152 | * there is a Display for the displayId. |
| 153 | * |
| 154 | * @param displayId The display the caller is interested in. |
| 155 | * @return The DisplayContent associated with displayId or null if there is no Display for it. |
| 156 | */ |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 157 | DisplayContent getDisplayContentOrCreate(int displayId) { |
| 158 | DisplayContent dc = getDisplayContent(displayId); |
| 159 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 160 | if (dc == null) { |
| 161 | final Display display = mService.mDisplayManager.getDisplay(displayId); |
| 162 | if (display != null) { |
| 163 | dc = createDisplayContent(display); |
| 164 | } |
| 165 | } |
| 166 | return dc; |
| 167 | } |
| 168 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 169 | DisplayContent getDisplayContent(int displayId) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 170 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 171 | final DisplayContent current = mChildren.get(i); |
| 172 | if (current.getDisplayId() == displayId) { |
| 173 | return current; |
| 174 | } |
| 175 | } |
| 176 | return null; |
| 177 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 178 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 179 | private DisplayContent createDisplayContent(final Display display) { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 180 | final DisplayContent dc = new DisplayContent(display, mService, mLayersController, |
| 181 | mWallpaperController); |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 182 | final int displayId = display.getDisplayId(); |
| 183 | |
| 184 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Adding display=" + display); |
| 185 | addChild(dc, null); |
| 186 | |
| 187 | final DisplayInfo displayInfo = dc.getDisplayInfo(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 188 | final Rect rect = new Rect(); |
| 189 | mService.mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect); |
| 190 | displayInfo.overscanLeft = rect.left; |
| 191 | displayInfo.overscanTop = rect.top; |
| 192 | displayInfo.overscanRight = rect.right; |
| 193 | displayInfo.overscanBottom = rect.bottom; |
| 194 | if (mService.mDisplayManagerInternal != null) { |
| 195 | mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager( |
| 196 | displayId, displayInfo); |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 197 | mService.configureDisplayPolicyLocked(dc); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 198 | |
| 199 | // TODO(multi-display): Create an input channel for each display with touch capability. |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 200 | if (displayId == DEFAULT_DISPLAY) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 201 | dc.mTapDetector = new TaskTapPointerEventListener( |
| 202 | mService, dc); |
| 203 | mService.registerPointerEventListener(dc.mTapDetector); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 204 | mService.registerPointerEventListener(mService.mMousePositionTracker); |
| 205 | } |
| 206 | } |
| 207 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 208 | return dc; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 211 | boolean isLayoutNeeded() { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 212 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 213 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 214 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 215 | if (displayContent.isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 216 | return true; |
| 217 | } |
| 218 | } |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | void getWindows(WindowList output) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 223 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 224 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 225 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 226 | dc.getWindows(output); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | void getWindows(WindowList output, boolean visibleOnly, boolean appsOnly) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 231 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 232 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 233 | final ReadOnlyWindowList windowList = mChildren.get(displayNdx).getReadOnlyWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 234 | for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) { |
| 235 | final WindowState w = windowList.get(winNdx); |
| 236 | if ((!visibleOnly || w.mWinAnimator.getShown()) |
| 237 | && (!appsOnly || w.mAppToken != null)) { |
| 238 | output.add(w); |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | void getWindowsByName(WindowList output, String name) { |
| 245 | int objectId = 0; |
| 246 | // See if this is an object ID. |
| 247 | try { |
| 248 | objectId = Integer.parseInt(name, 16); |
| 249 | name = null; |
| 250 | } catch (RuntimeException e) { |
| 251 | } |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 252 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 253 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 254 | final ReadOnlyWindowList windowList = mChildren.get(displayNdx).getReadOnlyWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 255 | for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) { |
| 256 | final WindowState w = windowList.get(winNdx); |
| 257 | if (name != null) { |
| 258 | if (w.mAttrs.getTitle().toString().contains(name)) { |
| 259 | output.add(w); |
| 260 | } |
| 261 | } else if (System.identityHashCode(w) == objectId) { |
| 262 | output.add(w); |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | WindowState findWindow(int hashCode) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 269 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 270 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 271 | final ReadOnlyWindowList windows = mChildren.get(displayNdx).getReadOnlyWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 272 | final int numWindows = windows.size(); |
| 273 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 274 | final WindowState w = windows.get(winNdx); |
| 275 | if (System.identityHashCode(w) == hashCode) { |
| 276 | return w; |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | return null; |
| 282 | } |
| 283 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 284 | /** |
| 285 | * Returns the app window token for the input binder if it exist in the system. |
| 286 | * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since |
| 287 | * AppWindowToken represents an activity which can only exist on one display. |
| 288 | */ |
| 289 | AppWindowToken getAppWindowToken(IBinder binder) { |
| 290 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 291 | final DisplayContent dc = mChildren.get(i); |
| 292 | final AppWindowToken atoken = dc.getAppWindowToken(binder); |
| 293 | if (atoken != null) { |
| 294 | return atoken; |
| 295 | } |
| 296 | } |
| 297 | return null; |
| 298 | } |
| 299 | |
| 300 | /** Returns the display object the input window token is currently mapped on. */ |
| 301 | DisplayContent getWindowTokenDisplay(WindowToken token) { |
| 302 | if (token == null) { |
| 303 | return null; |
| 304 | } |
| 305 | |
| 306 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 307 | final DisplayContent dc = mChildren.get(i); |
| 308 | final WindowToken current = dc.getWindowToken(token.token); |
| 309 | if (current == token) { |
| 310 | return dc; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | return null; |
| 315 | } |
| 316 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 317 | // TODO: Users would have their own window containers under the display container? |
| 318 | void switchUser() { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 319 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 320 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 321 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 322 | dc.switchUser(); |
| 323 | } |
| 324 | } |
| 325 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 326 | /** |
| 327 | * Set new display override config and return array of ids of stacks that were changed during |
| 328 | * update. If called for the default display, global configuration will also be updated. |
| 329 | */ |
| 330 | int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId) { |
| 331 | final DisplayContent displayContent = getDisplayContent(displayId); |
| 332 | if (displayContent == null) { |
| 333 | throw new IllegalArgumentException("Display not found for id: " + displayId); |
| 334 | } |
| 335 | |
| 336 | final Configuration currentConfig = displayContent.getOverrideConfiguration(); |
| 337 | final boolean configChanged = currentConfig.diff(newConfiguration) != 0; |
| 338 | if (!configChanged) { |
| 339 | return null; |
| 340 | } |
| 341 | displayContent.onOverrideConfigurationChanged(currentConfig); |
| 342 | |
| 343 | if (displayId == DEFAULT_DISPLAY) { |
| 344 | // Override configuration of the default display duplicates global config. In this case |
| 345 | // we also want to update the global config. |
| 346 | return setGlobalConfigurationIfNeeded(newConfiguration); |
| 347 | } else { |
| 348 | return updateStackBoundsAfterConfigChange(displayId); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | private int[] setGlobalConfigurationIfNeeded(Configuration newConfiguration) { |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 353 | final boolean configChanged = getConfiguration().diff(newConfiguration) != 0; |
| 354 | if (!configChanged) { |
| 355 | return null; |
| 356 | } |
| 357 | onConfigurationChanged(newConfiguration); |
| 358 | return updateStackBoundsAfterConfigChange(); |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | void onConfigurationChanged(Configuration newParentConfig) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 363 | prepareFreezingTaskBounds(); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 364 | super.onConfigurationChanged(newParentConfig); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 365 | |
| 366 | mService.mPolicy.onConfigurationChanged(); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 367 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 368 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 369 | /** |
| 370 | * Callback used to trigger bounds update after configuration change and get ids of stacks whose |
| 371 | * bounds were updated. |
| 372 | */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 373 | private int[] updateStackBoundsAfterConfigChange() { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 374 | mChangedStackList.clear(); |
| 375 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 376 | final int numDisplays = mChildren.size(); |
| 377 | for (int i = 0; i < numDisplays; ++i) { |
| 378 | final DisplayContent dc = mChildren.get(i); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 379 | dc.updateStackBoundsAfterConfigChange(mChangedStackList); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList); |
| 383 | } |
| 384 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 385 | /** Same as {@link #updateStackBoundsAfterConfigChange()} but only for a specific display. */ |
| 386 | private int[] updateStackBoundsAfterConfigChange(int displayId) { |
| 387 | mChangedStackList.clear(); |
| 388 | |
| 389 | final DisplayContent dc = getDisplayContent(displayId); |
| 390 | dc.updateStackBoundsAfterConfigChange(mChangedStackList); |
| 391 | |
| 392 | return mChangedStackList.isEmpty() ? null : ArrayUtils.convertToIntArray(mChangedStackList); |
| 393 | } |
| 394 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 395 | private void prepareFreezingTaskBounds() { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 396 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 397 | mChildren.get(i).prepareFreezingTaskBounds(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
| 401 | void setSecureSurfaceState(int userId, boolean disabled) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 402 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 403 | final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 404 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 405 | final WindowState win = windows.get(winNdx); |
| 406 | if (win.mHasSurface && userId == UserHandle.getUserId(win.mOwnerUid)) { |
| 407 | win.mWinAnimator.setSecureLocked(disabled); |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | void updateAppOpsState() { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 414 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 415 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 416 | final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 417 | final int numWindows = windows.size(); |
| 418 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 419 | final WindowState win = windows.get(winNdx); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 420 | if (win.mAppOp == OP_NONE) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 421 | continue; |
| 422 | } |
| 423 | final int mode = mService.mAppOps.checkOpNoThrow(win.mAppOp, win.getOwningUid(), |
| 424 | win.getOwningPackage()); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 425 | win.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | boolean canShowStrictModeViolation(int pid) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 431 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 432 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 433 | final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 434 | final int numWindows = windows.size(); |
| 435 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 436 | final WindowState ws = windows.get(winNdx); |
| 437 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 438 | return true; |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | return false; |
| 443 | } |
| 444 | |
| 445 | void closeSystemDialogs(String reason) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 446 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 447 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 448 | final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 449 | final int numWindows = windows.size(); |
| 450 | for (int j = 0; j < numWindows; ++j) { |
| 451 | final WindowState w = windows.get(j); |
| 452 | if (w.mHasSurface) { |
| 453 | try { |
| 454 | w.mClient.closeSystemDialogs(reason); |
| 455 | } catch (RemoteException e) { |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | void removeReplacedWindows() { |
| 463 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows"); |
| 464 | mService.openSurfaceTransaction(); |
| 465 | try { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 466 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 467 | DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 468 | final ReadOnlyWindowList windows = mChildren.get(i).getReadOnlyWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 469 | for (int j = windows.size() - 1; j >= 0; j--) { |
| 470 | final WindowState win = windows.get(j); |
| 471 | final AppWindowToken aToken = win.mAppToken; |
| 472 | if (aToken != null) { |
| 473 | aToken.removeReplacedWindowIfNeeded(win); |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | } finally { |
| 478 | mService.closeSurfaceTransaction(); |
| 479 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows"); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | boolean hasPendingLayoutChanges(WindowAnimator animator) { |
| 484 | boolean hasChanges = false; |
| 485 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 486 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 487 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 488 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 489 | final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId()); |
| 490 | if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 491 | animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING; |
| 492 | } |
| 493 | if (pendingChanges != 0) { |
| 494 | hasChanges = true; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | return hasChanges; |
| 499 | } |
| 500 | |
| 501 | void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 502 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 503 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 504 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 505 | dc.updateInputWindows(inputMonitor, inputFocus, inDrag); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
| 509 | boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation, |
| 510 | boolean secure) { |
| 511 | final WindowSurfaceController surfaceController = winAnimator.mSurfaceController; |
| 512 | boolean leakedSurface = false; |
| 513 | boolean killedApps = false; |
| 514 | |
| 515 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(), |
| 516 | winAnimator.mSession.mPid, operation); |
| 517 | |
| 518 | final long callingIdentity = Binder.clearCallingIdentity(); |
| 519 | try { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 520 | // There was some problem...first, do a sanity check of the window list to make sure |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 521 | // we haven't left any dangling surfaces around. |
| 522 | |
| 523 | Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks..."); |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 524 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 525 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 526 | leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | if (!leakedSurface) { |
| 530 | Slog.w(TAG_WM, "No leaked surfaces; killing applications!"); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 531 | final SparseIntArray pidCandidates = new SparseIntArray(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 532 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 533 | final ReadOnlyWindowList windows = |
| 534 | mChildren.get(displayNdx).getReadOnlyWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 535 | final int numWindows = windows.size(); |
| 536 | for (int winNdx = 0; winNdx < numWindows; ++winNdx) { |
| 537 | final WindowState ws = windows.get(winNdx); |
| 538 | if (mService.mForceRemoves.contains(ws)) { |
| 539 | continue; |
| 540 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 541 | final WindowStateAnimator wsa = ws.mWinAnimator; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 542 | if (wsa.mSurfaceController != null) { |
| 543 | pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid); |
| 544 | } |
| 545 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 546 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 547 | if (pidCandidates.size() > 0) { |
| 548 | int[] pids = new int[pidCandidates.size()]; |
| 549 | for (int i = 0; i < pids.length; i++) { |
| 550 | pids[i] = pidCandidates.keyAt(i); |
| 551 | } |
| 552 | try { |
| 553 | if (mService.mActivityManager.killPids(pids, "Free memory", secure)) { |
| 554 | killedApps = true; |
| 555 | } |
| 556 | } catch (RemoteException e) { |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | if (leakedSurface || killedApps) { |
| 563 | // We managed to reclaim some memory, so get rid of the trouble surface and ask the |
| 564 | // app to request another one. |
| 565 | Slog.w(TAG_WM, |
| 566 | "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 567 | if (surfaceController != null) { |
| 568 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin, |
| 569 | "RECOVER DESTROY", false); |
| 570 | winAnimator.destroySurface(); |
| 571 | mService.scheduleRemoveStartingWindowLocked(winAnimator.mWin.mAppToken); |
| 572 | } |
| 573 | |
| 574 | try { |
| 575 | winAnimator.mWin.mClient.dispatchGetNewSurface(); |
| 576 | } catch (RemoteException e) { |
| 577 | } |
| 578 | } |
| 579 | } finally { |
| 580 | Binder.restoreCallingIdentity(callingIdentity); |
| 581 | } |
| 582 | |
| 583 | return leakedSurface || killedApps; |
| 584 | } |
| 585 | |
| 586 | // "Something has changed! Let's make it correct now." |
| 587 | // TODO: Super crazy long method that should be broken down... |
| 588 | void performSurfacePlacement(boolean recoveringMemory) { |
| 589 | if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by " |
| 590 | + Debug.getCallers(3)); |
| 591 | |
| 592 | int i; |
| 593 | boolean updateInputWindowsNeeded = false; |
| 594 | |
| 595 | if (mService.mFocusMayChange) { |
| 596 | mService.mFocusMayChange = false; |
| 597 | updateInputWindowsNeeded = mService.updateFocusedWindowLocked( |
| 598 | UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/); |
| 599 | } |
| 600 | |
| 601 | // Initialize state of exiting tokens. |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 602 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 603 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 604 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 605 | for (i = displayContent.mExitingTokens.size() - 1; i >= 0; i--) { |
| 606 | displayContent.mExitingTokens.get(i).hasVisible = false; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) { |
| 611 | // Initialize state of exiting applications. |
| 612 | final AppTokenList exitingAppTokens = |
| 613 | mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens; |
| 614 | for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 615 | exitingAppTokens.get(tokenNdx).hasVisible = false; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | mHoldScreen = null; |
| 620 | mScreenBrightness = -1; |
| 621 | mButtonBrightness = -1; |
| 622 | mUserActivityTimeout = -1; |
| 623 | mObscureApplicationContentOnSecondaryDisplays = false; |
| 624 | mSustainedPerformanceModeCurrent = false; |
| 625 | mService.mTransactionSequence++; |
| 626 | |
| 627 | // TODO(multi-display): |
| 628 | final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked(); |
| 629 | final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo(); |
| 630 | final int defaultDw = defaultInfo.logicalWidth; |
| 631 | final int defaultDh = defaultInfo.logicalHeight; |
| 632 | |
| 633 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 634 | ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
| 635 | mService.openSurfaceTransaction(); |
| 636 | try { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 637 | applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 638 | } catch (RuntimeException e) { |
| 639 | Slog.wtf(TAG, "Unhandled exception in Window Manager", e); |
| 640 | } finally { |
| 641 | mService.closeSurfaceTransaction(); |
| 642 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 643 | "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 644 | } |
| 645 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 646 | final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked; |
| 647 | |
| 648 | // If we are ready to perform an app transition, check through all of the app tokens to be |
| 649 | // shown and see if they are ready to go. |
| 650 | if (mService.mAppTransition.isReady()) { |
| 651 | defaultDisplay.pendingLayoutChanges |= |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 652 | surfacePlacer.handleAppTransitionReadyLocked(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 653 | if (DEBUG_LAYOUT_REPEATS) |
| 654 | surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked", |
| 655 | defaultDisplay.pendingLayoutChanges); |
| 656 | } |
| 657 | |
| 658 | if (!mService.mAnimator.mAppWindowAnimating && mService.mAppTransition.isRunning()) { |
| 659 | // We have finished the animation of an app transition. To do this, we have delayed a |
| 660 | // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app |
| 661 | // token list reflects the correct Z-order, but the window list may now be out of sync |
| 662 | // with it. So here we will just rebuild the entire app window list. Fun! |
| 663 | defaultDisplay.pendingLayoutChanges |= |
| 664 | mService.handleAnimatingStoppedAndTransitionLocked(); |
| 665 | if (DEBUG_LAYOUT_REPEATS) |
| 666 | surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock", |
| 667 | defaultDisplay.pendingLayoutChanges); |
| 668 | } |
| 669 | |
| 670 | if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0 |
| 671 | && !mService.mAppTransition.isReady()) { |
| 672 | // At this point, there was a window with a wallpaper that was force hiding other |
| 673 | // windows behind it, but now it is going away. This may be simple -- just animate away |
| 674 | // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be |
| 675 | // shown behind something that was hidden. |
| 676 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 677 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 678 | "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges); |
| 679 | } |
| 680 | mWallpaperForceHidingChanged = false; |
| 681 | |
| 682 | if (mWallpaperMayChange) { |
| 683 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting"); |
| 684 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 685 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange", |
| 686 | defaultDisplay.pendingLayoutChanges); |
| 687 | } |
| 688 | |
| 689 | if (mService.mFocusMayChange) { |
| 690 | mService.mFocusMayChange = false; |
| 691 | if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 692 | false /*updateInputWindows*/)) { |
| 693 | updateInputWindowsNeeded = true; |
| 694 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 695 | } |
| 696 | } |
| 697 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 698 | if (isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 699 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 700 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded", |
| 701 | defaultDisplay.pendingLayoutChanges); |
| 702 | } |
| 703 | |
| 704 | for (i = mService.mResizingWindows.size() - 1; i >= 0; i--) { |
| 705 | WindowState win = mService.mResizingWindows.get(i); |
| 706 | if (win.mAppFreezing) { |
| 707 | // Don't remove this window until rotation has completed. |
| 708 | continue; |
| 709 | } |
| 710 | // Discard the saved surface if window size is changed, it can't be reused. |
| 711 | if (win.mAppToken != null) { |
| 712 | win.mAppToken.destroySavedSurfaces(); |
| 713 | } |
| 714 | win.reportResized(); |
| 715 | mService.mResizingWindows.remove(i); |
| 716 | } |
| 717 | |
| 718 | if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG, |
| 719 | "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete); |
| 720 | if (mOrientationChangeComplete) { |
| 721 | if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) { |
| 722 | mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE; |
| 723 | mService.mLastFinishedFreezeSource = mLastWindowFreezeSource; |
| 724 | mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT); |
| 725 | } |
| 726 | mService.stopFreezingDisplayLocked(); |
| 727 | } |
| 728 | |
| 729 | // Destroy the surface of any windows that are no longer visible. |
| 730 | boolean wallpaperDestroyed = false; |
| 731 | i = mService.mDestroySurface.size(); |
| 732 | if (i > 0) { |
| 733 | do { |
| 734 | i--; |
| 735 | WindowState win = mService.mDestroySurface.get(i); |
| 736 | win.mDestroying = false; |
| 737 | if (mService.mInputMethodWindow == win) { |
| 738 | mService.mInputMethodWindow = null; |
| 739 | } |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 740 | if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 741 | wallpaperDestroyed = true; |
| 742 | } |
| 743 | win.destroyOrSaveSurface(); |
| 744 | } while (i > 0); |
| 745 | mService.mDestroySurface.clear(); |
| 746 | } |
| 747 | |
| 748 | // Time to remove any exiting tokens? |
| 749 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 750 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 751 | ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens; |
| 752 | for (i = exitingTokens.size() - 1; i >= 0; i--) { |
| 753 | WindowToken token = exitingTokens.get(i); |
| 754 | if (!token.hasVisible) { |
| 755 | exitingTokens.remove(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | // Time to remove any exiting applications? |
| 761 | for (int stackNdx = mService.mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) { |
| 762 | // Initialize state of exiting applications. |
| 763 | final AppTokenList exitingAppTokens = |
| 764 | mService.mStackIdToStack.valueAt(stackNdx).mExitingAppTokens; |
| 765 | for (i = exitingAppTokens.size() - 1; i >= 0; i--) { |
| 766 | final AppWindowToken token = exitingAppTokens.get(i); |
| 767 | if (!token.hasVisible && !mService.mClosingApps.contains(token) && |
| 768 | (!token.mIsExiting || token.isEmpty())) { |
| 769 | // Make sure there is no animation running on this token, so any windows |
| 770 | // associated with it will be removed as soon as their animations are complete |
| 771 | token.mAppAnimator.clearAnimation(); |
| 772 | token.mAppAnimator.animating = false; |
| 773 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 774 | "performLayout: App token exiting now removed" + token); |
| 775 | token.removeIfPossible(); |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | if (wallpaperDestroyed) { |
| 781 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 782 | defaultDisplay.setLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 786 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 787 | if (displayContent.pendingLayoutChanges != 0) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 788 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | |
| 792 | // Finally update all input windows now that the window changes have stabilized. |
| 793 | mService.mInputMonitor.updateInputWindowsLw(true /*force*/); |
| 794 | |
| 795 | mService.setHoldScreenLocked(mHoldScreen); |
| 796 | if (!mService.mDisplayFrozen) { |
| 797 | if (mScreenBrightness < 0 || mScreenBrightness > 1.0f) { |
| 798 | mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1); |
| 799 | } else { |
| 800 | mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager( |
| 801 | toBrightnessOverride(mScreenBrightness)); |
| 802 | } |
| 803 | if (mButtonBrightness < 0 || mButtonBrightness > 1.0f) { |
| 804 | mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1); |
| 805 | } else { |
| 806 | mService.mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager( |
| 807 | toBrightnessOverride(mButtonBrightness)); |
| 808 | } |
| 809 | mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager( |
| 810 | mUserActivityTimeout); |
| 811 | } |
| 812 | |
| 813 | if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) { |
| 814 | mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent; |
| 815 | mService.mPowerManagerInternal.powerHint( |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 816 | PowerHint.SUSTAINED_PERFORMANCE, |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 817 | (mSustainedPerformanceModeEnabled ? 1 : 0)); |
| 818 | } |
| 819 | |
| 820 | if (mService.mTurnOnScreen) { |
| 821 | if (mService.mAllowTheaterModeWakeFromLayout |
| 822 | || Settings.Global.getInt(mService.mContext.getContentResolver(), |
| 823 | Settings.Global.THEATER_MODE_ON, 0) == 0) { |
| 824 | if (DEBUG_VISIBILITY || DEBUG_POWER) { |
| 825 | Slog.v(TAG, "Turning screen on after layout!"); |
| 826 | } |
| 827 | mService.mPowerManager.wakeUp(SystemClock.uptimeMillis(), |
| 828 | "android.server.wm:TURN_ON"); |
| 829 | } |
| 830 | mService.mTurnOnScreen = false; |
| 831 | } |
| 832 | |
| 833 | if (mUpdateRotation) { |
| 834 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 835 | // TODO(multi-display): Update rotation for different displays separately. |
| 836 | final int displayId = defaultDisplay.getDisplayId(); |
| 837 | if (mService.updateRotationUncheckedLocked(false, displayId)) { |
| 838 | mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 839 | } else { |
| 840 | mUpdateRotation = false; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | if (mService.mWaitingForDrawnCallback != null || |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 845 | (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded() |
| 846 | && !mUpdateRotation)) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 847 | mService.checkDrawnWindowsLocked(); |
| 848 | } |
| 849 | |
| 850 | final int N = mService.mPendingRemove.size(); |
| 851 | if (N > 0) { |
| 852 | if (mService.mPendingRemoveTmp.length < N) { |
| 853 | mService.mPendingRemoveTmp = new WindowState[N+10]; |
| 854 | } |
| 855 | mService.mPendingRemove.toArray(mService.mPendingRemoveTmp); |
| 856 | mService.mPendingRemove.clear(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 857 | ArrayList<DisplayContent> displayList = new ArrayList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 858 | for (i = 0; i < N; i++) { |
| 859 | final WindowState w = mService.mPendingRemoveTmp[i]; |
| 860 | w.removeImmediately(); |
| 861 | final DisplayContent displayContent = w.getDisplayContent(); |
| 862 | if (displayContent != null && !displayList.contains(displayContent)) { |
| 863 | displayList.add(displayContent); |
| 864 | } |
| 865 | } |
| 866 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 867 | for (int j = displayList.size() - 1; j >= 0; --j) { |
| 868 | final DisplayContent dc = displayList.get(j); |
| 869 | dc.assignWindowLayers(true /*setLayoutNeeded*/); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | |
| 873 | // Remove all deferred displays stacks, tasks, and activities. |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 874 | for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) { |
| 875 | mChildren.get(displayNdx).checkCompleteDeferredRemoval(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | if (updateInputWindowsNeeded) { |
| 879 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 880 | } |
| 881 | mService.setFocusTaskRegionLocked(); |
| 882 | |
| 883 | // Check to see if we are now in a state where the screen should |
| 884 | // be enabled, because the window obscured flags have changed. |
| 885 | mService.enableScreenIfNeededLocked(); |
| 886 | |
| 887 | mService.scheduleAnimationLocked(); |
| 888 | mService.mWindowPlacerLocked.destroyPendingSurfaces(); |
| 889 | |
| 890 | if (DEBUG_WINDOW_TRACE) Slog.e(TAG, |
| 891 | "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating()); |
| 892 | } |
| 893 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 894 | private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw, |
| 895 | int defaultDh) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 896 | mHoldScreenWindow = null; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 897 | mObscuringWindow = null; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 898 | |
| 899 | if (mService.mWatermark != null) { |
| 900 | mService.mWatermark.positionSurface(defaultDw, defaultDh); |
| 901 | } |
| 902 | if (mService.mStrictModeFlash != null) { |
| 903 | mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh); |
| 904 | } |
| 905 | if (mService.mCircularDisplayMask != null) { |
| 906 | mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh, mService.mRotation); |
| 907 | } |
| 908 | if (mService.mEmulatorDisplayOverlay != null) { |
| 909 | mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh, |
| 910 | mService.mRotation); |
| 911 | } |
| 912 | |
| 913 | boolean focusDisplayed = false; |
| 914 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 915 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 916 | for (int j = 0; j < count; ++j) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 917 | final DisplayContent dc = mChildren.get(j); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 918 | focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | if (focusDisplayed) { |
| 922 | mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS); |
| 923 | } |
| 924 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 925 | // Give the display manager a chance to adjust properties like display rotation if it needs |
| 926 | // to. |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 927 | mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager(); |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * @param w WindowState this method is applied to. |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 932 | * @param obscured True if there is a window on top of this obscuring the display. |
| 933 | * @param syswin System window? |
| 934 | * @return True when the display contains content to show the user. When false, the display |
| 935 | * manager may choose to mirror or blank the display. |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 936 | */ |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 937 | boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 938 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 939 | final int attrFlags = attrs.flags; |
| 940 | final boolean canBeSeen = w.isDisplayedLw(); |
| 941 | final int privateflags = attrs.privateFlags; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 942 | boolean displayHasContent = false; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 943 | |
| 944 | if (w.mHasSurface && canBeSeen) { |
| 945 | if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) { |
| 946 | mHoldScreen = w.mSession; |
| 947 | mHoldScreenWindow = w; |
| 948 | } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) { |
| 949 | Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding " |
| 950 | + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by" |
| 951 | + Debug.getCallers(10)); |
| 952 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 953 | if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 954 | mScreenBrightness = w.mAttrs.screenBrightness; |
| 955 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 956 | if (!syswin && w.mAttrs.buttonBrightness >= 0 && mButtonBrightness < 0) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 957 | mButtonBrightness = w.mAttrs.buttonBrightness; |
| 958 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 959 | if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 960 | mUserActivityTimeout = w.mAttrs.userActivityTimeout; |
| 961 | } |
| 962 | |
| 963 | final int type = attrs.type; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 964 | // This function assumes that the contents of the default display are processed first |
| 965 | // before secondary displays. |
| 966 | final DisplayContent displayContent = w.getDisplayContent(); |
| 967 | if (displayContent != null && displayContent.isDefaultDisplay) { |
| 968 | // While a dream or keyguard is showing, obscure ordinary application content on |
| 969 | // secondary displays (by forcibly enabling mirroring unless there is other content |
| 970 | // we want to show) but still allow opaque keyguard dialogs to be shown. |
| 971 | if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 972 | mObscureApplicationContentOnSecondaryDisplays = true; |
| 973 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 974 | displayHasContent = true; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 975 | } else if (displayContent != null && |
| 976 | (!mObscureApplicationContentOnSecondaryDisplays |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 977 | || (obscured && type == TYPE_KEYGUARD_DIALOG))) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 978 | // Allow full screen keyguard presentation dialogs to be seen. |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 979 | displayHasContent = true; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 980 | } |
| 981 | if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) { |
| 982 | mSustainedPerformanceModeCurrent = true; |
| 983 | } |
| 984 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 985 | |
| 986 | return displayHasContent; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | boolean copyAnimToLayoutParams() { |
| 990 | boolean doRequest = false; |
| 991 | |
| 992 | final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams; |
| 993 | if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) { |
| 994 | mUpdateRotation = true; |
| 995 | doRequest = true; |
| 996 | } |
| 997 | if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) { |
| 998 | mWallpaperMayChange = true; |
| 999 | doRequest = true; |
| 1000 | } |
| 1001 | if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) { |
| 1002 | mWallpaperForceHidingChanged = true; |
| 1003 | doRequest = true; |
| 1004 | } |
| 1005 | if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) { |
| 1006 | mOrientationChangeComplete = false; |
| 1007 | } else { |
| 1008 | mOrientationChangeComplete = true; |
| 1009 | mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource; |
| 1010 | if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) { |
| 1011 | doRequest = true; |
| 1012 | } |
| 1013 | } |
| 1014 | if ((bulkUpdateParams & SET_TURN_ON_SCREEN) != 0) { |
| 1015 | mService.mTurnOnScreen = true; |
| 1016 | } |
| 1017 | if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) { |
| 1018 | mWallpaperActionPending = true; |
| 1019 | } |
| 1020 | |
| 1021 | return doRequest; |
| 1022 | } |
| 1023 | |
| 1024 | private static int toBrightnessOverride(float value) { |
| 1025 | return (int)(value * PowerManager.BRIGHTNESS_ON); |
| 1026 | } |
| 1027 | |
| 1028 | void enableSurfaceTrace(ParcelFileDescriptor pfd) { |
| 1029 | final FileDescriptor fd = pfd.getFileDescriptor(); |
| 1030 | if (mSurfaceTraceEnabled) { |
| 1031 | disableSurfaceTrace(); |
| 1032 | } |
| 1033 | mSurfaceTraceEnabled = true; |
| 1034 | mRemoteEventTrace = new RemoteEventTrace(mService, fd); |
| 1035 | mSurfaceTraceFd = pfd; |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1036 | for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1037 | final DisplayContent dc = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1038 | dc.enableSurfaceTrace(fd); |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | void disableSurfaceTrace() { |
| 1043 | mSurfaceTraceEnabled = false; |
| 1044 | mRemoteEventTrace = null; |
| 1045 | mSurfaceTraceFd = null; |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1046 | for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1047 | final DisplayContent dc = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1048 | dc.disableSurfaceTrace(); |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | void dumpDisplayContents(PrintWriter pw) { |
| 1053 | pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)"); |
| 1054 | if (mService.mDisplayReady) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1055 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1056 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1057 | final DisplayContent displayContent = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1058 | displayContent.dump(" ", pw); |
| 1059 | } |
| 1060 | } else { |
| 1061 | pw.println(" NO DISPLAY"); |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | void dumpLayoutNeededDisplayIds(PrintWriter pw) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1066 | if (!isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1067 | return; |
| 1068 | } |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1069 | pw.print(" mLayoutNeeded on displays="); |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1070 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1071 | for (int displayNdx = 0; displayNdx < count; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1072 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1073 | if (displayContent.isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1074 | pw.print(displayContent.getDisplayId()); |
| 1075 | } |
| 1076 | } |
| 1077 | pw.println(); |
| 1078 | } |
| 1079 | |
| 1080 | void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1081 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1082 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1083 | final ReadOnlyWindowList windowList = mChildren.get(displayNdx).getReadOnlyWindowList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1084 | for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) { |
| 1085 | final WindowState w = windowList.get(winNdx); |
| 1086 | if (windows == null || windows.contains(w)) { |
| 1087 | pw.println(" Window #" + winNdx + " " + w + ":"); |
| 1088 | w.dump(pw, " ", dumpAll || windows != null); |
| 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | } |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1093 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1094 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 1095 | pw.println(" All tokens:"); |
| 1096 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1097 | mChildren.get(i).dumpTokens(pw, dumpAll); |
| 1098 | } |
| 1099 | } |
| 1100 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1101 | @Override |
| 1102 | String getName() { |
| 1103 | return "ROOT"; |
| 1104 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1105 | } |