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