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