Dianne Hackborn | f56e102 | 2011-02-22 10:47:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 15 | */ |
Dianne Hackborn | f56e102 | 2011-02-22 10:47:13 -0800 | [diff] [blame] | 16 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
| 18 | |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 20 | import static com.android.server.wm.WindowManagerService.DEBUG_FOCUS_LIGHT; |
| 21 | import static com.android.server.wm.WindowManagerService.DEBUG_INPUT; |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 22 | |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 23 | import android.app.ActivityManagerNative; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 24 | import android.graphics.Rect; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 25 | import android.os.RemoteException; |
| 26 | import android.util.Log; |
| 27 | import android.util.Slog; |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 28 | import android.view.Display; |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 29 | import android.view.InputChannel; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 30 | import android.view.KeyEvent; |
| 31 | import android.view.WindowManager; |
| 32 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 33 | import com.android.server.input.InputApplicationHandle; |
| 34 | import com.android.server.input.InputManagerService; |
| 35 | import com.android.server.input.InputWindowHandle; |
| 36 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 37 | import java.util.Arrays; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 38 | |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 39 | final class InputMonitor implements InputManagerService.WindowManagerCallbacks { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 40 | private final WindowManagerService mService; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 41 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 42 | // Current window with input focus for keys and other non-touch events. May be null. |
| 43 | private WindowState mInputFocus; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 44 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 45 | // When true, prevents input dispatch from proceeding until set to false again. |
| 46 | private boolean mInputDispatchFrozen; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 47 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 48 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
Jeff Brown | c042ee2 | 2012-05-08 13:03:42 -0700 | [diff] [blame] | 49 | // Initially false, so that input does not get dispatched until boot is finished at |
| 50 | // which point the ActivityManager will enable dispatching. |
| 51 | private boolean mInputDispatchEnabled; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 52 | |
| 53 | // When true, need to call updateInputWindowsLw(). |
| 54 | private boolean mUpdateInputWindowsNeeded = true; |
| 55 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 56 | // Array of window handles to provide to the input dispatcher. |
| 57 | private InputWindowHandle[] mInputWindowHandles; |
| 58 | private int mInputWindowHandleCount; |
| 59 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 60 | // Set to true when the first input device configuration change notification |
| 61 | // is received to indicate that the input devices are ready. |
| 62 | private final Object mInputDevicesReadyMonitor = new Object(); |
| 63 | private boolean mInputDevicesReady; |
| 64 | |
| 65 | public InputMonitor(WindowManagerService service) { |
| 66 | mService = service; |
| 67 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 68 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 69 | /* Notifies the window manager about a broken input channel. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 70 | * |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 71 | * Called by the InputManager. |
| 72 | */ |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 73 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 74 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
| 75 | if (inputWindowHandle == null) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | synchronized (mService.mWindowMap) { |
| 80 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 81 | if (windowState != null) { |
| 82 | Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState); |
Wale Ogunwale | a6ab5c4 | 2015-04-24 09:00:25 -0700 | [diff] [blame] | 83 | mService.removeWindowLocked(windowState); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 84 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 85 | } |
| 86 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 87 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 88 | /* Notifies the window manager about an application that is not responding. |
| 89 | * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 90 | * |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 91 | * Called by the InputManager. |
| 92 | */ |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 93 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 94 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 95 | InputWindowHandle inputWindowHandle, String reason) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 96 | AppWindowToken appWindowToken = null; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 97 | WindowState windowState = null; |
| 98 | boolean aboveSystem = false; |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 99 | synchronized (mService.mWindowMap) { |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 100 | if (inputWindowHandle != null) { |
| 101 | windowState = (WindowState) inputWindowHandle.windowState; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 102 | if (windowState != null) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 103 | appWindowToken = windowState.mAppToken; |
| 104 | } |
| 105 | } |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 106 | if (appWindowToken == null && inputApplicationHandle != null) { |
| 107 | appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 108 | } |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 109 | |
| 110 | if (windowState != null) { |
| 111 | Slog.i(WindowManagerService.TAG, "Input event dispatching timed out " |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 112 | + "sending to " + windowState.mAttrs.getTitle() |
| 113 | + ". Reason: " + reason); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 114 | // Figure out whether this window is layered above system windows. |
| 115 | // We need to do this here to help the activity manager know how to |
| 116 | // layer its ANR dialog. |
| 117 | int systemAlertLayer = mService.mPolicy.windowTypeToLayerLw( |
| 118 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 119 | aboveSystem = windowState.mBaseLayer > systemAlertLayer; |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 120 | } else if (appWindowToken != null) { |
| 121 | Slog.i(WindowManagerService.TAG, "Input event dispatching timed out " |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 122 | + "sending to application " + appWindowToken.stringName |
| 123 | + ". Reason: " + reason); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 124 | } else { |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 125 | Slog.i(WindowManagerService.TAG, "Input event dispatching timed out " |
| 126 | + ". Reason: " + reason); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 129 | mService.saveANRStateLocked(appWindowToken, windowState, reason); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | if (appWindowToken != null && appWindowToken.appToken != null) { |
| 133 | try { |
| 134 | // Notify the activity manager about the timeout and let it decide whether |
| 135 | // to abort dispatching or keep waiting. |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 136 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(reason); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 137 | if (! abort) { |
| 138 | // The activity manager declined to abort dispatching. |
| 139 | // Wait a bit longer and timeout again later. |
| 140 | return appWindowToken.inputDispatchingTimeoutNanos; |
| 141 | } |
| 142 | } catch (RemoteException ex) { |
| 143 | } |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 144 | } else if (windowState != null) { |
| 145 | try { |
| 146 | // Notify the activity manager about the timeout and let it decide whether |
| 147 | // to abort dispatching or keep waiting. |
| 148 | long timeout = ActivityManagerNative.getDefault().inputDispatchingTimedOut( |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 149 | windowState.mSession.mPid, aboveSystem, reason); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 150 | if (timeout >= 0) { |
| 151 | // The activity manager declined to abort dispatching. |
| 152 | // Wait a bit longer and timeout again later. |
baik.han | def340d | 2015-04-15 10:21:05 +0900 | [diff] [blame] | 153 | return timeout * 1000000L; // nanoseconds |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 154 | } |
| 155 | } catch (RemoteException ex) { |
| 156 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 157 | } |
| 158 | return 0; // abort dispatching |
| 159 | } |
| 160 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 161 | private void addInputWindowHandleLw(final InputWindowHandle windowHandle) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 162 | if (mInputWindowHandles == null) { |
| 163 | mInputWindowHandles = new InputWindowHandle[16]; |
| 164 | } |
| 165 | if (mInputWindowHandleCount >= mInputWindowHandles.length) { |
| 166 | mInputWindowHandles = Arrays.copyOf(mInputWindowHandles, |
| 167 | mInputWindowHandleCount * 2); |
| 168 | } |
| 169 | mInputWindowHandles[mInputWindowHandleCount++] = windowHandle; |
| 170 | } |
| 171 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 172 | private void addInputWindowHandleLw(final InputWindowHandle inputWindowHandle, |
Craig Mautner | c08eab8 | 2014-11-11 09:03:59 -0800 | [diff] [blame] | 173 | final WindowState child, int flags, final int type, final boolean isVisible, |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 174 | final boolean hasFocus, final boolean hasWallpaper) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 175 | // Add a window to our list of input windows. |
| 176 | inputWindowHandle.name = child.toString(); |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 177 | flags = child.getTouchableRegion(inputWindowHandle.touchableRegion, flags); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 178 | inputWindowHandle.layoutParamsFlags = flags; |
| 179 | inputWindowHandle.layoutParamsType = type; |
| 180 | inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 181 | inputWindowHandle.visible = isVisible; |
| 182 | inputWindowHandle.canReceiveKeys = child.canReceiveKeys(); |
| 183 | inputWindowHandle.hasFocus = hasFocus; |
| 184 | inputWindowHandle.hasWallpaper = hasWallpaper; |
| 185 | inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 186 | inputWindowHandle.layer = child.mLayer; |
| 187 | inputWindowHandle.ownerPid = child.mSession.mPid; |
| 188 | inputWindowHandle.ownerUid = child.mSession.mUid; |
| 189 | inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures; |
| 190 | |
| 191 | final Rect frame = child.mFrame; |
| 192 | inputWindowHandle.frameLeft = frame.left; |
| 193 | inputWindowHandle.frameTop = frame.top; |
| 194 | inputWindowHandle.frameRight = frame.right; |
| 195 | inputWindowHandle.frameBottom = frame.bottom; |
| 196 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 197 | if (child.isDockedInEffect()) { |
| 198 | // Adjust to account for non-resizeable tasks that's scrolled |
| 199 | inputWindowHandle.frameLeft += child.mXOffset; |
| 200 | inputWindowHandle.frameTop += child.mYOffset; |
| 201 | inputWindowHandle.frameRight += child.mXOffset; |
| 202 | inputWindowHandle.frameBottom += child.mYOffset; |
| 203 | } |
| 204 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 205 | if (child.mGlobalScale != 1) { |
| 206 | // If we are scaling the window, input coordinates need |
| 207 | // to be inversely scaled to map from what is on screen |
| 208 | // to what is actually being touched in the UI. |
| 209 | inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale; |
| 210 | } else { |
| 211 | inputWindowHandle.scaleFactor = 1; |
| 212 | } |
| 213 | |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 214 | if (DEBUG_INPUT) { |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 215 | Slog.d(WindowManagerService.TAG, "addInputWindowHandle: " |
| 216 | + child + ", " + inputWindowHandle); |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 217 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 218 | addInputWindowHandleLw(inputWindowHandle); |
| 219 | } |
| 220 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 221 | private void clearInputWindowHandlesLw() { |
| 222 | while (mInputWindowHandleCount != 0) { |
| 223 | mInputWindowHandles[--mInputWindowHandleCount] = null; |
| 224 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | public void setUpdateInputWindowsNeededLw() { |
| 228 | mUpdateInputWindowsNeeded = true; |
| 229 | } |
| 230 | |
| 231 | /* Updates the cached window information provided to the input dispatcher. */ |
| 232 | public void updateInputWindowsLw(boolean force) { |
| 233 | if (!force && !mUpdateInputWindowsNeeded) { |
| 234 | return; |
| 235 | } |
| 236 | mUpdateInputWindowsNeeded = false; |
| 237 | |
Dianne Hackborn | b961cd2 | 2011-06-21 12:13:37 -0700 | [diff] [blame] | 238 | if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED updateInputWindowsLw"); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 239 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 240 | // Populate the input window list with information about all of the windows that |
| 241 | // could potentially receive input. |
| 242 | // As an optimization, we could try to prune the list of windows but this turns |
| 243 | // out to be difficult because only the native code knows for sure which window |
| 244 | // currently has touch focus. |
Filip Gruszczynski | b8c0694 | 2014-12-04 15:02:18 -0800 | [diff] [blame] | 245 | boolean disableWallpaperTouchEvents = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 246 | |
| 247 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 248 | final boolean inDrag = (mService.mDragState != null); |
| 249 | if (inDrag) { |
| 250 | if (WindowManagerService.DEBUG_DRAG) { |
| 251 | Log.d(WindowManagerService.TAG, "Inserting drag window"); |
| 252 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 253 | final InputWindowHandle dragWindowHandle = mService.mDragState.mDragWindowHandle; |
| 254 | if (dragWindowHandle != null) { |
| 255 | addInputWindowHandleLw(dragWindowHandle); |
| 256 | } else { |
| 257 | Slog.w(WindowManagerService.TAG, "Drag is in progress but there is no " |
| 258 | + "drag window handle."); |
| 259 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 262 | final boolean inPositioning = (mService.mTaskPositioner != null); |
| 263 | if (inPositioning) { |
| 264 | if (WindowManagerService.DEBUG_TASK_POSITIONING) { |
| 265 | Log.d(WindowManagerService.TAG, "Inserting window handle for repositioning"); |
| 266 | } |
| 267 | final InputWindowHandle dragWindowHandle = mService.mTaskPositioner.mDragWindowHandle; |
| 268 | if (dragWindowHandle != null) { |
| 269 | addInputWindowHandleLw(dragWindowHandle); |
| 270 | } else { |
| 271 | Slog.e(WindowManagerService.TAG, |
| 272 | "Repositioning is in progress but there is no drag window handle."); |
| 273 | } |
| 274 | } |
| 275 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 276 | boolean addInputConsumerHandle = mService.mInputConsumer != null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 277 | |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 278 | // Add all windows on the default display. |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 279 | final int numDisplays = mService.mDisplayContents.size(); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 280 | final WallpaperController wallpaperController = mService.mWallpaperControllerLocked; |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 281 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 282 | final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx); |
| 283 | final WindowList windows = displayContent.getWindowList(); |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 284 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 285 | final WindowState child = windows.get(winNdx); |
| 286 | final InputChannel inputChannel = child.mInputChannel; |
| 287 | final InputWindowHandle inputWindowHandle = child.mInputWindowHandle; |
| 288 | if (inputChannel == null || inputWindowHandle == null || child.mRemoved) { |
| 289 | // Skip this window because it cannot possibly receive input. |
| 290 | continue; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 291 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 292 | if (addInputConsumerHandle |
| 293 | && inputWindowHandle.layer <= mService.mInputConsumer.mWindowHandle.layer) { |
| 294 | addInputWindowHandleLw(mService.mInputConsumer.mWindowHandle); |
| 295 | addInputConsumerHandle = false; |
| 296 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 297 | |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 298 | final int flags = child.mAttrs.flags; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 299 | final int privateFlags = child.mAttrs.privateFlags; |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 300 | final int type = child.mAttrs.type; |
| 301 | |
| 302 | final boolean hasFocus = (child == mInputFocus); |
| 303 | final boolean isVisible = child.isVisibleLw(); |
Filip Gruszczynski | b8c0694 | 2014-12-04 15:02:18 -0800 | [diff] [blame] | 304 | if ((privateFlags |
| 305 | & WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) |
| 306 | != 0) { |
| 307 | disableWallpaperTouchEvents = true; |
| 308 | } |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 309 | final boolean hasWallpaper = wallpaperController.isWallpaperTarget(child) |
Filip Gruszczynski | b8c0694 | 2014-12-04 15:02:18 -0800 | [diff] [blame] | 310 | && (privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD) == 0 |
| 311 | && !disableWallpaperTouchEvents; |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 312 | final boolean onDefaultDisplay = (child.getDisplayId() == Display.DEFAULT_DISPLAY); |
| 313 | |
| 314 | // If there's a drag in progress and 'child' is a potential drop target, |
| 315 | // make sure it's been told about the drag |
| 316 | if (inDrag && isVisible && onDefaultDisplay) { |
| 317 | mService.mDragState.sendDragStartedIfNeededLw(child); |
| 318 | } |
| 319 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 320 | addInputWindowHandleLw( |
| 321 | inputWindowHandle, child, flags, type, isVisible, hasFocus, hasWallpaper); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 322 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // Send windows to native code. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 326 | mService.mInputManager.setInputWindows(mInputWindowHandles); |
| 327 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 328 | // Clear the list in preparation for the next round. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 329 | clearInputWindowHandlesLw(); |
| 330 | |
Dianne Hackborn | b961cd2 | 2011-06-21 12:13:37 -0700 | [diff] [blame] | 331 | if (false) Slog.d(WindowManagerService.TAG, "<<<<<<< EXITED updateInputWindowsLw"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /* Notifies that the input device configuration has changed. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 335 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 336 | public void notifyConfigurationChanged() { |
| 337 | mService.sendNewConfiguration(); |
| 338 | |
| 339 | synchronized (mInputDevicesReadyMonitor) { |
| 340 | if (!mInputDevicesReady) { |
| 341 | mInputDevicesReady = true; |
| 342 | mInputDevicesReadyMonitor.notifyAll(); |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /* Waits until the built-in input devices have been configured. */ |
| 348 | public boolean waitForInputDevicesReady(long timeoutMillis) { |
| 349 | synchronized (mInputDevicesReadyMonitor) { |
| 350 | if (!mInputDevicesReady) { |
| 351 | try { |
| 352 | mInputDevicesReadyMonitor.wait(timeoutMillis); |
| 353 | } catch (InterruptedException ex) { |
| 354 | } |
| 355 | } |
| 356 | return mInputDevicesReady; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | /* Notifies that the lid switch changed state. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 361 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 362 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 363 | mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 364 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 365 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 366 | /* Notifies that the camera lens cover state has changed. */ |
| 367 | @Override |
| 368 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 369 | mService.mPolicy.notifyCameraLensCoverSwitchChanged(whenNanos, lensCovered); |
| 370 | } |
| 371 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 372 | /* Provides an opportunity for the window manager policy to intercept early key |
| 373 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 374 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 375 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
| 376 | return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 377 | } |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 378 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 379 | /* Provides an opportunity for the window manager policy to intercept early motion event |
| 380 | * processing when the device is in a non-interactive state since these events are normally |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 381 | * dropped. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 382 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 383 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 384 | return mService.mPolicy.interceptMotionBeforeQueueingNonInteractive( |
| 385 | whenNanos, policyFlags); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 388 | /* Provides an opportunity for the window manager policy to process a key before |
| 389 | * ordinary dispatch. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 390 | @Override |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 391 | public long interceptKeyBeforeDispatching( |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 392 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| 393 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| 394 | return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags); |
| 395 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 396 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 397 | /* Provides an opportunity for the window manager policy to process a key that |
| 398 | * the application did not handle. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 399 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 400 | public KeyEvent dispatchUnhandledKey( |
| 401 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| 402 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| 403 | return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags); |
| 404 | } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 405 | |
| 406 | /* Callback to get pointer layer. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 407 | @Override |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 408 | public int getPointerLayer() { |
| 409 | return mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_POINTER) |
| 410 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 411 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 412 | } |
| 413 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 414 | /* Called when the current input focus changes. |
| 415 | * Layer assignment is assumed to be complete by the time this is called. |
| 416 | */ |
| 417 | public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 418 | if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 419 | Slog.d(WindowManagerService.TAG, "Input focus has changed to " + newWindow); |
| 420 | } |
| 421 | |
| 422 | if (newWindow != mInputFocus) { |
| 423 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 424 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 425 | // This is to protect against bugs if someone pauses dispatching but |
| 426 | // forgets to resume. |
| 427 | newWindow.mToken.paused = false; |
| 428 | } |
| 429 | |
| 430 | mInputFocus = newWindow; |
| 431 | setUpdateInputWindowsNeededLw(); |
| 432 | |
| 433 | if (updateInputWindows) { |
| 434 | updateInputWindowsLw(false /*force*/); |
| 435 | } |
| 436 | } |
| 437 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 438 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 439 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 440 | // Focused app has changed. |
| 441 | if (newApp == null) { |
| 442 | mService.mInputManager.setFocusedApplication(null); |
| 443 | } else { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 444 | final InputApplicationHandle handle = newApp.mInputApplicationHandle; |
| 445 | handle.name = newApp.toString(); |
| 446 | handle.dispatchingTimeoutNanos = newApp.inputDispatchingTimeoutNanos; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 447 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 448 | mService.mInputManager.setFocusedApplication(handle); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 449 | } |
| 450 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 451 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 452 | public void pauseDispatchingLw(WindowToken window) { |
| 453 | if (! window.paused) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 454 | if (DEBUG_INPUT) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 455 | Slog.v(WindowManagerService.TAG, "Pausing WindowToken " + window); |
| 456 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 457 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 458 | window.paused = true; |
| 459 | updateInputWindowsLw(true /*force*/); |
| 460 | } |
| 461 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 462 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 463 | public void resumeDispatchingLw(WindowToken window) { |
| 464 | if (window.paused) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 465 | if (DEBUG_INPUT) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 466 | Slog.v(WindowManagerService.TAG, "Resuming WindowToken " + window); |
| 467 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 468 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 469 | window.paused = false; |
| 470 | updateInputWindowsLw(true /*force*/); |
| 471 | } |
| 472 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 473 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 474 | public void freezeInputDispatchingLw() { |
| 475 | if (! mInputDispatchFrozen) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 476 | if (DEBUG_INPUT) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 477 | Slog.v(WindowManagerService.TAG, "Freezing input dispatching"); |
| 478 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 479 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 480 | mInputDispatchFrozen = true; |
| 481 | updateInputDispatchModeLw(); |
| 482 | } |
| 483 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 484 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 485 | public void thawInputDispatchingLw() { |
| 486 | if (mInputDispatchFrozen) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 487 | if (DEBUG_INPUT) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 488 | Slog.v(WindowManagerService.TAG, "Thawing input dispatching"); |
| 489 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 490 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 491 | mInputDispatchFrozen = false; |
| 492 | updateInputDispatchModeLw(); |
| 493 | } |
| 494 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 495 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 496 | public void setEventDispatchingLw(boolean enabled) { |
| 497 | if (mInputDispatchEnabled != enabled) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 498 | if (DEBUG_INPUT) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 499 | Slog.v(WindowManagerService.TAG, "Setting event dispatching to " + enabled); |
| 500 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 501 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 502 | mInputDispatchEnabled = enabled; |
| 503 | updateInputDispatchModeLw(); |
| 504 | } |
| 505 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 506 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 507 | private void updateInputDispatchModeLw() { |
| 508 | mService.mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 509 | } |
Jeff Brown | ea42655 | 2011-07-18 16:53:48 -0700 | [diff] [blame] | 510 | } |