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