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