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