blob: c87e3210699b94cb22df70c085f7ce78f54d7843 [file] [log] [blame]
Dianne Hackbornf56e1022011-02-22 10:47:13 -08001/*
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 Hackborn6e1eb762011-02-17 16:07:28 -080015 */
Dianne Hackbornf56e1022011-02-22 10:47:13 -080016
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080017package com.android.server.wm;
18
Jeff Brown4532e612012-04-05 14:27:12 -070019import com.android.server.input.InputManagerService;
20import com.android.server.input.InputApplicationHandle;
21import com.android.server.input.InputWindowHandle;
22
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070023import android.app.ActivityManagerNative;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080024import android.graphics.Rect;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080025import android.os.RemoteException;
26import android.util.Log;
27import android.util.Slog;
Jeff Brown83d616a2012-09-09 20:33:43 -070028import android.view.Display;
Jeff Browncc4f7db2011-08-30 20:34:48 -070029import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080030import android.view.KeyEvent;
31import android.view.WindowManager;
32
Jeff Brown9302c872011-07-13 22:51:29 -070033import java.util.Arrays;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080034
Jeff Browna9d131c2012-09-20 16:48:17 -070035final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080036 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 Brownc042ee22012-05-08 13:03:42 -070045 // 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 Hackborn6e1eb762011-02-17 16:07:28 -080048
49 // When true, need to call updateInputWindowsLw().
50 private boolean mUpdateInputWindowsNeeded = true;
51
Jeff Brown9302c872011-07-13 22:51:29 -070052 // Array of window handles to provide to the input dispatcher.
53 private InputWindowHandle[] mInputWindowHandles;
54 private int mInputWindowHandleCount;
55
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056 // 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
Craig Mautnerbdc748a2013-12-02 14:08:25 -080061 Rect mTmpRect = new Rect();
62
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063 public InputMonitor(WindowManagerService service) {
64 mService = service;
65 }
66
67 /* Notifies the window manager about a broken input channel.
68 *
69 * Called by the InputManager.
70 */
Craig Mautner4cd0c132013-04-16 15:55:52 -070071 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
73 if (inputWindowHandle == null) {
74 return;
75 }
76
77 synchronized (mService.mWindowMap) {
78 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown9302c872011-07-13 22:51:29 -070079 if (windowState != null) {
80 Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState);
81 mService.removeWindowLocked(windowState.mSession, windowState);
82 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080083 }
84 }
85
86 /* Notifies the window manager about an application that is not responding.
87 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
88 *
89 * Called by the InputManager.
90 */
Craig Mautner4cd0c132013-04-16 15:55:52 -070091 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092 public long notifyANR(InputApplicationHandle inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -070093 InputWindowHandle inputWindowHandle, String reason) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080094 AppWindowToken appWindowToken = null;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070095 WindowState windowState = null;
96 boolean aboveSystem = false;
Jeff Brownee172412012-06-18 12:58:03 -070097 synchronized (mService.mWindowMap) {
Jeff Brownee172412012-06-18 12:58:03 -070098 if (inputWindowHandle != null) {
99 windowState = (WindowState) inputWindowHandle.windowState;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100 if (windowState != null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800101 appWindowToken = windowState.mAppToken;
102 }
103 }
Jeff Brownee172412012-06-18 12:58:03 -0700104 if (appWindowToken == null && inputApplicationHandle != null) {
105 appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken;
Jeff Brown9302c872011-07-13 22:51:29 -0700106 }
Jeff Brownee172412012-06-18 12:58:03 -0700107
108 if (windowState != null) {
109 Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
Jeff Brownbd181bb2013-09-10 16:44:24 -0700110 + "sending to " + windowState.mAttrs.getTitle()
111 + ". Reason: " + reason);
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700112 // Figure out whether this window is layered above system windows.
113 // We need to do this here to help the activity manager know how to
114 // layer its ANR dialog.
115 int systemAlertLayer = mService.mPolicy.windowTypeToLayerLw(
116 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
117 aboveSystem = windowState.mBaseLayer > systemAlertLayer;
Jeff Brownee172412012-06-18 12:58:03 -0700118 } else if (appWindowToken != null) {
119 Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
Jeff Brownbd181bb2013-09-10 16:44:24 -0700120 + "sending to application " + appWindowToken.stringName
121 + ". Reason: " + reason);
Jeff Brownee172412012-06-18 12:58:03 -0700122 } else {
Jeff Brownbd181bb2013-09-10 16:44:24 -0700123 Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
124 + ". Reason: " + reason);
Jeff Brownee172412012-06-18 12:58:03 -0700125 }
126
Jeff Brownbd181bb2013-09-10 16:44:24 -0700127 mService.saveANRStateLocked(appWindowToken, windowState, reason);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800128 }
129
130 if (appWindowToken != null && appWindowToken.appToken != null) {
131 try {
132 // Notify the activity manager about the timeout and let it decide whether
133 // to abort dispatching or keep waiting.
Jeff Brownbd181bb2013-09-10 16:44:24 -0700134 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(reason);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135 if (! abort) {
136 // The activity manager declined to abort dispatching.
137 // Wait a bit longer and timeout again later.
138 return appWindowToken.inputDispatchingTimeoutNanos;
139 }
140 } catch (RemoteException ex) {
141 }
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700142 } else if (windowState != null) {
143 try {
144 // Notify the activity manager about the timeout and let it decide whether
145 // to abort dispatching or keep waiting.
146 long timeout = ActivityManagerNative.getDefault().inputDispatchingTimedOut(
Jeff Brownbd181bb2013-09-10 16:44:24 -0700147 windowState.mSession.mPid, aboveSystem, reason);
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700148 if (timeout >= 0) {
149 // The activity manager declined to abort dispatching.
150 // Wait a bit longer and timeout again later.
151 return timeout;
152 }
153 } catch (RemoteException ex) {
154 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 }
156 return 0; // abort dispatching
157 }
158
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700159 private void addInputWindowHandleLw(final InputWindowHandle windowHandle) {
Jeff Brown9302c872011-07-13 22:51:29 -0700160 if (mInputWindowHandles == null) {
161 mInputWindowHandles = new InputWindowHandle[16];
162 }
163 if (mInputWindowHandleCount >= mInputWindowHandles.length) {
164 mInputWindowHandles = Arrays.copyOf(mInputWindowHandles,
165 mInputWindowHandleCount * 2);
166 }
167 mInputWindowHandles[mInputWindowHandleCount++] = windowHandle;
168 }
169
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700170 private void addInputWindowHandleLw(final InputWindowHandle inputWindowHandle,
Adam Lesinski95c42972013-10-02 10:13:27 -0700171 final WindowState child, int flags, int privateFlags, final int type,
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700172 final boolean isVisible, final boolean hasFocus, final boolean hasWallpaper) {
173 // Add a window to our list of input windows.
174 inputWindowHandle.name = child.toString();
Craig Mautner4cd0c132013-04-16 15:55:52 -0700175 final boolean modal = (flags & (WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
176 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) == 0;
177 if (modal && child.mAppToken != null) {
178 // Limit the outer touch to the activity stack region.
179 flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Craig Mautnerbdc748a2013-12-02 14:08:25 -0800180 child.getStackBounds(mTmpRect);
181 inputWindowHandle.touchableRegion.set(mTmpRect);
Craig Mautner4cd0c132013-04-16 15:55:52 -0700182 } else {
183 // Not modal or full screen modal
184 child.getTouchableRegion(inputWindowHandle.touchableRegion);
185 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700186 inputWindowHandle.layoutParamsFlags = flags;
Adam Lesinski95c42972013-10-02 10:13:27 -0700187 inputWindowHandle.layoutParamsPrivateFlags = privateFlags;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700188 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 Hackborna4b7f2f2012-05-21 11:28:41 -0700215
216 addInputWindowHandleLw(inputWindowHandle);
217 }
218
Jeff Brown9302c872011-07-13 22:51:29 -0700219 private void clearInputWindowHandlesLw() {
220 while (mInputWindowHandleCount != 0) {
221 mInputWindowHandles[--mInputWindowHandleCount] = null;
222 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 }
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 Hackbornb961cd22011-06-21 12:13:37 -0700236 if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED updateInputWindowsLw");
Jeff Brown9302c872011-07-13 22:51:29 -0700237
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800238 // 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.
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700243 final WindowStateAnimator universeBackground = mService.mAnimator.mUniverseBackground;
244 final int aboveUniverseLayer = mService.mAnimator.mAboveUniverseLayer;
245 boolean addedUniverse = false;
Filip Gruszczynskib8c06942014-12-04 15:02:18 -0800246 boolean disableWallpaperTouchEvents = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247
248 // If there's a drag in flight, provide a pseudowindow to catch drag input
249 final boolean inDrag = (mService.mDragState != null);
250 if (inDrag) {
251 if (WindowManagerService.DEBUG_DRAG) {
252 Log.d(WindowManagerService.TAG, "Inserting drag window");
253 }
Jeff Browncc4f7db2011-08-30 20:34:48 -0700254 final InputWindowHandle dragWindowHandle = mService.mDragState.mDragWindowHandle;
255 if (dragWindowHandle != null) {
256 addInputWindowHandleLw(dragWindowHandle);
257 } else {
258 Slog.w(WindowManagerService.TAG, "Drag is in progress but there is no "
259 + "drag window handle.");
260 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 }
262
Dianne Hackborndf89e652011-10-06 22:35:11 -0700263 final int NFW = mService.mFakeWindows.size();
264 for (int i = 0; i < NFW; i++) {
265 addInputWindowHandleLw(mService.mFakeWindows.get(i).mWindowHandle);
266 }
267
Jeff Brown83d616a2012-09-09 20:33:43 -0700268 // Add all windows on the default display.
Craig Mautnerf8924152013-07-16 09:10:55 -0700269 final int numDisplays = mService.mDisplayContents.size();
270 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
271 WindowList windows = mService.mDisplayContents.valueAt(displayNdx).getWindowList();
272 for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
273 final WindowState child = windows.get(winNdx);
274 final InputChannel inputChannel = child.mInputChannel;
275 final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
276 if (inputChannel == null || inputWindowHandle == null || child.mRemoved) {
277 // Skip this window because it cannot possibly receive input.
278 continue;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700279 }
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400280
Craig Mautnerf8924152013-07-16 09:10:55 -0700281 final int flags = child.mAttrs.flags;
Adam Lesinski95c42972013-10-02 10:13:27 -0700282 final int privateFlags = child.mAttrs.privateFlags;
Craig Mautnerf8924152013-07-16 09:10:55 -0700283 final int type = child.mAttrs.type;
284
285 final boolean hasFocus = (child == mInputFocus);
286 final boolean isVisible = child.isVisibleLw();
Filip Gruszczynskib8c06942014-12-04 15:02:18 -0800287 if ((privateFlags
288 & WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS)
289 != 0) {
290 disableWallpaperTouchEvents = true;
291 }
Craig Mautnerf8924152013-07-16 09:10:55 -0700292 final boolean hasWallpaper = (child == mService.mWallpaperTarget)
Filip Gruszczynskib8c06942014-12-04 15:02:18 -0800293 && (privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD) == 0
294 && !disableWallpaperTouchEvents;
Craig Mautnerf8924152013-07-16 09:10:55 -0700295 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
303 if (universeBackground != null && !addedUniverse
304 && child.mBaseLayer < aboveUniverseLayer && onDefaultDisplay) {
305 final WindowState u = universeBackground.mWin;
306 if (u.mInputChannel != null && u.mInputWindowHandle != null) {
307 addInputWindowHandleLw(u.mInputWindowHandle, u, u.mAttrs.flags,
Adam Lesinski95c42972013-10-02 10:13:27 -0700308 u.mAttrs.privateFlags, u.mAttrs.type,
309 true, u == mInputFocus, false);
Craig Mautnerf8924152013-07-16 09:10:55 -0700310 }
311 addedUniverse = true;
312 }
313
314 if (child.mWinAnimator != universeBackground) {
Adam Lesinski95c42972013-10-02 10:13:27 -0700315 addInputWindowHandleLw(inputWindowHandle, child, flags, privateFlags, type,
Craig Mautnerf8924152013-07-16 09:10:55 -0700316 isVisible, hasFocus, hasWallpaper);
317 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700318 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800319 }
320
321 // Send windows to native code.
Jeff Brown9302c872011-07-13 22:51:29 -0700322 mService.mInputManager.setInputWindows(mInputWindowHandles);
323
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 // Clear the list in preparation for the next round.
Jeff Brown9302c872011-07-13 22:51:29 -0700325 clearInputWindowHandlesLw();
326
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700327 if (false) Slog.d(WindowManagerService.TAG, "<<<<<<< EXITED updateInputWindowsLw");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800328 }
329
330 /* Notifies that the input device configuration has changed. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700331 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332 public void notifyConfigurationChanged() {
333 mService.sendNewConfiguration();
334
335 synchronized (mInputDevicesReadyMonitor) {
336 if (!mInputDevicesReady) {
337 mInputDevicesReady = true;
338 mInputDevicesReadyMonitor.notifyAll();
339 }
340 }
341 }
342
343 /* Waits until the built-in input devices have been configured. */
344 public boolean waitForInputDevicesReady(long timeoutMillis) {
345 synchronized (mInputDevicesReadyMonitor) {
346 if (!mInputDevicesReady) {
347 try {
348 mInputDevicesReadyMonitor.wait(timeoutMillis);
349 } catch (InterruptedException ex) {
350 }
351 }
352 return mInputDevicesReady;
353 }
354 }
355
356 /* Notifies that the lid switch changed state. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700357 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
359 mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
360 }
Craig Mautner58458122013-09-14 14:59:50 -0700361
Michael Wright3818c922014-09-02 13:59:07 -0700362 /* Notifies that the camera lens cover state has changed. */
363 @Override
364 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
365 mService.mPolicy.notifyCameraLensCoverSwitchChanged(whenNanos, lensCovered);
366 }
367
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368 /* Provides an opportunity for the window manager policy to intercept early key
369 * processing as soon as the key has been read from the device. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700370 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -0700371 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
372 return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800373 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800374
Michael Wright70af00a2014-09-03 19:30:20 -0700375 /* Provides an opportunity for the window manager policy to intercept early motion event
376 * processing when the device is in a non-interactive state since these events are normally
Jeff Brown56194eb2011-03-02 19:23:13 -0800377 * dropped. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700378 @Override
Michael Wright70af00a2014-09-03 19:30:20 -0700379 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
380 return mService.mPolicy.interceptMotionBeforeQueueingNonInteractive(
381 whenNanos, policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800382 }
383
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 /* Provides an opportunity for the window manager policy to process a key before
385 * ordinary dispatch. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700386 @Override
Jeff Brown905805a2011-10-12 13:57:59 -0700387 public long interceptKeyBeforeDispatching(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800388 InputWindowHandle focus, KeyEvent event, int policyFlags) {
389 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
390 return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
391 }
Craig Mautner58458122013-09-14 14:59:50 -0700392
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800393 /* Provides an opportunity for the window manager policy to process a key that
394 * the application did not handle. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700395 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800396 public KeyEvent dispatchUnhandledKey(
397 InputWindowHandle focus, KeyEvent event, int policyFlags) {
398 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
399 return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
400 }
Jeff Brown4532e612012-04-05 14:27:12 -0700401
402 /* Callback to get pointer layer. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700403 @Override
Jeff Brown4532e612012-04-05 14:27:12 -0700404 public int getPointerLayer() {
405 return mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_POINTER)
406 * WindowManagerService.TYPE_LAYER_MULTIPLIER
407 + WindowManagerService.TYPE_LAYER_OFFSET;
408 }
409
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800410 /* Called when the current input focus changes.
411 * Layer assignment is assumed to be complete by the time this is called.
412 */
413 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Craig Mautner58458122013-09-14 14:59:50 -0700414 if (WindowManagerService.DEBUG_FOCUS_LIGHT || WindowManagerService.DEBUG_INPUT) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800415 Slog.d(WindowManagerService.TAG, "Input focus has changed to " + newWindow);
416 }
417
418 if (newWindow != mInputFocus) {
419 if (newWindow != null && newWindow.canReceiveKeys()) {
420 // Displaying a window implicitly causes dispatching to be unpaused.
421 // This is to protect against bugs if someone pauses dispatching but
422 // forgets to resume.
423 newWindow.mToken.paused = false;
424 }
425
426 mInputFocus = newWindow;
427 setUpdateInputWindowsNeededLw();
428
429 if (updateInputWindows) {
430 updateInputWindowsLw(false /*force*/);
431 }
432 }
433 }
Craig Mautner58458122013-09-14 14:59:50 -0700434
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800435 public void setFocusedAppLw(AppWindowToken newApp) {
436 // Focused app has changed.
437 if (newApp == null) {
438 mService.mInputManager.setFocusedApplication(null);
439 } else {
Jeff Brown9302c872011-07-13 22:51:29 -0700440 final InputApplicationHandle handle = newApp.mInputApplicationHandle;
441 handle.name = newApp.toString();
442 handle.dispatchingTimeoutNanos = newApp.inputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800443
Jeff Brown9302c872011-07-13 22:51:29 -0700444 mService.mInputManager.setFocusedApplication(handle);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800445 }
446 }
Craig Mautner58458122013-09-14 14:59:50 -0700447
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800448 public void pauseDispatchingLw(WindowToken window) {
449 if (! window.paused) {
450 if (WindowManagerService.DEBUG_INPUT) {
451 Slog.v(WindowManagerService.TAG, "Pausing WindowToken " + window);
452 }
453
454 window.paused = true;
455 updateInputWindowsLw(true /*force*/);
456 }
457 }
458
459 public void resumeDispatchingLw(WindowToken window) {
460 if (window.paused) {
461 if (WindowManagerService.DEBUG_INPUT) {
462 Slog.v(WindowManagerService.TAG, "Resuming WindowToken " + window);
463 }
464
465 window.paused = false;
466 updateInputWindowsLw(true /*force*/);
467 }
468 }
469
470 public void freezeInputDispatchingLw() {
471 if (! mInputDispatchFrozen) {
472 if (WindowManagerService.DEBUG_INPUT) {
473 Slog.v(WindowManagerService.TAG, "Freezing input dispatching");
474 }
475
476 mInputDispatchFrozen = true;
477 updateInputDispatchModeLw();
478 }
479 }
480
481 public void thawInputDispatchingLw() {
482 if (mInputDispatchFrozen) {
483 if (WindowManagerService.DEBUG_INPUT) {
484 Slog.v(WindowManagerService.TAG, "Thawing input dispatching");
485 }
486
487 mInputDispatchFrozen = false;
488 updateInputDispatchModeLw();
489 }
490 }
491
492 public void setEventDispatchingLw(boolean enabled) {
493 if (mInputDispatchEnabled != enabled) {
494 if (WindowManagerService.DEBUG_INPUT) {
495 Slog.v(WindowManagerService.TAG, "Setting event dispatching to " + enabled);
496 }
497
498 mInputDispatchEnabled = enabled;
499 updateInputDispatchModeLw();
500 }
501 }
502
503 private void updateInputDispatchModeLw() {
504 mService.mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
505 }
Jeff Brownea426552011-07-18 16:53:48 -0700506}