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