blob: b3244ffb980f15dc3951fdc26e1ecd052bd5b7bf [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
Skuhnef932e562015-08-20 12:07:30 -070019import static com.android.server.wm.WindowState.BOUNDS_FOR_TOUCH;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070020import android.app.ActivityManagerNative;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080021import android.graphics.Rect;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080022import android.os.RemoteException;
23import android.util.Log;
24import android.util.Slog;
Jeff Brown83d616a2012-09-09 20:33:43 -070025import android.view.Display;
Jeff Browncc4f7db2011-08-30 20:34:48 -070026import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080027import android.view.KeyEvent;
28import android.view.WindowManager;
29
Selim Cinekf83e8242015-05-19 18:08:14 -070030import com.android.server.input.InputApplicationHandle;
31import com.android.server.input.InputManagerService;
32import com.android.server.input.InputWindowHandle;
33
Jeff Brown9302c872011-07-13 22:51:29 -070034import java.util.Arrays;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080035
Jeff Browna9d131c2012-09-20 16:48:17 -070036final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080037 private final WindowManagerService mService;
Selim Cinekf83e8242015-05-19 18:08:14 -070038
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080039 // Current window with input focus for keys and other non-touch events. May be null.
40 private WindowState mInputFocus;
Selim Cinekf83e8242015-05-19 18:08:14 -070041
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042 // When true, prevents input dispatch from proceeding until set to false again.
43 private boolean mInputDispatchFrozen;
Selim Cinekf83e8242015-05-19 18:08:14 -070044
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080045 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
Jeff Brownc042ee22012-05-08 13:03:42 -070046 // 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 Hackborn6e1eb762011-02-17 16:07:28 -080049
50 // When true, need to call updateInputWindowsLw().
51 private boolean mUpdateInputWindowsNeeded = true;
52
Jeff Brown9302c872011-07-13 22:51:29 -070053 // Array of window handles to provide to the input dispatcher.
54 private InputWindowHandle[] mInputWindowHandles;
55 private int mInputWindowHandleCount;
56
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080057 // 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 Mautnerbdc748af2013-12-02 14:08:25 -080062 Rect mTmpRect = new Rect();
63
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064 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 Mautner4cd0c13f2013-04-16 15:55:52 -070072 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
74 if (inputWindowHandle == null) {
75 return;
76 }
77
78 synchronized (mService.mWindowMap) {
79 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown9302c872011-07-13 22:51:29 -070080 if (windowState != null) {
81 Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState);
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -070082 mService.removeWindowLocked(windowState);
Jeff Brown9302c872011-07-13 22:51:29 -070083 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080084 }
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 Mautner4cd0c13f2013-04-16 15:55:52 -070092 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093 public long notifyANR(InputApplicationHandle inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -070094 InputWindowHandle inputWindowHandle, String reason) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095 AppWindowToken appWindowToken = null;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070096 WindowState windowState = null;
97 boolean aboveSystem = false;
Jeff Brownee172412012-06-18 12:58:03 -070098 synchronized (mService.mWindowMap) {
Jeff Brownee172412012-06-18 12:58:03 -070099 if (inputWindowHandle != null) {
100 windowState = (WindowState) inputWindowHandle.windowState;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800101 if (windowState != null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800102 appWindowToken = windowState.mAppToken;
103 }
104 }
Jeff Brownee172412012-06-18 12:58:03 -0700105 if (appWindowToken == null && inputApplicationHandle != null) {
106 appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken;
Jeff Brown9302c872011-07-13 22:51:29 -0700107 }
Jeff Brownee172412012-06-18 12:58:03 -0700108
109 if (windowState != null) {
110 Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
Jeff Brownbd181bb2013-09-10 16:44:24 -0700111 + "sending to " + windowState.mAttrs.getTitle()
112 + ". Reason: " + reason);
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700113 // 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 Brownee172412012-06-18 12:58:03 -0700119 } else if (appWindowToken != null) {
120 Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
Jeff Brownbd181bb2013-09-10 16:44:24 -0700121 + "sending to application " + appWindowToken.stringName
122 + ". Reason: " + reason);
Jeff Brownee172412012-06-18 12:58:03 -0700123 } else {
Jeff Brownbd181bb2013-09-10 16:44:24 -0700124 Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
125 + ". Reason: " + reason);
Jeff Brownee172412012-06-18 12:58:03 -0700126 }
127
Jeff Brownbd181bb2013-09-10 16:44:24 -0700128 mService.saveANRStateLocked(appWindowToken, windowState, reason);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800129 }
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 Brownbd181bb2013-09-10 16:44:24 -0700135 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(reason);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 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 Hackborn5fe7e2a2012-10-04 11:58:16 -0700143 } 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 Brownbd181bb2013-09-10 16:44:24 -0700148 windowState.mSession.mPid, aboveSystem, reason);
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700149 if (timeout >= 0) {
150 // The activity manager declined to abort dispatching.
151 // Wait a bit longer and timeout again later.
baik.handef340d2015-04-15 10:21:05 +0900152 return timeout * 1000000L; // nanoseconds
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700153 }
154 } catch (RemoteException ex) {
155 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 }
157 return 0; // abort dispatching
158 }
159
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700160 private void addInputWindowHandleLw(final InputWindowHandle windowHandle) {
Jeff Brown9302c872011-07-13 22:51:29 -0700161 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 Hackborna4b7f2f2012-05-21 11:28:41 -0700171 private void addInputWindowHandleLw(final InputWindowHandle inputWindowHandle,
Craig Mautnerc08eab82014-11-11 09:03:59 -0800172 final WindowState child, int flags, final int type, final boolean isVisible,
173 final boolean hasFocus, final boolean hasWallpaper) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700174 // Add a window to our list of input windows.
175 inputWindowHandle.name = child.toString();
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700176 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;
Skuhnef932e562015-08-20 12:07:30 -0700181 child.getTaskBounds(mTmpRect, BOUNDS_FOR_TOUCH);
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800182 inputWindowHandle.touchableRegion.set(mTmpRect);
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700183 } else {
184 // Not modal or full screen modal
185 child.getTouchableRegion(inputWindowHandle.touchableRegion);
186 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700187 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 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.
Filip Gruszczynskib8c06942014-12-04 15:02:18 -0800243 boolean disableWallpaperTouchEvents = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244
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 Browncc4f7db2011-08-30 20:34:48 -0700251 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 Hackborn6e1eb762011-02-17 16:07:28 -0800258 }
259
Selim Cinekf83e8242015-05-19 18:08:14 -0700260 boolean addInputConsumerHandle = mService.mInputConsumer != null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700261
Jeff Brown83d616a2012-09-09 20:33:43 -0700262 // Add all windows on the default display.
Craig Mautnerf8924152013-07-16 09:10:55 -0700263 final int numDisplays = mService.mDisplayContents.size();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700264 final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
Craig Mautnerf8924152013-07-16 09:10:55 -0700265 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 Hackborna4b7f2f2012-05-21 11:28:41 -0700274 }
Selim Cinekf83e8242015-05-19 18:08:14 -0700275 if (addInputConsumerHandle
276 && inputWindowHandle.layer <= mService.mInputConsumer.mWindowHandle.layer) {
277 addInputWindowHandleLw(mService.mInputConsumer.mWindowHandle);
278 addInputConsumerHandle = false;
279 }
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 }
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700292 final boolean hasWallpaper = wallpaperController.isWallpaperTarget(child)
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
Craig Mautner165be0c2015-01-27 15:16:58 -0800303 addInputWindowHandleLw(inputWindowHandle, child, flags, type, isVisible, hasFocus,
304 hasWallpaper);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700305 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 }
307
308 // Send windows to native code.
Jeff Brown9302c872011-07-13 22:51:29 -0700309 mService.mInputManager.setInputWindows(mInputWindowHandles);
310
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800311 // Clear the list in preparation for the next round.
Jeff Brown9302c872011-07-13 22:51:29 -0700312 clearInputWindowHandlesLw();
313
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700314 if (false) Slog.d(WindowManagerService.TAG, "<<<<<<< EXITED updateInputWindowsLw");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315 }
316
317 /* Notifies that the input device configuration has changed. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700318 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800319 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 Brown0b31d812013-08-22 19:41:29 -0700344 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
346 mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
347 }
Craig Mautner58458122013-09-14 14:59:50 -0700348
Michael Wright3818c922014-09-02 13:59:07 -0700349 /* 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 Hackborn6e1eb762011-02-17 16:07:28 -0800355 /* 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 Brown0b31d812013-08-22 19:41:29 -0700357 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -0700358 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
359 return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800361
Michael Wright70af00a2014-09-03 19:30:20 -0700362 /* 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 Brown56194eb2011-03-02 19:23:13 -0800364 * dropped. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700365 @Override
Michael Wright70af00a2014-09-03 19:30:20 -0700366 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
367 return mService.mPolicy.interceptMotionBeforeQueueingNonInteractive(
368 whenNanos, policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800369 }
370
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 /* Provides an opportunity for the window manager policy to process a key before
372 * ordinary dispatch. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700373 @Override
Jeff Brown905805a2011-10-12 13:57:59 -0700374 public long interceptKeyBeforeDispatching(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 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 Mautner58458122013-09-14 14:59:50 -0700379
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800380 /* Provides an opportunity for the window manager policy to process a key that
381 * the application did not handle. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700382 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800383 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 Brown4532e612012-04-05 14:27:12 -0700388
389 /* Callback to get pointer layer. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700390 @Override
Jeff Brown4532e612012-04-05 14:27:12 -0700391 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 Hackborn6e1eb762011-02-17 16:07:28 -0800397 /* 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 Mautner58458122013-09-14 14:59:50 -0700401 if (WindowManagerService.DEBUG_FOCUS_LIGHT || WindowManagerService.DEBUG_INPUT) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402 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 Mautner58458122013-09-14 14:59:50 -0700421
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800422 public void setFocusedAppLw(AppWindowToken newApp) {
423 // Focused app has changed.
424 if (newApp == null) {
425 mService.mInputManager.setFocusedApplication(null);
426 } else {
Jeff Brown9302c872011-07-13 22:51:29 -0700427 final InputApplicationHandle handle = newApp.mInputApplicationHandle;
428 handle.name = newApp.toString();
429 handle.dispatchingTimeoutNanos = newApp.inputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800430
Jeff Brown9302c872011-07-13 22:51:29 -0700431 mService.mInputManager.setFocusedApplication(handle);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800432 }
433 }
Craig Mautner58458122013-09-14 14:59:50 -0700434
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800435 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 Brownea426552011-07-18 16:53:48 -0700493}