blob: eea0e73c1b0bac22b453d1c550b301bd5dcf9397 [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 Gruszczynski0bd180d2015-12-07 15:43:52 -080019import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
20import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
21import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT;
22import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
23import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -070024
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070025import android.app.ActivityManagerNative;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080026import android.graphics.Rect;
Wale Ogunwalee89eeac2016-03-12 11:07:58 -080027import android.os.Debug;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080028import android.os.RemoteException;
29import android.util.Log;
30import android.util.Slog;
Jeff Brown83d616a2012-09-09 20:33:43 -070031import android.view.Display;
Jeff Browncc4f7db2011-08-30 20:34:48 -070032import android.view.InputChannel;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080033import android.view.KeyEvent;
34import android.view.WindowManager;
35
Selim Cinekf83e8242015-05-19 18:08:14 -070036import com.android.server.input.InputApplicationHandle;
37import com.android.server.input.InputManagerService;
38import com.android.server.input.InputWindowHandle;
39
Wale Ogunwalee89eeac2016-03-12 11:07:58 -080040import java.io.PrintWriter;
Jeff Brown9302c872011-07-13 22:51:29 -070041import java.util.Arrays;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042
Jeff Browna9d131c2012-09-20 16:48:17 -070043final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080044 private final WindowManagerService mService;
Selim Cinekf83e8242015-05-19 18:08:14 -070045
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080046 // Current window with input focus for keys and other non-touch events. May be null.
47 private WindowState mInputFocus;
Selim Cinekf83e8242015-05-19 18:08:14 -070048
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049 // When true, prevents input dispatch from proceeding until set to false again.
50 private boolean mInputDispatchFrozen;
Selim Cinekf83e8242015-05-19 18:08:14 -070051
Wale Ogunwalee89eeac2016-03-12 11:07:58 -080052 // The reason the input is currently frozen or null if the input isn't frozen.
53 private String mInputFreezeReason = null;
54
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
Jeff Brownc042ee22012-05-08 13:03:42 -070056 // Initially false, so that input does not get dispatched until boot is finished at
57 // which point the ActivityManager will enable dispatching.
58 private boolean mInputDispatchEnabled;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059
60 // When true, need to call updateInputWindowsLw().
61 private boolean mUpdateInputWindowsNeeded = true;
62
Jeff Brown9302c872011-07-13 22:51:29 -070063 // Array of window handles to provide to the input dispatcher.
64 private InputWindowHandle[] mInputWindowHandles;
65 private int mInputWindowHandleCount;
66
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080067 // Set to true when the first input device configuration change notification
68 // is received to indicate that the input devices are ready.
69 private final Object mInputDevicesReadyMonitor = new Object();
70 private boolean mInputDevicesReady;
71
72 public InputMonitor(WindowManagerService service) {
73 mService = service;
74 }
Chong Zhang8e89b312015-09-09 15:09:30 -070075
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076 /* Notifies the window manager about a broken input channel.
Chong Zhang8e89b312015-09-09 15:09:30 -070077 *
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080078 * Called by the InputManager.
79 */
Craig Mautner4cd0c13f2013-04-16 15:55:52 -070080 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080081 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
82 if (inputWindowHandle == null) {
83 return;
84 }
85
86 synchronized (mService.mWindowMap) {
87 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown9302c872011-07-13 22:51:29 -070088 if (windowState != null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080089 Slog.i(TAG_WM, "WINDOW DIED " + windowState);
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -070090 mService.removeWindowLocked(windowState);
Jeff Brown9302c872011-07-13 22:51:29 -070091 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092 }
93 }
Chong Zhang8e89b312015-09-09 15:09:30 -070094
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095 /* Notifies the window manager about an application that is not responding.
96 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Chong Zhang8e89b312015-09-09 15:09:30 -070097 *
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098 * Called by the InputManager.
99 */
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700100 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800101 public long notifyANR(InputApplicationHandle inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700102 InputWindowHandle inputWindowHandle, String reason) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800103 AppWindowToken appWindowToken = null;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700104 WindowState windowState = null;
105 boolean aboveSystem = false;
Jeff Brownee172412012-06-18 12:58:03 -0700106 synchronized (mService.mWindowMap) {
Jeff Brownee172412012-06-18 12:58:03 -0700107 if (inputWindowHandle != null) {
108 windowState = (WindowState) inputWindowHandle.windowState;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109 if (windowState != null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110 appWindowToken = windowState.mAppToken;
111 }
112 }
Jeff Brownee172412012-06-18 12:58:03 -0700113 if (appWindowToken == null && inputApplicationHandle != null) {
114 appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken;
Jeff Brown9302c872011-07-13 22:51:29 -0700115 }
Jeff Brownee172412012-06-18 12:58:03 -0700116
117 if (windowState != null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800118 Slog.i(TAG_WM, "Input event dispatching timed out "
Jeff Brownbd181bb2013-09-10 16:44:24 -0700119 + "sending to " + windowState.mAttrs.getTitle()
120 + ". Reason: " + reason);
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700121 // Figure out whether this window is layered above system windows.
122 // We need to do this here to help the activity manager know how to
123 // layer its ANR dialog.
124 int systemAlertLayer = mService.mPolicy.windowTypeToLayerLw(
125 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
126 aboveSystem = windowState.mBaseLayer > systemAlertLayer;
Jeff Brownee172412012-06-18 12:58:03 -0700127 } else if (appWindowToken != null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800128 Slog.i(TAG_WM, "Input event dispatching timed out "
Jeff Brownbd181bb2013-09-10 16:44:24 -0700129 + "sending to application " + appWindowToken.stringName
130 + ". Reason: " + reason);
Jeff Brownee172412012-06-18 12:58:03 -0700131 } else {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800132 Slog.i(TAG_WM, "Input event dispatching timed out "
Jeff Brownbd181bb2013-09-10 16:44:24 -0700133 + ". Reason: " + reason);
Jeff Brownee172412012-06-18 12:58:03 -0700134 }
135
Jeff Brownbd181bb2013-09-10 16:44:24 -0700136 mService.saveANRStateLocked(appWindowToken, windowState, reason);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137 }
138
139 if (appWindowToken != null && appWindowToken.appToken != null) {
140 try {
141 // Notify the activity manager about the timeout and let it decide whether
142 // to abort dispatching or keep waiting.
Jeff Brownbd181bb2013-09-10 16:44:24 -0700143 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(reason);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 if (! abort) {
145 // The activity manager declined to abort dispatching.
146 // Wait a bit longer and timeout again later.
147 return appWindowToken.inputDispatchingTimeoutNanos;
148 }
149 } catch (RemoteException ex) {
150 }
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700151 } else if (windowState != null) {
152 try {
153 // Notify the activity manager about the timeout and let it decide whether
154 // to abort dispatching or keep waiting.
155 long timeout = ActivityManagerNative.getDefault().inputDispatchingTimedOut(
Jeff Brownbd181bb2013-09-10 16:44:24 -0700156 windowState.mSession.mPid, aboveSystem, reason);
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700157 if (timeout >= 0) {
158 // The activity manager declined to abort dispatching.
159 // Wait a bit longer and timeout again later.
baik.handef340d2015-04-15 10:21:05 +0900160 return timeout * 1000000L; // nanoseconds
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700161 }
162 } catch (RemoteException ex) {
163 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164 }
165 return 0; // abort dispatching
166 }
167
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700168 private void addInputWindowHandleLw(final InputWindowHandle windowHandle) {
Jeff Brown9302c872011-07-13 22:51:29 -0700169 if (mInputWindowHandles == null) {
170 mInputWindowHandles = new InputWindowHandle[16];
171 }
172 if (mInputWindowHandleCount >= mInputWindowHandles.length) {
173 mInputWindowHandles = Arrays.copyOf(mInputWindowHandles,
174 mInputWindowHandleCount * 2);
175 }
176 mInputWindowHandles[mInputWindowHandleCount++] = windowHandle;
177 }
178
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700179 private void addInputWindowHandleLw(final InputWindowHandle inputWindowHandle,
Craig Mautnerc08eab82014-11-11 09:03:59 -0800180 final WindowState child, int flags, final int type, final boolean isVisible,
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800181 final boolean hasFocus, final boolean hasWallpaper) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700182 // Add a window to our list of input windows.
183 inputWindowHandle.name = child.toString();
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800184 flags = child.getTouchableRegion(inputWindowHandle.touchableRegion, flags);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700185 inputWindowHandle.layoutParamsFlags = flags;
186 inputWindowHandle.layoutParamsType = type;
187 inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
188 inputWindowHandle.visible = isVisible;
189 inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
190 inputWindowHandle.hasFocus = hasFocus;
191 inputWindowHandle.hasWallpaper = hasWallpaper;
192 inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false;
193 inputWindowHandle.layer = child.mLayer;
194 inputWindowHandle.ownerPid = child.mSession.mPid;
195 inputWindowHandle.ownerUid = child.mSession.mUid;
196 inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
197
198 final Rect frame = child.mFrame;
199 inputWindowHandle.frameLeft = frame.left;
200 inputWindowHandle.frameTop = frame.top;
201 inputWindowHandle.frameRight = frame.right;
202 inputWindowHandle.frameBottom = frame.bottom;
203
Chong Zhangb15758a2015-11-17 12:12:03 -0800204 if (child.isDockedInEffect()) {
205 // Adjust to account for non-resizeable tasks that's scrolled
206 inputWindowHandle.frameLeft += child.mXOffset;
207 inputWindowHandle.frameTop += child.mYOffset;
208 inputWindowHandle.frameRight += child.mXOffset;
209 inputWindowHandle.frameBottom += child.mYOffset;
210 }
211
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700212 if (child.mGlobalScale != 1) {
213 // If we are scaling the window, input coordinates need
214 // to be inversely scaled to map from what is on screen
215 // to what is actually being touched in the UI.
216 inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale;
217 } else {
218 inputWindowHandle.scaleFactor = 1;
219 }
220
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700221 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800222 Slog.d(TAG_WM, "addInputWindowHandle: "
Chong Zhangb15758a2015-11-17 12:12:03 -0800223 + child + ", " + inputWindowHandle);
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700224 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700225 addInputWindowHandleLw(inputWindowHandle);
226 }
227
Jeff Brown9302c872011-07-13 22:51:29 -0700228 private void clearInputWindowHandlesLw() {
229 while (mInputWindowHandleCount != 0) {
230 mInputWindowHandles[--mInputWindowHandleCount] = null;
231 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 }
233
234 public void setUpdateInputWindowsNeededLw() {
235 mUpdateInputWindowsNeeded = true;
236 }
237
238 /* Updates the cached window information provided to the input dispatcher. */
239 public void updateInputWindowsLw(boolean force) {
240 if (!force && !mUpdateInputWindowsNeeded) {
241 return;
242 }
243 mUpdateInputWindowsNeeded = false;
244
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800245 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED updateInputWindowsLw");
Jeff Brown9302c872011-07-13 22:51:29 -0700246
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 // Populate the input window list with information about all of the windows that
248 // could potentially receive input.
249 // As an optimization, we could try to prune the list of windows but this turns
250 // out to be difficult because only the native code knows for sure which window
251 // currently has touch focus.
Filip Gruszczynskib8c06942014-12-04 15:02:18 -0800252 boolean disableWallpaperTouchEvents = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800253
254 // If there's a drag in flight, provide a pseudowindow to catch drag input
255 final boolean inDrag = (mService.mDragState != null);
256 if (inDrag) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800257 if (DEBUG_DRAG) {
258 Log.d(TAG_WM, "Inserting drag window");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259 }
Jeff Browncc4f7db2011-08-30 20:34:48 -0700260 final InputWindowHandle dragWindowHandle = mService.mDragState.mDragWindowHandle;
261 if (dragWindowHandle != null) {
262 addInputWindowHandleLw(dragWindowHandle);
263 } else {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800264 Slog.w(TAG_WM, "Drag is in progress but there is no "
Jeff Browncc4f7db2011-08-30 20:34:48 -0700265 + "drag window handle.");
266 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267 }
268
Chong Zhang8e89b312015-09-09 15:09:30 -0700269 final boolean inPositioning = (mService.mTaskPositioner != null);
270 if (inPositioning) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800271 if (DEBUG_TASK_POSITIONING) {
272 Log.d(TAG_WM, "Inserting window handle for repositioning");
Chong Zhang8e89b312015-09-09 15:09:30 -0700273 }
274 final InputWindowHandle dragWindowHandle = mService.mTaskPositioner.mDragWindowHandle;
275 if (dragWindowHandle != null) {
276 addInputWindowHandleLw(dragWindowHandle);
277 } else {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800278 Slog.e(TAG_WM,
Chong Zhang8e89b312015-09-09 15:09:30 -0700279 "Repositioning is in progress but there is no drag window handle.");
280 }
281 }
282
Selim Cinekf83e8242015-05-19 18:08:14 -0700283 boolean addInputConsumerHandle = mService.mInputConsumer != null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700284
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -0700285 boolean addWallpaperInputConsumerHandle = mService.mWallpaperInputConsumer != null;
286
Jeff Brown83d616a2012-09-09 20:33:43 -0700287 // Add all windows on the default display.
Craig Mautnerf8924152013-07-16 09:10:55 -0700288 final int numDisplays = mService.mDisplayContents.size();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700289 final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
Craig Mautnerf8924152013-07-16 09:10:55 -0700290 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700291 final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
292 final WindowList windows = displayContent.getWindowList();
Craig Mautnerf8924152013-07-16 09:10:55 -0700293 for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
294 final WindowState child = windows.get(winNdx);
295 final InputChannel inputChannel = child.mInputChannel;
296 final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
297 if (inputChannel == null || inputWindowHandle == null || child.mRemoved) {
298 // Skip this window because it cannot possibly receive input.
299 continue;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700300 }
Selim Cinekf83e8242015-05-19 18:08:14 -0700301 if (addInputConsumerHandle
302 && inputWindowHandle.layer <= mService.mInputConsumer.mWindowHandle.layer) {
303 addInputWindowHandleLw(mService.mInputConsumer.mWindowHandle);
304 addInputConsumerHandle = false;
305 }
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400306
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -0700307 if (addWallpaperInputConsumerHandle) {
308 if (child.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER) {
309 // Add the wallpaper input consumer above the first wallpaper window.
310 addInputWindowHandleLw(mService.mWallpaperInputConsumer.mWindowHandle);
311 addWallpaperInputConsumerHandle = false;
312 }
313 }
314
Craig Mautnerf8924152013-07-16 09:10:55 -0700315 final int flags = child.mAttrs.flags;
Adam Lesinski95c42972013-10-02 10:13:27 -0700316 final int privateFlags = child.mAttrs.privateFlags;
Craig Mautnerf8924152013-07-16 09:10:55 -0700317 final int type = child.mAttrs.type;
318
319 final boolean hasFocus = (child == mInputFocus);
320 final boolean isVisible = child.isVisibleLw();
Filip Gruszczynskib8c06942014-12-04 15:02:18 -0800321 if ((privateFlags
322 & WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS)
323 != 0) {
324 disableWallpaperTouchEvents = true;
325 }
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700326 final boolean hasWallpaper = wallpaperController.isWallpaperTarget(child)
Filip Gruszczynskib8c06942014-12-04 15:02:18 -0800327 && (privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD) == 0
328 && !disableWallpaperTouchEvents;
Craig Mautnerf8924152013-07-16 09:10:55 -0700329 final boolean onDefaultDisplay = (child.getDisplayId() == Display.DEFAULT_DISPLAY);
330
331 // If there's a drag in progress and 'child' is a potential drop target,
332 // make sure it's been told about the drag
333 if (inDrag && isVisible && onDefaultDisplay) {
334 mService.mDragState.sendDragStartedIfNeededLw(child);
335 }
336
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800337 addInputWindowHandleLw(
338 inputWindowHandle, child, flags, type, isVisible, hasFocus, hasWallpaper);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700339 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 }
341
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -0700342 if (addWallpaperInputConsumerHandle) {
343 // No wallpaper found, add the wallpaper input consumer at the end.
344 addInputWindowHandleLw(mService.mWallpaperInputConsumer.mWindowHandle);
345 }
346
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800347 // Send windows to native code.
Jeff Brown9302c872011-07-13 22:51:29 -0700348 mService.mInputManager.setInputWindows(mInputWindowHandles);
349
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 // Clear the list in preparation for the next round.
Jeff Brown9302c872011-07-13 22:51:29 -0700351 clearInputWindowHandlesLw();
352
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800353 if (false) Slog.d(TAG_WM, "<<<<<<< EXITED updateInputWindowsLw");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800354 }
355
356 /* Notifies that the input device configuration has changed. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700357 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 public void notifyConfigurationChanged() {
359 mService.sendNewConfiguration();
360
361 synchronized (mInputDevicesReadyMonitor) {
362 if (!mInputDevicesReady) {
363 mInputDevicesReady = true;
364 mInputDevicesReadyMonitor.notifyAll();
365 }
366 }
367 }
368
369 /* Waits until the built-in input devices have been configured. */
370 public boolean waitForInputDevicesReady(long timeoutMillis) {
371 synchronized (mInputDevicesReadyMonitor) {
372 if (!mInputDevicesReady) {
373 try {
374 mInputDevicesReadyMonitor.wait(timeoutMillis);
375 } catch (InterruptedException ex) {
376 }
377 }
378 return mInputDevicesReady;
379 }
380 }
381
382 /* Notifies that the lid switch changed state. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700383 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
385 mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
386 }
Craig Mautner58458122013-09-14 14:59:50 -0700387
Michael Wright3818c922014-09-02 13:59:07 -0700388 /* Notifies that the camera lens cover state has changed. */
389 @Override
390 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
391 mService.mPolicy.notifyCameraLensCoverSwitchChanged(whenNanos, lensCovered);
392 }
393
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800394 /* Provides an opportunity for the window manager policy to intercept early key
395 * processing as soon as the key has been read from the device. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700396 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -0700397 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
398 return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800399 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800400
Michael Wright70af00a2014-09-03 19:30:20 -0700401 /* Provides an opportunity for the window manager policy to intercept early motion event
402 * processing when the device is in a non-interactive state since these events are normally
Jeff Brown56194eb2011-03-02 19:23:13 -0800403 * dropped. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700404 @Override
Michael Wright70af00a2014-09-03 19:30:20 -0700405 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
406 return mService.mPolicy.interceptMotionBeforeQueueingNonInteractive(
407 whenNanos, policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800408 }
409
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800410 /* Provides an opportunity for the window manager policy to process a key before
411 * ordinary dispatch. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700412 @Override
Jeff Brown905805a2011-10-12 13:57:59 -0700413 public long interceptKeyBeforeDispatching(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 InputWindowHandle focus, KeyEvent event, int policyFlags) {
415 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
416 return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
417 }
Craig Mautner58458122013-09-14 14:59:50 -0700418
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419 /* Provides an opportunity for the window manager policy to process a key that
420 * the application did not handle. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700421 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800422 public KeyEvent dispatchUnhandledKey(
423 InputWindowHandle focus, KeyEvent event, int policyFlags) {
424 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
425 return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
426 }
Jeff Brown4532e612012-04-05 14:27:12 -0700427
428 /* Callback to get pointer layer. */
Jeff Brown0b31d812013-08-22 19:41:29 -0700429 @Override
Jeff Brown4532e612012-04-05 14:27:12 -0700430 public int getPointerLayer() {
431 return mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_POINTER)
432 * WindowManagerService.TYPE_LAYER_MULTIPLIER
433 + WindowManagerService.TYPE_LAYER_OFFSET;
434 }
435
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800436 /* Called when the current input focus changes.
437 * Layer assignment is assumed to be complete by the time this is called.
438 */
439 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700440 if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800441 Slog.d(TAG_WM, "Input focus has changed to " + newWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800442 }
443
444 if (newWindow != mInputFocus) {
445 if (newWindow != null && newWindow.canReceiveKeys()) {
446 // Displaying a window implicitly causes dispatching to be unpaused.
447 // This is to protect against bugs if someone pauses dispatching but
448 // forgets to resume.
449 newWindow.mToken.paused = false;
450 }
451
452 mInputFocus = newWindow;
453 setUpdateInputWindowsNeededLw();
454
455 if (updateInputWindows) {
456 updateInputWindowsLw(false /*force*/);
457 }
458 }
459 }
Craig Mautner58458122013-09-14 14:59:50 -0700460
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800461 public void setFocusedAppLw(AppWindowToken newApp) {
462 // Focused app has changed.
463 if (newApp == null) {
464 mService.mInputManager.setFocusedApplication(null);
465 } else {
Jeff Brown9302c872011-07-13 22:51:29 -0700466 final InputApplicationHandle handle = newApp.mInputApplicationHandle;
467 handle.name = newApp.toString();
468 handle.dispatchingTimeoutNanos = newApp.inputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469
Jeff Brown9302c872011-07-13 22:51:29 -0700470 mService.mInputManager.setFocusedApplication(handle);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800471 }
472 }
Craig Mautner58458122013-09-14 14:59:50 -0700473
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800474 public void pauseDispatchingLw(WindowToken window) {
475 if (! window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700476 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800477 Slog.v(TAG_WM, "Pausing WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800478 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700479
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800480 window.paused = true;
481 updateInputWindowsLw(true /*force*/);
482 }
483 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700484
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800485 public void resumeDispatchingLw(WindowToken window) {
486 if (window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700487 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800488 Slog.v(TAG_WM, "Resuming WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700490
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800491 window.paused = false;
492 updateInputWindowsLw(true /*force*/);
493 }
494 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700495
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800496 public void freezeInputDispatchingLw() {
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800497 if (!mInputDispatchFrozen) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700498 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800499 Slog.v(TAG_WM, "Freezing input dispatching");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800500 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700501
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800502 mInputDispatchFrozen = true;
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800503
504 if (DEBUG_INPUT || true) {
505 mInputFreezeReason = Debug.getCallers(6);
506 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800507 updateInputDispatchModeLw();
508 }
509 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700510
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800511 public void thawInputDispatchingLw() {
512 if (mInputDispatchFrozen) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700513 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800514 Slog.v(TAG_WM, "Thawing input dispatching");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800515 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700516
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800517 mInputDispatchFrozen = false;
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800518 mInputFreezeReason = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519 updateInputDispatchModeLw();
520 }
521 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700522
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800523 public void setEventDispatchingLw(boolean enabled) {
524 if (mInputDispatchEnabled != enabled) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700525 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800526 Slog.v(TAG_WM, "Setting event dispatching to " + enabled);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800527 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700528
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800529 mInputDispatchEnabled = enabled;
530 updateInputDispatchModeLw();
531 }
532 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700533
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800534 private void updateInputDispatchModeLw() {
535 mService.mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
536 }
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800537
538 void dump(PrintWriter pw, String prefix) {
539 if (mInputFreezeReason != null) {
540 pw.println(prefix + "mInputFreezeReason=" + mInputFreezeReason);
541 }
542 }
Jeff Brownea426552011-07-18 16:53:48 -0700543}