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