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