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