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 | |
| 420 | void updateAppOpsState() { |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 421 | forAllWindows((w) -> { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 422 | w.updateAppOpsState(); |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 423 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | boolean canShowStrictModeViolation(int pid) { |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 427 | final WindowState win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw()); |
| 428 | return win != null; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | void closeSystemDialogs(String reason) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 432 | mCloseSystemDialogsReason = reason; |
| 433 | forAllWindows(mCloseSystemDialogsConsumer, false /* traverseTopToBottom */); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | void removeReplacedWindows() { |
| 437 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION removeReplacedWindows"); |
| 438 | mService.openSurfaceTransaction(); |
| 439 | try { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 440 | forAllWindows(sRemoveReplacedWindowsConsumer, true /* traverseTopToBottom */); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 441 | } finally { |
Adrian Roos | 111aff9 | 2017-09-27 18:11:46 +0200 | [diff] [blame] | 442 | mService.closeSurfaceTransaction("removeReplacedWindows"); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 443 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION removeReplacedWindows"); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | boolean hasPendingLayoutChanges(WindowAnimator animator) { |
| 448 | boolean hasChanges = false; |
| 449 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 450 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 451 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 452 | final DisplayContent dc = mChildren.get(i); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 453 | final int pendingChanges = animator.getPendingLayoutChanges(dc.getDisplayId()); |
| 454 | if ((pendingChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 455 | animator.mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING; |
| 456 | } |
| 457 | if (pendingChanges != 0) { |
| 458 | hasChanges = true; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | return hasChanges; |
| 463 | } |
| 464 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 465 | boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation, |
| 466 | boolean secure) { |
| 467 | final WindowSurfaceController surfaceController = winAnimator.mSurfaceController; |
| 468 | boolean leakedSurface = false; |
| 469 | boolean killedApps = false; |
| 470 | |
| 471 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(), |
| 472 | winAnimator.mSession.mPid, operation); |
| 473 | |
| 474 | final long callingIdentity = Binder.clearCallingIdentity(); |
| 475 | try { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 476 | // 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] | 477 | // we haven't left any dangling surfaces around. |
| 478 | |
| 479 | Slog.i(TAG_WM, "Out of memory for surface! Looking for leaks..."); |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 480 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 481 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 482 | leakedSurface |= mChildren.get(displayNdx).destroyLeakedSurfaces(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | if (!leakedSurface) { |
| 486 | Slog.w(TAG_WM, "No leaked surfaces; killing applications!"); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 487 | final SparseIntArray pidCandidates = new SparseIntArray(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 488 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 489 | mChildren.get(displayNdx).forAllWindows((w) -> { |
| 490 | if (mService.mForceRemoves.contains(w)) { |
| 491 | return; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 492 | } |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 493 | final WindowStateAnimator wsa = w.mWinAnimator; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 494 | if (wsa.mSurfaceController != null) { |
| 495 | pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid); |
| 496 | } |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 497 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 498 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 499 | if (pidCandidates.size() > 0) { |
| 500 | int[] pids = new int[pidCandidates.size()]; |
| 501 | for (int i = 0; i < pids.length; i++) { |
| 502 | pids[i] = pidCandidates.keyAt(i); |
| 503 | } |
| 504 | try { |
| 505 | if (mService.mActivityManager.killPids(pids, "Free memory", secure)) { |
| 506 | killedApps = true; |
| 507 | } |
| 508 | } catch (RemoteException e) { |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | if (leakedSurface || killedApps) { |
| 515 | // We managed to reclaim some memory, so get rid of the trouble surface and ask the |
| 516 | // app to request another one. |
| 517 | Slog.w(TAG_WM, |
| 518 | "Looks like we have reclaimed some memory, clearing surface for retry."); |
| 519 | if (surfaceController != null) { |
| 520 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin, |
| 521 | "RECOVER DESTROY", false); |
| 522 | winAnimator.destroySurface(); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 523 | if (winAnimator.mWin.mAppToken != null |
| 524 | && winAnimator.mWin.mAppToken.getController() != null) { |
| 525 | winAnimator.mWin.mAppToken.getController().removeStartingWindow(); |
| 526 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | try { |
| 530 | winAnimator.mWin.mClient.dispatchGetNewSurface(); |
| 531 | } catch (RemoteException e) { |
| 532 | } |
| 533 | } |
| 534 | } finally { |
| 535 | Binder.restoreCallingIdentity(callingIdentity); |
| 536 | } |
| 537 | |
| 538 | return leakedSurface || killedApps; |
| 539 | } |
| 540 | |
| 541 | // "Something has changed! Let's make it correct now." |
| 542 | // TODO: Super crazy long method that should be broken down... |
| 543 | void performSurfacePlacement(boolean recoveringMemory) { |
| 544 | if (DEBUG_WINDOW_TRACE) Slog.v(TAG, "performSurfacePlacementInner: entry. Called by " |
| 545 | + Debug.getCallers(3)); |
| 546 | |
| 547 | int i; |
| 548 | boolean updateInputWindowsNeeded = false; |
| 549 | |
| 550 | if (mService.mFocusMayChange) { |
| 551 | mService.mFocusMayChange = false; |
| 552 | updateInputWindowsNeeded = mService.updateFocusedWindowLocked( |
| 553 | UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/); |
| 554 | } |
| 555 | |
| 556 | // Initialize state of exiting tokens. |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 557 | final int numDisplays = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 558 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 559 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 560 | displayContent.setExitingTokensHasVisible(false); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | mHoldScreen = null; |
| 564 | mScreenBrightness = -1; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 565 | mUserActivityTimeout = -1; |
| 566 | mObscureApplicationContentOnSecondaryDisplays = false; |
| 567 | mSustainedPerformanceModeCurrent = false; |
| 568 | mService.mTransactionSequence++; |
| 569 | |
| 570 | // TODO(multi-display): |
| 571 | final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked(); |
| 572 | final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo(); |
| 573 | final int defaultDw = defaultInfo.logicalWidth; |
| 574 | final int defaultDh = defaultInfo.logicalHeight; |
| 575 | |
| 576 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 577 | ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
| 578 | mService.openSurfaceTransaction(); |
| 579 | try { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 580 | applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 581 | } catch (RuntimeException e) { |
| 582 | Slog.wtf(TAG, "Unhandled exception in Window Manager", e); |
| 583 | } finally { |
Adrian Roos | 111aff9 | 2017-09-27 18:11:46 +0200 | [diff] [blame] | 584 | mService.closeSurfaceTransaction("performLayoutAndPlaceSurfaces"); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 585 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 586 | "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 587 | } |
| 588 | |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 589 | mService.mAnimator.executeAfterPrepareSurfacesRunnables(); |
| 590 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 591 | final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked; |
| 592 | |
| 593 | // If we are ready to perform an app transition, check through all of the app tokens to be |
| 594 | // shown and see if they are ready to go. |
| 595 | if (mService.mAppTransition.isReady()) { |
Jorim Jaggi | 82c1786 | 2018-02-21 17:50:18 +0100 | [diff] [blame] | 596 | // This needs to be split into two expressions, as handleAppTransitionReadyLocked may |
| 597 | // modify dc.pendingLayoutChanges, which would get lost when writing |
| 598 | // defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked() |
| 599 | final int layoutChanges = surfacePlacer.handleAppTransitionReadyLocked(); |
| 600 | defaultDisplay.pendingLayoutChanges |= layoutChanges; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 601 | if (DEBUG_LAYOUT_REPEATS) |
| 602 | surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked", |
| 603 | defaultDisplay.pendingLayoutChanges); |
| 604 | } |
| 605 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 606 | if (!isAppAnimating() && mService.mAppTransition.isRunning()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 607 | // We have finished the animation of an app transition. To do this, we have delayed a |
| 608 | // lot of operations like showing and hiding apps, moving apps in Z-order, etc. The app |
| 609 | // token list reflects the correct Z-order, but the window list may now be out of sync |
| 610 | // with it. So here we will just rebuild the entire app window list. Fun! |
| 611 | defaultDisplay.pendingLayoutChanges |= |
| 612 | mService.handleAnimatingStoppedAndTransitionLocked(); |
| 613 | if (DEBUG_LAYOUT_REPEATS) |
| 614 | surfacePlacer.debugLayoutRepeats("after handleAnimStopAndXitionLock", |
| 615 | defaultDisplay.pendingLayoutChanges); |
| 616 | } |
| 617 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 618 | // Defer starting the recents animation until the wallpaper has drawn |
| 619 | final RecentsAnimationController recentsAnimationController = |
| 620 | mService.getRecentsAnimationController(); |
| 621 | if (recentsAnimationController != null) { |
| 622 | recentsAnimationController.checkAnimationReady(mWallpaperController); |
| 623 | } |
| 624 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 625 | if (mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0 |
| 626 | && !mService.mAppTransition.isReady()) { |
| 627 | // At this point, there was a window with a wallpaper that was force hiding other |
| 628 | // windows behind it, but now it is going away. This may be simple -- just animate away |
| 629 | // the wallpaper and its window -- or it may be hard -- the wallpaper now needs to be |
| 630 | // shown behind something that was hidden. |
| 631 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 632 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 633 | "after animateAwayWallpaperLocked", defaultDisplay.pendingLayoutChanges); |
| 634 | } |
| 635 | mWallpaperForceHidingChanged = false; |
| 636 | |
| 637 | if (mWallpaperMayChange) { |
| 638 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change! Adjusting"); |
| 639 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 640 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("WallpaperMayChange", |
| 641 | defaultDisplay.pendingLayoutChanges); |
| 642 | } |
| 643 | |
| 644 | if (mService.mFocusMayChange) { |
| 645 | mService.mFocusMayChange = false; |
| 646 | if (mService.updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 647 | false /*updateInputWindows*/)) { |
| 648 | updateInputWindowsNeeded = true; |
| 649 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 650 | } |
| 651 | } |
| 652 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 653 | if (isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 654 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 655 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("mLayoutNeeded", |
| 656 | defaultDisplay.pendingLayoutChanges); |
| 657 | } |
| 658 | |
David Stevens | f833ba9 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 659 | final ArraySet<DisplayContent> touchExcludeRegionUpdateDisplays = handleResizingWindows(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 660 | |
| 661 | if (DEBUG_ORIENTATION && mService.mDisplayFrozen) Slog.v(TAG, |
| 662 | "With display frozen, orientationChangeComplete=" + mOrientationChangeComplete); |
| 663 | if (mOrientationChangeComplete) { |
| 664 | if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) { |
| 665 | mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_NONE; |
| 666 | mService.mLastFinishedFreezeSource = mLastWindowFreezeSource; |
| 667 | mService.mH.removeMessages(WINDOW_FREEZE_TIMEOUT); |
| 668 | } |
| 669 | mService.stopFreezingDisplayLocked(); |
| 670 | } |
| 671 | |
| 672 | // Destroy the surface of any windows that are no longer visible. |
| 673 | boolean wallpaperDestroyed = false; |
| 674 | i = mService.mDestroySurface.size(); |
| 675 | if (i > 0) { |
| 676 | do { |
| 677 | i--; |
| 678 | WindowState win = mService.mDestroySurface.get(i); |
| 679 | win.mDestroying = false; |
| 680 | if (mService.mInputMethodWindow == win) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 681 | mService.setInputMethodWindowLocked(null); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 682 | } |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 683 | if (win.getDisplayContent().mWallpaperController.isWallpaperTarget(win)) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 684 | wallpaperDestroyed = true; |
| 685 | } |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 686 | win.destroySurfaceUnchecked(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 687 | } while (i > 0); |
| 688 | mService.mDestroySurface.clear(); |
| 689 | } |
| 690 | |
| 691 | // Time to remove any exiting tokens? |
| 692 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 693 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 694 | displayContent.removeExistingTokensIfPossible(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | if (wallpaperDestroyed) { |
| 698 | defaultDisplay.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 699 | defaultDisplay.setLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 703 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 704 | if (displayContent.pendingLayoutChanges != 0) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 705 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
| 709 | // Finally update all input windows now that the window changes have stabilized. |
| 710 | mService.mInputMonitor.updateInputWindowsLw(true /*force*/); |
| 711 | |
| 712 | mService.setHoldScreenLocked(mHoldScreen); |
| 713 | if (!mService.mDisplayFrozen) { |
Jorim Jaggi | 86c39f9 | 2017-05-02 18:02:46 +0200 | [diff] [blame] | 714 | final int brightness = mScreenBrightness < 0 || mScreenBrightness > 1.0f |
| 715 | ? -1 : toBrightnessOverride(mScreenBrightness); |
| 716 | |
| 717 | // Post these on a handler such that we don't call into power manager service while |
| 718 | // holding the window manager lock to avoid lock contention with power manager lock. |
| 719 | mHandler.obtainMessage(SET_SCREEN_BRIGHTNESS_OVERRIDE, brightness, 0).sendToTarget(); |
| 720 | mHandler.obtainMessage(SET_USER_ACTIVITY_TIMEOUT, mUserActivityTimeout).sendToTarget(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) { |
| 724 | mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent; |
| 725 | mService.mPowerManagerInternal.powerHint( |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 726 | PowerHint.SUSTAINED_PERFORMANCE, |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 727 | (mSustainedPerformanceModeEnabled ? 1 : 0)); |
| 728 | } |
| 729 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 730 | if (mUpdateRotation) { |
| 731 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Andrii Kulian | 48146fd | 2017-08-07 11:22:50 -0700 | [diff] [blame] | 732 | // TODO(multi-display): Update rotation for different displays separately. |
| 733 | final int displayId = defaultDisplay.getDisplayId(); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 734 | if (defaultDisplay.updateRotationUnchecked()) { |
Andrii Kulian | 48146fd | 2017-08-07 11:22:50 -0700 | [diff] [blame] | 735 | mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget(); |
| 736 | } else { |
| 737 | mUpdateRotation = false; |
| 738 | } |
| 739 | // Update rotation of VR virtual display separately. Currently this is the only kind of |
| 740 | // secondary display that can be rotated because of the single-display limitations in |
| 741 | // PhoneWindowManager. |
| 742 | final DisplayContent vrDisplay = mService.mVr2dDisplayId != INVALID_DISPLAY |
| 743 | ? getDisplayContent(mService.mVr2dDisplayId) : null; |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 744 | if (vrDisplay != null && vrDisplay.updateRotationUnchecked()) { |
Andrii Kulian | 48146fd | 2017-08-07 11:22:50 -0700 | [diff] [blame] | 745 | mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mService.mVr2dDisplayId) |
| 746 | .sendToTarget(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
| 750 | if (mService.mWaitingForDrawnCallback != null || |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 751 | (mOrientationChangeComplete && !defaultDisplay.isLayoutNeeded() |
| 752 | && !mUpdateRotation)) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 753 | mService.checkDrawnWindowsLocked(); |
| 754 | } |
| 755 | |
| 756 | final int N = mService.mPendingRemove.size(); |
| 757 | if (N > 0) { |
| 758 | if (mService.mPendingRemoveTmp.length < N) { |
| 759 | mService.mPendingRemoveTmp = new WindowState[N+10]; |
| 760 | } |
| 761 | mService.mPendingRemove.toArray(mService.mPendingRemoveTmp); |
| 762 | mService.mPendingRemove.clear(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 763 | ArrayList<DisplayContent> displayList = new ArrayList(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 764 | for (i = 0; i < N; i++) { |
| 765 | final WindowState w = mService.mPendingRemoveTmp[i]; |
| 766 | w.removeImmediately(); |
| 767 | final DisplayContent displayContent = w.getDisplayContent(); |
| 768 | if (displayContent != null && !displayList.contains(displayContent)) { |
| 769 | displayList.add(displayContent); |
| 770 | } |
| 771 | } |
| 772 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 773 | for (int j = displayList.size() - 1; j >= 0; --j) { |
| 774 | final DisplayContent dc = displayList.get(j); |
| 775 | dc.assignWindowLayers(true /*setLayoutNeeded*/); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
| 779 | // Remove all deferred displays stacks, tasks, and activities. |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 780 | for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) { |
| 781 | mChildren.get(displayNdx).checkCompleteDeferredRemoval(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | if (updateInputWindowsNeeded) { |
| 785 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 786 | } |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 787 | mService.setFocusTaskRegionLocked(null); |
David Stevens | f833ba9 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 788 | if (touchExcludeRegionUpdateDisplays != null) { |
| 789 | final DisplayContent focusedDc = mService.mFocusedApp != null |
| 790 | ? mService.mFocusedApp.getDisplayContent() : null; |
| 791 | for (DisplayContent dc : touchExcludeRegionUpdateDisplays) { |
| 792 | // The focused DisplayContent was recalcuated in setFocusTaskRegionLocked |
| 793 | if (focusedDc != dc) { |
| 794 | dc.setTouchExcludeRegion(null /* focusedTask */); |
| 795 | } |
| 796 | } |
| 797 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 798 | |
| 799 | // Check to see if we are now in a state where the screen should |
| 800 | // be enabled, because the window obscured flags have changed. |
| 801 | mService.enableScreenIfNeededLocked(); |
| 802 | |
| 803 | mService.scheduleAnimationLocked(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 804 | |
| 805 | if (DEBUG_WINDOW_TRACE) Slog.e(TAG, |
| 806 | "performSurfacePlacementInner exit: animating=" + mService.mAnimator.isAnimating()); |
| 807 | } |
| 808 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 809 | private void applySurfaceChangesTransaction(boolean recoveringMemory, int defaultDw, |
| 810 | int defaultDh) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 811 | mHoldScreenWindow = null; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 812 | mObscuringWindow = null; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 813 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 814 | // TODO(multi-display): Support these features on secondary screens. |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 815 | if (mService.mWatermark != null) { |
| 816 | mService.mWatermark.positionSurface(defaultDw, defaultDh); |
| 817 | } |
| 818 | if (mService.mStrictModeFlash != null) { |
| 819 | mService.mStrictModeFlash.positionSurface(defaultDw, defaultDh); |
| 820 | } |
| 821 | if (mService.mCircularDisplayMask != null) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 822 | mService.mCircularDisplayMask.positionSurface(defaultDw, defaultDh, |
| 823 | mService.getDefaultDisplayRotation()); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 824 | } |
| 825 | if (mService.mEmulatorDisplayOverlay != null) { |
| 826 | mService.mEmulatorDisplayOverlay.positionSurface(defaultDw, defaultDh, |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 827 | mService.getDefaultDisplayRotation()); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | boolean focusDisplayed = false; |
| 831 | |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 832 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 833 | for (int j = 0; j < count; ++j) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 834 | final DisplayContent dc = mChildren.get(j); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 835 | focusDisplayed |= dc.applySurfaceChangesTransaction(recoveringMemory); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | if (focusDisplayed) { |
| 839 | mService.mH.sendEmptyMessage(REPORT_LOSING_FOCUS); |
| 840 | } |
| 841 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 842 | // Give the display manager a chance to adjust properties like display rotation if it needs |
| 843 | // to. |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 844 | mService.mDisplayManagerInternal.performTraversal(mDisplayTransaction); |
| 845 | SurfaceControl.mergeToGlobalTransaction(mDisplayTransaction); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /** |
David Stevens | f833ba9 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 849 | * Handles resizing windows during surface placement. |
| 850 | * |
| 851 | * @return A set of any DisplayContent whose touch exclude region needs to be recalculated due |
| 852 | * to a tap-exclude window resizing, or null if no such DisplayContents were found. |
| 853 | */ |
| 854 | private ArraySet<DisplayContent> handleResizingWindows() { |
| 855 | ArraySet<DisplayContent> touchExcludeRegionUpdateSet = null; |
| 856 | for (int i = mService.mResizingWindows.size() - 1; i >= 0; i--) { |
| 857 | WindowState win = mService.mResizingWindows.get(i); |
| 858 | if (win.mAppFreezing) { |
| 859 | // Don't remove this window until rotation has completed. |
| 860 | continue; |
| 861 | } |
| 862 | win.reportResized(); |
| 863 | mService.mResizingWindows.remove(i); |
| 864 | if (WindowManagerService.excludeWindowTypeFromTapOutTask(win.mAttrs.type)) { |
| 865 | final DisplayContent dc = win.getDisplayContent(); |
| 866 | if (touchExcludeRegionUpdateSet == null) { |
| 867 | touchExcludeRegionUpdateSet = new ArraySet<>(); |
| 868 | } |
| 869 | touchExcludeRegionUpdateSet.add(dc); |
| 870 | } |
| 871 | } |
| 872 | return touchExcludeRegionUpdateSet; |
| 873 | } |
| 874 | |
| 875 | /** |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 876 | * @param w WindowState this method is applied to. |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 877 | * @param obscured True if there is a window on top of this obscuring the display. |
| 878 | * @param syswin System window? |
| 879 | * @return True when the display contains content to show the user. When false, the display |
| 880 | * manager may choose to mirror or blank the display. |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 881 | */ |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 882 | boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 883 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 884 | final int attrFlags = attrs.flags; |
Aaron Whyte | 8cbdf04 | 2018-01-23 12:06:02 -0800 | [diff] [blame] | 885 | final boolean onScreen = w.isOnScreen(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 886 | final boolean canBeSeen = w.isDisplayedLw(); |
| 887 | final int privateflags = attrs.privateFlags; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 888 | boolean displayHasContent = false; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 889 | |
Aaron Whyte | 8cbdf04 | 2018-01-23 12:06:02 -0800 | [diff] [blame] | 890 | if (DEBUG_KEEP_SCREEN_ON) { |
| 891 | Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked w: " + w |
| 892 | + ", w.mHasSurface: " + w.mHasSurface |
| 893 | + ", w.isOnScreen(): " + onScreen |
| 894 | + ", w.isDisplayedLw(): " + w.isDisplayedLw() |
| 895 | + ", w.mAttrs.userActivityTimeout: " + w.mAttrs.userActivityTimeout); |
| 896 | } |
| 897 | if (w.mHasSurface && onScreen) { |
| 898 | if (!syswin && w.mAttrs.userActivityTimeout >= 0 && mUserActivityTimeout < 0) { |
| 899 | mUserActivityTimeout = w.mAttrs.userActivityTimeout; |
| 900 | if (DEBUG_KEEP_SCREEN_ON) { |
| 901 | Slog.d(TAG, "mUserActivityTimeout set to " + mUserActivityTimeout); |
| 902 | } |
| 903 | } |
| 904 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 905 | if (w.mHasSurface && canBeSeen) { |
| 906 | if ((attrFlags & FLAG_KEEP_SCREEN_ON) != 0) { |
| 907 | mHoldScreen = w.mSession; |
| 908 | mHoldScreenWindow = w; |
| 909 | } else if (DEBUG_KEEP_SCREEN_ON && w == mService.mLastWakeLockHoldingWindow) { |
| 910 | Slog.d(TAG_KEEP_SCREEN_ON, "handleNotObscuredLocked: " + w + " was holding " |
Wale Ogunwale | 743fcc1 | 2017-06-06 21:36:50 +0000 | [diff] [blame] | 911 | + "screen wakelock but no longer has FLAG_KEEP_SCREEN_ON!!! called by" |
| 912 | + Debug.getCallers(10)); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 913 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 914 | if (!syswin && w.mAttrs.screenBrightness >= 0 && mScreenBrightness < 0) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 915 | mScreenBrightness = w.mAttrs.screenBrightness; |
| 916 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 917 | |
| 918 | final int type = attrs.type; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 919 | // This function assumes that the contents of the default display are processed first |
| 920 | // before secondary displays. |
| 921 | final DisplayContent displayContent = w.getDisplayContent(); |
| 922 | if (displayContent != null && displayContent.isDefaultDisplay) { |
| 923 | // While a dream or keyguard is showing, obscure ordinary application content on |
| 924 | // secondary displays (by forcibly enabling mirroring unless there is other content |
| 925 | // we want to show) but still allow opaque keyguard dialogs to be shown. |
| 926 | if (type == TYPE_DREAM || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 927 | mObscureApplicationContentOnSecondaryDisplays = true; |
| 928 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 929 | displayHasContent = true; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 930 | } else if (displayContent != null && |
| 931 | (!mObscureApplicationContentOnSecondaryDisplays |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 932 | || (obscured && type == TYPE_KEYGUARD_DIALOG))) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 933 | // Allow full screen keyguard presentation dialogs to be seen. |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 934 | displayHasContent = true; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 935 | } |
| 936 | if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) { |
| 937 | mSustainedPerformanceModeCurrent = true; |
| 938 | } |
| 939 | } |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 940 | |
| 941 | return displayHasContent; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | boolean copyAnimToLayoutParams() { |
| 945 | boolean doRequest = false; |
| 946 | |
| 947 | final int bulkUpdateParams = mService.mAnimator.mBulkUpdateParams; |
| 948 | if ((bulkUpdateParams & SET_UPDATE_ROTATION) != 0) { |
| 949 | mUpdateRotation = true; |
| 950 | doRequest = true; |
| 951 | } |
| 952 | if ((bulkUpdateParams & SET_WALLPAPER_MAY_CHANGE) != 0) { |
| 953 | mWallpaperMayChange = true; |
| 954 | doRequest = true; |
| 955 | } |
| 956 | if ((bulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0) { |
| 957 | mWallpaperForceHidingChanged = true; |
| 958 | doRequest = true; |
| 959 | } |
| 960 | if ((bulkUpdateParams & SET_ORIENTATION_CHANGE_COMPLETE) == 0) { |
| 961 | mOrientationChangeComplete = false; |
| 962 | } else { |
| 963 | mOrientationChangeComplete = true; |
| 964 | mLastWindowFreezeSource = mService.mAnimator.mLastWindowFreezeSource; |
| 965 | if (mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_NONE) { |
| 966 | doRequest = true; |
| 967 | } |
| 968 | } |
chaviw | 042059d | 2018-01-11 11:24:08 -0800 | [diff] [blame] | 969 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 970 | if ((bulkUpdateParams & SET_WALLPAPER_ACTION_PENDING) != 0) { |
| 971 | mWallpaperActionPending = true; |
| 972 | } |
| 973 | |
| 974 | return doRequest; |
| 975 | } |
| 976 | |
| 977 | private static int toBrightnessOverride(float value) { |
| 978 | return (int)(value * PowerManager.BRIGHTNESS_ON); |
| 979 | } |
| 980 | |
Jorim Jaggi | 86c39f9 | 2017-05-02 18:02:46 +0200 | [diff] [blame] | 981 | private final class MyHandler extends Handler { |
| 982 | |
| 983 | public MyHandler(Looper looper) { |
| 984 | super(looper); |
| 985 | } |
| 986 | |
| 987 | @Override |
| 988 | public void handleMessage(Message msg) { |
| 989 | switch (msg.what) { |
| 990 | case SET_SCREEN_BRIGHTNESS_OVERRIDE: |
| 991 | mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager( |
| 992 | msg.arg1); |
| 993 | break; |
| 994 | case SET_USER_ACTIVITY_TIMEOUT: |
| 995 | mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager( |
| 996 | (Long) msg.obj); |
| 997 | break; |
| 998 | default: |
| 999 | break; |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1004 | void dumpDisplayContents(PrintWriter pw) { |
| 1005 | pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)"); |
| 1006 | if (mService.mDisplayReady) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1007 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1008 | for (int i = 0; i < count; ++i) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1009 | final DisplayContent displayContent = mChildren.get(i); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1010 | displayContent.dump(pw, " ", true /* dumpAll */); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1011 | } |
| 1012 | } else { |
| 1013 | pw.println(" NO DISPLAY"); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | void dumpLayoutNeededDisplayIds(PrintWriter pw) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1018 | if (!isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1019 | return; |
| 1020 | } |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1021 | pw.print(" mLayoutNeeded on displays="); |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1022 | final int count = mChildren.size(); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1023 | for (int displayNdx = 0; displayNdx < count; ++displayNdx) { |
Wale Ogunwale | eaabfab | 2016-09-16 17:19:52 -0700 | [diff] [blame] | 1024 | final DisplayContent displayContent = mChildren.get(displayNdx); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1025 | if (displayContent.isLayoutNeeded()) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1026 | pw.print(displayContent.getDisplayId()); |
| 1027 | } |
| 1028 | } |
| 1029 | pw.println(); |
| 1030 | } |
| 1031 | |
| 1032 | void dumpWindowsNoHeader(PrintWriter pw, boolean dumpAll, ArrayList<WindowState> windows) { |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 1033 | final int[] index = new int[1]; |
| 1034 | forAllWindows((w) -> { |
| 1035 | if (windows == null || windows.contains(w)) { |
| 1036 | pw.println(" Window #" + index[0] + " " + w + ":"); |
| 1037 | w.dump(pw, " ", dumpAll || windows != null); |
| 1038 | index[0] = index[0] + 1; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1039 | } |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 1040 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1041 | } |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1042 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1043 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 1044 | pw.println(" All tokens:"); |
| 1045 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1046 | mChildren.get(i).dumpTokens(pw, dumpAll); |
| 1047 | } |
| 1048 | } |
| 1049 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1050 | @CallSuper |
| 1051 | @Override |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1052 | public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) { |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1053 | final long token = proto.start(fieldId); |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1054 | super.writeToProto(proto, WINDOW_CONTAINER, trim); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1055 | if (mService.mDisplayReady) { |
| 1056 | final int count = mChildren.size(); |
| 1057 | for (int i = 0; i < count; ++i) { |
| 1058 | final DisplayContent displayContent = mChildren.get(i); |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1059 | displayContent.writeToProto(proto, DISPLAYS, trim); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1060 | } |
| 1061 | } |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1062 | if (!trim) { |
| 1063 | forAllWindows((w) -> { |
| 1064 | w.writeIdentifierToProto(proto, WINDOWS); |
| 1065 | }, true); |
| 1066 | } |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1067 | proto.end(token); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1070 | @Override |
| 1071 | String getName() { |
| 1072 | return "ROOT"; |
| 1073 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1074 | |
| 1075 | @Override |
| 1076 | void scheduleAnimation() { |
| 1077 | mService.scheduleAnimationLocked(); |
| 1078 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1079 | } |