blob: 55111361a1a69caca99e58adabf3b7fc7c752c34 [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
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070019import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -070020import static com.android.server.wm.WindowManagerService.DEBUG_FOCUS_LIGHT;
21import static com.android.server.wm.WindowManagerService.DEBUG_INPUT;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -070022
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
Selim Cinekf83e8242015-05-19 18:08:14 -070033import com.android.server.input.InputApplicationHandle;
34import com.android.server.input.InputManagerService;
35import com.android.server.input.InputWindowHandle;
36
Jeff Brown9302c872011-07-13 22:51:29 -070037import java.util.Arrays;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080038
Jeff Browna9d131c2012-09-20 16:48:17 -070039final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080040 private final WindowManagerService mService;
Selim Cinekf83e8242015-05-19 18:08:14 -070041
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042 // Current window with input focus for keys and other non-touch events. May be null.
43 private WindowState mInputFocus;
Selim Cinekf83e8242015-05-19 18:08:14 -070044
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080045 // When true, prevents input dispatch from proceeding until set to false again.
46 private boolean mInputDispatchFrozen;
Selim Cinekf83e8242015-05-19 18:08:14 -070047
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
Jeff Brownc042ee22012-05-08 13:03:42 -070049 // Initially false, so that input does not get dispatched until boot is finished at
50 // which point the ActivityManager will enable dispatching.
51 private boolean mInputDispatchEnabled;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052
53 // When true, need to call updateInputWindowsLw().
54 private boolean mUpdateInputWindowsNeeded = true;
55
Jeff Brown9302c872011-07-13 22:51:29 -070056 // Array of window handles to provide to the input dispatcher.
57 private InputWindowHandle[] mInputWindowHandles;
58 private int mInputWindowHandleCount;
59
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060 // Set to true when the first input device configuration change notification
61 // is received to indicate that the input devices are ready.
62 private final Object mInputDevicesReadyMonitor = new Object();
63 private boolean mInputDevicesReady;
64
65 public InputMonitor(WindowManagerService service) {
66 mService = service;
67 }
Chong Zhang8e89b312015-09-09 15:09:30 -070068
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080069 /* Notifies the window manager about a broken input channel.
Chong Zhang8e89b312015-09-09 15:09:30 -070070 *
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080071 * Called by the InputManager.
72 */
Craig Mautner4cd0c13f2013-04-16 15:55:52 -070073 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
75 if (inputWindowHandle == null) {
76 return;
77 }
78
79 synchronized (mService.mWindowMap) {
80 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown9302c872011-07-13 22:51:29 -070081 if (windowState != null) {
82 Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState);
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -070083 mService.removeWindowLocked(windowState);
Jeff Brown9302c872011-07-13 22:51:29 -070084 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080085 }
86 }
Chong Zhang8e89b312015-09-09 15:09:30 -070087
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080088 /* Notifies the window manager about an application that is not responding.
89 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Chong Zhang8e89b312015-09-09 15:09:30 -070090 *
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080091 * Called by the InputManager.
92 */
Craig Mautner4cd0c13f2013-04-16 15:55:52 -070093 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080094 public long notifyANR(InputApplicationHandle inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -070095 InputWindowHandle inputWindowHandle, String reason) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 AppWindowToken appWindowToken = null;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070097 WindowState windowState = null;
98 boolean aboveSystem = false;
Jeff Brownee172412012-06-18 12:58:03 -070099 synchronized (mService.mWindowMap) {
Jeff Brownee172412012-06-18 12:58:03 -0700100 if (inputWindowHandle != null) {
101 windowState = (WindowState) inputWindowHandle.windowState;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800102 if (windowState != null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800103 appWindowToken = windowState.mAppToken;
104 }
105 }
Jeff Brownee172412012-06-18 12:58:03 -0700106 if (appWindowToken == null && inputApplicationHandle != null) {
107 appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken;
Jeff Brown9302c872011-07-13 22:51:29 -0700108 }
Jeff Brownee172412012-06-18 12:58:03 -0700109
110 if (windowState != null) {
111 Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
Jeff Brownbd181bb2013-09-10 16:44:24 -0700112 + "sending to " + windowState.mAttrs.getTitle()
113 + ". Reason: " + reason);
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700114 // Figure out whether this window is layered above system windows.
115 // We need to do this here to help the activity manager know how to
116 // layer its ANR dialog.
117 int systemAlertLayer = mService.mPolicy.windowTypeToLayerLw(
118 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
119 aboveSystem = windowState.mBaseLayer > systemAlertLayer;
Jeff Brownee172412012-06-18 12:58:03 -0700120 } else if (appWindowToken != null) {
121 Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
Jeff Brownbd181bb2013-09-10 16:44:24 -0700122 + "sending to application " + appWindowToken.stringName
123 + ". Reason: " + reason);
Jeff Brownee172412012-06-18 12:58:03 -0700124 } else {
Jeff Brownbd181bb2013-09-10 16:44:24 -0700125 Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
126 + ". Reason: " + reason);
Jeff Brownee172412012-06-18 12:58:03 -0700127 }
128
Jeff Brownbd181bb2013-09-10 16:44:24 -0700129 mService.saveANRStateLocked(appWindowToken, windowState, reason);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 }
131
132 if (appWindowToken != null && appWindowToken.appToken != null) {
133 try {
134 // Notify the activity manager about the timeout and let it decide whether
135 // to abort dispatching or keep waiting.
Jeff Brownbd181bb2013-09-10 16:44:24 -0700136 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(reason);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137 if (! abort) {
138 // The activity manager declined to abort dispatching.
139 // Wait a bit longer and timeout again later.
140 return appWindowToken.inputDispatchingTimeoutNanos;
141 }
142 } catch (RemoteException ex) {
143 }
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700144 } else if (windowState != null) {
145 try {
146 // Notify the activity manager about the timeout and let it decide whether
147 // to abort dispatching or keep waiting.
148 long timeout = ActivityManagerNative.getDefault().inputDispatchingTimedOut(
Jeff Brownbd181bb2013-09-10 16:44:24 -0700149 windowState.mSession.mPid, aboveSystem, reason);
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700150 if (timeout >= 0) {
151 // The activity manager declined to abort dispatching.
152 // Wait a bit longer and timeout again later.
baik.handef340d2015-04-15 10:21:05 +0900153 return timeout * 1000000L; // nanoseconds
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700154 }
155 } catch (RemoteException ex) {
156 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 }
158 return 0; // abort dispatching
159 }
160
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700161 private void addInputWindowHandleLw(final InputWindowHandle windowHandle) {
Jeff Brown9302c872011-07-13 22:51:29 -0700162 if (mInputWindowHandles == null) {
163 mInputWindowHandles = new InputWindowHandle[16];
164 }
165 if (mInputWindowHandleCount >= mInputWindowHandles.length) {
166 mInputWindowHandles = Arrays.copyOf(mInputWindowHandles,
167 mInputWindowHandleCount * 2);
168 }
169 mInputWindowHandles[mInputWindowHandleCount++] = windowHandle;
170 }
171
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700172 private void addInputWindowHandleLw(final InputWindowHandle inputWindowHandle,
Craig Mautnerc08eab82014-11-11 09:03:59 -0800173 final WindowState child, int flags, final int type, final boolean isVisible,
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800174 final boolean hasFocus, final boolean hasWallpaper) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700175 // Add a window to our list of input windows.
176 inputWindowHandle.name = child.toString();
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800177 flags = child.getTouchableRegion(inputWindowHandle.touchableRegion, flags);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700178 inputWindowHandle.layoutParamsFlags = flags;
179 inputWindowHandle.layoutParamsType = type;
180 inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
181 inputWindowHandle.visible = isVisible;
182 inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
183 inputWindowHandle.hasFocus = hasFocus;
184 inputWindowHandle.hasWallpaper = hasWallpaper;
185 inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false;
186 inputWindowHandle.layer = child.mLayer;
187 inputWindowHandle.ownerPid = child.mSession.mPid;
188 inputWindowHandle.ownerUid = child.mSession.mUid;
189 inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
190
191 final Rect frame = child.mFrame;
192 inputWindowHandle.frameLeft = frame.left;
193 inputWindowHandle.frameTop = frame.top;
194 inputWindowHandle.frameRight = frame.right;
195 inputWindowHandle.frameBottom = frame.bottom;
196
Chong Zhangb15758a2015-11-17 12:12:03 -0800197 if (child.isDockedInEffect()) {
198 // Adjust to account for non-resizeable tasks that's scrolled
199 inputWindowHandle.frameLeft += child.mXOffset;
200 inputWindowHandle.frameTop += child.mYOffset;
201 inputWindowHandle.frameRight += child.mXOffset;
202 inputWindowHandle.frameBottom += child.mYOffset;
203 }
204
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700205 if (child.mGlobalScale != 1) {
206 // If we are scaling the window, input coordinates need
207 // to be inversely scaled to map from what is on screen
208 // to what is actually being touched in the UI.
209 inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale;
210 } else {
211 inputWindowHandle.scaleFactor = 1;
212 }
213
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700214 if (DEBUG_INPUT) {
Chong Zhangb15758a2015-11-17 12:12:03 -0800215 Slog.d(WindowManagerService.TAG, "addInputWindowHandle: "
216 + child + ", " + inputWindowHandle);
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700217 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700218 addInputWindowHandleLw(inputWindowHandle);
219 }
220
Jeff Brown9302c872011-07-13 22:51:29 -0700221 private void clearInputWindowHandlesLw() {
222 while (mInputWindowHandleCount != 0) {
223 mInputWindowHandles[--mInputWindowHandleCount] = null;
224 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 }
226
227 public void setUpdateInputWindowsNeededLw() {
228 mUpdateInputWindowsNeeded = true;
229 }
230
231 /* Updates the cached window information provided to the input dispatcher. */
232 public void updateInputWindowsLw(boolean force) {
233 if (!force && !mUpdateInputWindowsNeeded) {
234 return;
235 }
236 mUpdateInputWindowsNeeded = false;
237
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700238 if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED updateInputWindowsLw");
Jeff Brown9302c872011-07-13 22:51:29 -0700239
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 // Populate the input window list with information about all of the windows that
241 // could potentially receive input.
242 // As an optimization, we could try to prune the list of windows but this turns
243 // out to be difficult because only the native code knows for sure which window
244 // currently has touch focus.
Filip Gruszczynskib8c06942014-12-04 15:02:18 -0800245 boolean disableWallpaperTouchEvents = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246
247 // If there's a drag in flight, provide a pseudowindow to catch drag input
248 final boolean inDrag = (mService.mDragState != null);
249 if (inDrag) {
250 if (WindowManagerService.DEBUG_DRAG) {
251 Log.d(WindowManagerService.TAG, "Inserting drag window");
252 }
Jeff Browncc4f7db2011-08-30 20:34:48 -0700253 final InputWindowHandle dragWindowHandle = mService.mDragState.mDragWindowHandle;
254 if (dragWindowHandle != null) {
255 addInputWindowHandleLw(dragWindowHandle);
256 } else {
257 Slog.w(WindowManagerService.TAG, "Drag is in progress but there is no "
258 + "drag window handle.");
259 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260 }
261
Chong Zhang8e89b312015-09-09 15:09:30 -0700262 final boolean inPositioning = (mService.mTaskPositioner != null);
263 if (inPositioning) {
264 if (WindowManagerService.DEBUG_TASK_POSITIONING) {
265 Log.d(WindowManagerService.TAG, "Inserting window handle for repositioning");
266 }
267 final InputWindowHandle dragWindowHandle = mService.mTaskPositioner.mDragWindowHandle;
268 if (dragWindowHandle != null) {
269 addInputWindowHandleLw(dragWindowHandle);
270 } else {
271 Slog.e(WindowManagerService.TAG,
272 "Repositioning is in progress but there is no drag window handle.");
273 }
274 }
275
Selim Cinekf83e8242015-05-19 18:08:14 -0700276 boolean addInputConsumerHandle = mService.mInputConsumer != null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700277
Jeff Brown83d616a2012-09-09 20:33:43 -0700278 // Add all windows on the default display.
Craig Mautnerf8924152013-07-16 09:10:55 -0700279 final int numDisplays = mService.mDisplayContents.size();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700280 final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
Craig Mautnerf8924152013-07-16 09:10:55 -0700281 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700282 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
283 final WindowList windows = displayContent.getWindowList();
Craig Mautnerf8924152013-07-16 09:10:55 -0700284 for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
285 final WindowState child = windows.get(winNdx);
286 final InputChannel inputChannel = child.mInputChannel;
287 final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
288 if (inputChannel == null || inputWindowHandle == null || child.mRemoved) {
289 // Skip this window because it cannot possibly receive input.
290 continue;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700291 }
Selim Cinekf83e8242015-05-19 18:08:14 -0700292 if (addInputConsumerHandle
293 && inputWindowHandle.layer <= mService.mInputConsumer.mWindowHandle.layer) {
294 addInputWindowHandleLw(mService.mInputConsumer.mWindowHandle);
295 addInputConsumerHandle = false;
296 }
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400297
Craig Mautnerf8924152013-07-16 09:10:55 -0700298 final int flags = child.mAttrs.flags;
Adam Lesinski95c42972013-10-02 10:13:27 -0700299 final int privateFlags = child.mAttrs.privateFlags;
Craig Mautnerf8924152013-07-16 09:10:55 -0700300 final int type = child.mAttrs.type;
301
302 final boolean hasFocus = (child == mInputFocus);
303 final boolean isVisible = child.isVisibleLw();
Filip Gruszczynskib8c06942014-12-04 15:02:18 -0800304 if ((privateFlags
305 & WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS)
306 != 0) {
307 disableWallpaperTouchEvents = true;
308 }
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700309 final boolean hasWallpaper = wallpaperController.isWallpaperTarget(child)
Filip Gruszczynskib8c06942014-12-04 15:02:18 -0800310 && (privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD) == 0
311 && !disableWallpaperTouchEvents;
Craig Mautnerf8924152013-07-16 09:10:55 -0700312 final boolean onDefaultDisplay = (child.getDisplayId() == Display.DEFAULT_DISPLAY);
313
314 // If there's a drag in progress and 'child' is a potential drop target,
315 // make sure it's been told about the drag
316 if (inDrag && isVisible && onDefaultDisplay) {
317 mService.mDragState.sendDragStartedIfNeededLw(child);
318 }
319
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800320 addInputWindowHandleLw(
321 inputWindowHandle, child, flags, type, isVisible, hasFocus, hasWallpaper);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700322 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 }
324
325 // Send windows to native code.
Jeff Brown9302c872011-07-13 22:51:29 -0700326 mService.mInputManager.setInputWindows(mInputWindowHandles);
327
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800328 // Clear the list in preparation for the next round.
Jeff Brown9302c872011-07-13 22:51:29 -0700329 clearInputWindowHandlesLw();
330
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700331 if (false) Slog.d(WindowManagerService.TAG, "<<<<<<< EXITED updateInputWindowsLw");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332 }
333
334 /* Notifies that the input device configuration has changed. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700335 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336 public void notifyConfigurationChanged() {
337 mService.sendNewConfiguration();
338
339 synchronized (mInputDevicesReadyMonitor) {
340 if (!mInputDevicesReady) {
341 mInputDevicesReady = true;
342 mInputDevicesReadyMonitor.notifyAll();
343 }
344 }
345 }
346
347 /* Waits until the built-in input devices have been configured. */
348 public boolean waitForInputDevicesReady(long timeoutMillis) {
349 synchronized (mInputDevicesReadyMonitor) {
350 if (!mInputDevicesReady) {
351 try {
352 mInputDevicesReadyMonitor.wait(timeoutMillis);
353 } catch (InterruptedException ex) {
354 }
355 }
356 return mInputDevicesReady;
357 }
358 }
359
360 /* Notifies that the lid switch changed state. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700361 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
363 mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
364 }
Craig Mautner58458122013-09-14 14:59:50 -0700365
Michael Wright3818c922014-09-02 13:59:07 -0700366 /* Notifies that the camera lens cover state has changed. */
367 @Override
368 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
369 mService.mPolicy.notifyCameraLensCoverSwitchChanged(whenNanos, lensCovered);
370 }
371
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800372 /* Provides an opportunity for the window manager policy to intercept early key
373 * processing as soon as the key has been read from the device. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700374 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -0700375 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
376 return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800377 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800378
Michael Wright70af00a2014-09-03 19:30:20 -0700379 /* Provides an opportunity for the window manager policy to intercept early motion event
380 * processing when the device is in a non-interactive state since these events are normally
Jeff Brown56194eb2011-03-02 19:23:13 -0800381 * dropped. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700382 @Override
Michael Wright70af00a2014-09-03 19:30:20 -0700383 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
384 return mService.mPolicy.interceptMotionBeforeQueueingNonInteractive(
385 whenNanos, policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800386 }
387
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800388 /* Provides an opportunity for the window manager policy to process a key before
389 * ordinary dispatch. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700390 @Override
Jeff Brown905805a2011-10-12 13:57:59 -0700391 public long interceptKeyBeforeDispatching(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392 InputWindowHandle focus, KeyEvent event, int policyFlags) {
393 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
394 return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
395 }
Craig Mautner58458122013-09-14 14:59:50 -0700396
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800397 /* Provides an opportunity for the window manager policy to process a key that
398 * the application did not handle. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700399 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800400 public KeyEvent dispatchUnhandledKey(
401 InputWindowHandle focus, KeyEvent event, int policyFlags) {
402 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
403 return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
404 }
Jeff Brown4532e612012-04-05 14:27:12 -0700405
406 /* Callback to get pointer layer. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700407 @Override
Jeff Brown4532e612012-04-05 14:27:12 -0700408 public int getPointerLayer() {
409 return mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_POINTER)
410 * WindowManagerService.TYPE_LAYER_MULTIPLIER
411 + WindowManagerService.TYPE_LAYER_OFFSET;
412 }
413
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 /* Called when the current input focus changes.
415 * Layer assignment is assumed to be complete by the time this is called.
416 */
417 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700418 if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419 Slog.d(WindowManagerService.TAG, "Input focus has changed to " + newWindow);
420 }
421
422 if (newWindow != mInputFocus) {
423 if (newWindow != null && newWindow.canReceiveKeys()) {
424 // Displaying a window implicitly causes dispatching to be unpaused.
425 // This is to protect against bugs if someone pauses dispatching but
426 // forgets to resume.
427 newWindow.mToken.paused = false;
428 }
429
430 mInputFocus = newWindow;
431 setUpdateInputWindowsNeededLw();
432
433 if (updateInputWindows) {
434 updateInputWindowsLw(false /*force*/);
435 }
436 }
437 }
Craig Mautner58458122013-09-14 14:59:50 -0700438
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800439 public void setFocusedAppLw(AppWindowToken newApp) {
440 // Focused app has changed.
441 if (newApp == null) {
442 mService.mInputManager.setFocusedApplication(null);
443 } else {
Jeff Brown9302c872011-07-13 22:51:29 -0700444 final InputApplicationHandle handle = newApp.mInputApplicationHandle;
445 handle.name = newApp.toString();
446 handle.dispatchingTimeoutNanos = newApp.inputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800447
Jeff Brown9302c872011-07-13 22:51:29 -0700448 mService.mInputManager.setFocusedApplication(handle);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800449 }
450 }
Craig Mautner58458122013-09-14 14:59:50 -0700451
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800452 public void pauseDispatchingLw(WindowToken window) {
453 if (! window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700454 if (DEBUG_INPUT) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800455 Slog.v(WindowManagerService.TAG, "Pausing WindowToken " + window);
456 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700457
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800458 window.paused = true;
459 updateInputWindowsLw(true /*force*/);
460 }
461 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700462
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463 public void resumeDispatchingLw(WindowToken window) {
464 if (window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700465 if (DEBUG_INPUT) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800466 Slog.v(WindowManagerService.TAG, "Resuming WindowToken " + window);
467 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700468
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 window.paused = false;
470 updateInputWindowsLw(true /*force*/);
471 }
472 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700473
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800474 public void freezeInputDispatchingLw() {
475 if (! mInputDispatchFrozen) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700476 if (DEBUG_INPUT) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800477 Slog.v(WindowManagerService.TAG, "Freezing input dispatching");
478 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700479
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800480 mInputDispatchFrozen = true;
481 updateInputDispatchModeLw();
482 }
483 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700484
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800485 public void thawInputDispatchingLw() {
486 if (mInputDispatchFrozen) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700487 if (DEBUG_INPUT) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800488 Slog.v(WindowManagerService.TAG, "Thawing input dispatching");
489 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700490
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800491 mInputDispatchFrozen = false;
492 updateInputDispatchModeLw();
493 }
494 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700495
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800496 public void setEventDispatchingLw(boolean enabled) {
497 if (mInputDispatchEnabled != enabled) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700498 if (DEBUG_INPUT) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800499 Slog.v(WindowManagerService.TAG, "Setting event dispatching to " + enabled);
500 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700501
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800502 mInputDispatchEnabled = enabled;
503 updateInputDispatchModeLw();
504 }
505 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700506
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800507 private void updateInputDispatchModeLw() {
508 mService.mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
509 }
Jeff Brownea426552011-07-18 16:53:48 -0700510}