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