blob: 4eda68474547fa846e4bf475246e005bed98d140 [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
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.
15 */
16
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080017package com.android.server.wm;
Jeff Brown46b9ac02010-04-22 18:58:52 -070018
19import com.android.internal.util.XmlUtils;
Jeff Brown46b9ac02010-04-22 18:58:52 -070020
21import org.xmlpull.v1.XmlPullParser;
22
23import android.content.Context;
Jeff Brown349703e2010-06-22 01:27:15 -070024import android.content.pm.PackageManager;
Jeff Brown46b9ac02010-04-22 18:58:52 -070025import android.content.res.Configuration;
Jeff Brown1a84fd12011-06-02 01:26:32 -070026import android.database.ContentObserver;
Jeff Brown46b9ac02010-04-22 18:58:52 -070027import android.os.Environment;
Jeff Brown1a84fd12011-06-02 01:26:32 -070028import android.os.Handler;
Jeff Brown05dc66a2011-03-02 14:41:58 -080029import android.os.Looper;
30import android.os.MessageQueue;
Jeff Brownae9fc032010-08-18 15:51:08 -070031import android.os.SystemProperties;
Jeff Brown1a84fd12011-06-02 01:26:32 -070032import android.provider.Settings;
33import android.provider.Settings.SettingNotFoundException;
Jeff Brown46b9ac02010-04-22 18:58:52 -070034import android.util.Slog;
35import android.util.Xml;
36import android.view.InputChannel;
Jeff Brown8d608662010-08-30 03:02:23 -070037import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -070038import android.view.InputEvent;
Jeff Brown1f245102010-11-18 20:53:46 -080039import android.view.KeyEvent;
Jeff Brown86ea1f52011-04-12 22:39:53 -070040import android.view.PointerIcon;
Jeff Brown46b9ac02010-04-22 18:58:52 -070041import android.view.Surface;
Jeff Browna4547672011-03-02 21:38:11 -080042import android.view.ViewConfiguration;
Jeff Brown83c09682010-12-23 17:50:18 -080043import android.view.WindowManager;
Jeff Brown46b9ac02010-04-22 18:58:52 -070044
Jeff Brown46b9ac02010-04-22 18:58:52 -070045import java.io.File;
Jeff Brown46b9ac02010-04-22 18:58:52 -070046import java.io.FileNotFoundException;
47import java.io.FileReader;
48import java.io.IOException;
Jeff Brown46b9ac02010-04-22 18:58:52 -070049import java.io.PrintWriter;
50import java.util.ArrayList;
51
52/*
53 * Wraps the C++ InputManager and provides its callbacks.
Jeff Brown46b9ac02010-04-22 18:58:52 -070054 */
55public class InputManager {
56 static final String TAG = "InputManager";
57
Jeff Brownb6997262010-10-08 22:31:17 -070058 private static final boolean DEBUG = false;
59
Jeff Brown46b9ac02010-04-22 18:58:52 -070060 private final Callbacks mCallbacks;
61 private final Context mContext;
62 private final WindowManagerService mWindowManagerService;
Jeff Brown1a84fd12011-06-02 01:26:32 -070063
Jeff Brown86ea1f52011-04-12 22:39:53 -070064 private static native void nativeInit(Context context,
65 Callbacks callbacks, MessageQueue messageQueue);
Jeff Brown46b9ac02010-04-22 18:58:52 -070066 private static native void nativeStart();
67 private static native void nativeSetDisplaySize(int displayId, int width, int height);
68 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
69
Jeff Brown6d0fec22010-07-23 21:28:06 -070070 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070071 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070072 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070073 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070074 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070075 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070076 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
77 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070078 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -080079 InputWindowHandle inputWindowHandle, boolean monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -070080 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown6ec402b2010-07-28 15:48:59 -070081 private static native int nativeInjectInputEvent(InputEvent event,
82 int injectorPid, int injectorUid, int syncMode, int timeoutMillis);
Jeff Brown349703e2010-06-22 01:27:15 -070083 private static native void nativeSetInputWindows(InputWindow[] windows);
84 private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -080085 private static native void nativeSetSystemUiVisibility(int visibility);
Jeff Brown349703e2010-06-22 01:27:15 -070086 private static native void nativeSetFocusedApplication(InputApplication application);
Jeff Brown8d608662010-08-30 03:02:23 -070087 private static native InputDevice nativeGetInputDevice(int deviceId);
Jeff Brown57c59372010-09-21 18:22:55 -070088 private static native void nativeGetInputConfiguration(Configuration configuration);
Jeff Brown8d608662010-08-30 03:02:23 -070089 private static native int[] nativeGetInputDeviceIds();
Jeff Browne6504122010-09-27 14:52:15 -070090 private static native boolean nativeTransferTouchFocus(InputChannel fromChannel,
91 InputChannel toChannel);
Jeff Brown1a84fd12011-06-02 01:26:32 -070092 private static native void nativeSetPointerSpeed(int speed);
Jeff Browne33348b2010-07-15 23:54:05 -070093 private static native String nativeDump();
Jeff Brown46b9ac02010-04-22 18:58:52 -070094
Jeff Brown7fbdc842010-06-17 20:52:56 -070095 // Input event injection constants defined in InputDispatcher.h.
96 static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
97 static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
98 static final int INPUT_EVENT_INJECTION_FAILED = 2;
99 static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
100
Jeff Brown6ec402b2010-07-28 15:48:59 -0700101 // Input event injection synchronization modes defined in InputDispatcher.h
102 static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0;
103 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1;
104 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2;
105
Jeff Brown6d0fec22010-07-23 21:28:06 -0700106 // Key states (may be returned by queries about the current state of a
107 // particular key code, scan code or switch).
108
109 /** The key state is unknown or the requested key itself is not supported. */
110 public static final int KEY_STATE_UNKNOWN = -1;
111
112 /** The key is up. /*/
113 public static final int KEY_STATE_UP = 0;
114
115 /** The key is down. */
116 public static final int KEY_STATE_DOWN = 1;
117
118 /** The key is down but is a virtual key press that is being emulated by the system. */
119 public static final int KEY_STATE_VIRTUAL = 2;
120
Jeff Browne33348b2010-07-15 23:54:05 -0700121 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700122 this.mContext = context;
123 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700124 this.mCallbacks = new Callbacks();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800125
126 Looper looper = windowManagerService.mH.getLooper();
127
Jeff Brown46b9ac02010-04-22 18:58:52 -0700128 Slog.i(TAG, "Initializing input manager");
Jeff Brown86ea1f52011-04-12 22:39:53 -0700129 nativeInit(mContext, mCallbacks, looper.getQueue());
Jeff Brown46b9ac02010-04-22 18:58:52 -0700130 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700131
Jeff Brown46b9ac02010-04-22 18:58:52 -0700132 public void start() {
133 Slog.i(TAG, "Starting input manager");
134 nativeStart();
Jeff Brown1a84fd12011-06-02 01:26:32 -0700135
136 registerPointerSpeedSettingObserver();
137 updatePointerSpeedFromSettings();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700138 }
139
140 public void setDisplaySize(int displayId, int width, int height) {
141 if (width <= 0 || height <= 0) {
142 throw new IllegalArgumentException("Invalid display id or dimensions.");
143 }
144
Jeff Brownb6997262010-10-08 22:31:17 -0700145 if (DEBUG) {
146 Slog.d(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
147 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700148 nativeSetDisplaySize(displayId, width, height);
149 }
150
151 public void setDisplayOrientation(int displayId, int rotation) {
152 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
153 throw new IllegalArgumentException("Invalid rotation.");
154 }
155
Jeff Brownb6997262010-10-08 22:31:17 -0700156 if (DEBUG) {
157 Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation);
158 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700159 nativeSetDisplayOrientation(displayId, rotation);
160 }
161
162 public void getInputConfiguration(Configuration config) {
163 if (config == null) {
164 throw new IllegalArgumentException("config must not be null.");
165 }
166
Jeff Brown57c59372010-09-21 18:22:55 -0700167 nativeGetInputConfiguration(config);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700168 }
169
Jeff Brown6d0fec22010-07-23 21:28:06 -0700170 /**
171 * Gets the current state of a key or button by key code.
172 * @param deviceId The input device id, or -1 to consult all devices.
173 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
174 * consider all input sources. An input device is consulted if at least one of its
175 * non-class input source bits matches the specified source mask.
176 * @param keyCode The key code to check.
177 * @return The key state.
178 */
179 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
180 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700181 }
182
Jeff Brown6d0fec22010-07-23 21:28:06 -0700183 /**
184 * Gets the current state of a key or button by scan code.
185 * @param deviceId The input device id, or -1 to consult all devices.
186 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
187 * consider all input sources. An input device is consulted if at least one of its
188 * non-class input source bits matches the specified source mask.
189 * @param scanCode The scan code to check.
190 * @return The key state.
191 */
192 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
193 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700194 }
195
Jeff Brown6d0fec22010-07-23 21:28:06 -0700196 /**
197 * Gets the current state of a switch by switch code.
198 * @param deviceId The input device id, or -1 to consult all devices.
199 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
200 * consider all input sources. An input device is consulted if at least one of its
201 * non-class input source bits matches the specified source mask.
202 * @param switchCode The switch code to check.
203 * @return The switch state.
204 */
205 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
206 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700207 }
208
Jeff Brown6d0fec22010-07-23 21:28:06 -0700209 /**
210 * Determines whether the specified key codes are supported by a particular device.
211 * @param deviceId The input device id, or -1 to consult all devices.
212 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
213 * consider all input sources. An input device is consulted if at least one of its
214 * non-class input source bits matches the specified source mask.
215 * @param keyCodes The array of key codes to check.
216 * @param keyExists An array at least as large as keyCodes whose entries will be set
217 * to true or false based on the presence or absence of support for the corresponding
218 * key codes.
219 * @return True if the lookup was successful, false otherwise.
220 */
221 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700222 if (keyCodes == null) {
223 throw new IllegalArgumentException("keyCodes must not be null.");
224 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700225 if (keyExists == null || keyExists.length < keyCodes.length) {
226 throw new IllegalArgumentException("keyExists must not be null and must be at "
227 + "least as large as keyCodes.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700228 }
229
Jeff Brown6d0fec22010-07-23 21:28:06 -0700230 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700231 }
232
Jeff Browna41ca772010-08-11 14:46:32 -0700233 /**
234 * Creates an input channel that will receive all input from the input dispatcher.
235 * @param inputChannelName The input channel name.
236 * @return The input channel.
237 */
238 public InputChannel monitorInput(String inputChannelName) {
239 if (inputChannelName == null) {
240 throw new IllegalArgumentException("inputChannelName must not be null.");
241 }
242
243 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
Jeff Brown928e0542011-01-10 11:17:36 -0800244 nativeRegisterInputChannel(inputChannels[0], null, true);
Jeff Browna41ca772010-08-11 14:46:32 -0700245 inputChannels[0].dispose(); // don't need to retain the Java object reference
246 return inputChannels[1];
247 }
248
249 /**
250 * Registers an input channel so that it can be used as an input event target.
251 * @param inputChannel The input channel to register.
Jeff Brown928e0542011-01-10 11:17:36 -0800252 * @param inputWindowHandle The handle of the input window associated with the
253 * input channel, or null if none.
Jeff Browna41ca772010-08-11 14:46:32 -0700254 */
Jeff Brown928e0542011-01-10 11:17:36 -0800255 public void registerInputChannel(InputChannel inputChannel,
256 InputWindowHandle inputWindowHandle) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700257 if (inputChannel == null) {
258 throw new IllegalArgumentException("inputChannel must not be null.");
259 }
260
Jeff Brown928e0542011-01-10 11:17:36 -0800261 nativeRegisterInputChannel(inputChannel, inputWindowHandle, false);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700262 }
263
Jeff Browna41ca772010-08-11 14:46:32 -0700264 /**
265 * Unregisters an input channel.
266 * @param inputChannel The input channel to unregister.
267 */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700268 public void unregisterInputChannel(InputChannel inputChannel) {
269 if (inputChannel == null) {
270 throw new IllegalArgumentException("inputChannel must not be null.");
271 }
272
273 nativeUnregisterInputChannel(inputChannel);
274 }
275
Jeff Brown46b9ac02010-04-22 18:58:52 -0700276 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700277 * Injects an input event into the event system on behalf of an application.
278 * The synchronization mode determines whether the method blocks while waiting for
279 * input injection to proceed.
280 *
281 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
282 * is assumed always to be successful.
283 *
284 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
285 * dispatched so that the input dispatcher can determine whether input event injection will
286 * be permitted based on the current input focus. Does not wait for the input event to
287 * finish processing.
288 *
289 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
290 * be completely processed.
291 *
Jeff Brown46b9ac02010-04-22 18:58:52 -0700292 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700293 * @param injectorPid The pid of the injecting application.
294 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700295 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700296 * @param timeoutMillis The injection timeout in milliseconds.
297 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700298 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700299 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
300 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700301 if (event == null) {
302 throw new IllegalArgumentException("event must not be null");
303 }
304 if (injectorPid < 0 || injectorUid < 0) {
305 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
306 }
307 if (timeoutMillis <= 0) {
308 throw new IllegalArgumentException("timeoutMillis must be positive");
309 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700310
311 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700312 }
313
Jeff Brown8d608662010-08-30 03:02:23 -0700314 /**
315 * Gets information about the input device with the specified id.
316 * @param id The device id.
317 * @return The input device or null if not found.
318 */
319 public InputDevice getInputDevice(int deviceId) {
320 return nativeGetInputDevice(deviceId);
321 }
322
323 /**
324 * Gets the ids of all input devices in the system.
325 * @return The input device ids.
326 */
327 public int[] getInputDeviceIds() {
328 return nativeGetInputDeviceIds();
329 }
330
Jeff Brown349703e2010-06-22 01:27:15 -0700331 public void setInputWindows(InputWindow[] windows) {
332 nativeSetInputWindows(windows);
333 }
334
335 public void setFocusedApplication(InputApplication application) {
336 nativeSetFocusedApplication(application);
337 }
338
Jeff Brown349703e2010-06-22 01:27:15 -0700339 public void setInputDispatchMode(boolean enabled, boolean frozen) {
340 nativeSetInputDispatchMode(enabled, frozen);
341 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800342
343 public void setSystemUiVisibility(int visibility) {
344 nativeSetSystemUiVisibility(visibility);
345 }
346
Jeff Browne6504122010-09-27 14:52:15 -0700347 /**
348 * Atomically transfers touch focus from one window to another as identified by
349 * their input channels. It is possible for multiple windows to have
350 * touch focus if they support split touch dispatch
351 * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
352 * method only transfers touch focus of the specified window without affecting
353 * other windows that may also have touch focus at the same time.
354 * @param fromChannel The channel of a window that currently has touch focus.
355 * @param toChannel The channel of the window that should receive touch focus in
356 * place of the first.
357 * @return True if the transfer was successful. False if the window with the
358 * specified channel did not actually have touch focus at the time of the request.
359 */
360 public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) {
361 if (fromChannel == null) {
362 throw new IllegalArgumentException("fromChannel must not be null.");
363 }
364 if (toChannel == null) {
365 throw new IllegalArgumentException("toChannel must not be null.");
366 }
367 return nativeTransferTouchFocus(fromChannel, toChannel);
368 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800369
Jeff Brown1a84fd12011-06-02 01:26:32 -0700370 /**
371 * Set the pointer speed.
372 * @param speed The pointer speed as a value between -7 (slowest) and 7 (fastest)
373 * where 0 is the default speed.
374 */
375 public void setPointerSpeed(int speed) {
376 speed = Math.min(Math.max(speed, -7), 7);
377 nativeSetPointerSpeed(speed);
378 }
379
380 public void updatePointerSpeedFromSettings() {
381 int speed = getPointerSpeedSetting(0);
382 setPointerSpeed(speed);
383 }
384
385 private void registerPointerSpeedSettingObserver() {
386 mContext.getContentResolver().registerContentObserver(
387 Settings.System.getUriFor(Settings.System.POINTER_SPEED), true,
388 new ContentObserver(mWindowManagerService.mH) {
389 @Override
390 public void onChange(boolean selfChange) {
391 updatePointerSpeedFromSettings();
392 }
393 });
394 }
395
396 private int getPointerSpeedSetting(int defaultValue) {
397 int speed = defaultValue;
398 try {
399 speed = Settings.System.getInt(mContext.getContentResolver(),
400 Settings.System.POINTER_SPEED);
401 } catch (SettingNotFoundException snfe) {
402 }
403 return speed;
404 }
405
Jeff Brown46b9ac02010-04-22 18:58:52 -0700406 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700407 String dumpStr = nativeDump();
408 if (dumpStr != null) {
409 pw.println(dumpStr);
410 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700411 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800412
Jeff Brown46b9ac02010-04-22 18:58:52 -0700413 /*
414 * Callbacks from native.
415 */
416 private class Callbacks {
417 static final String TAG = "InputManager-Callbacks";
418
419 private static final boolean DEBUG_VIRTUAL_KEYS = false;
420 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
Jeff Brown8d608662010-08-30 03:02:23 -0700421 private static final String CALIBRATION_DIR_PATH = "usr/idc/";
Jeff Brown46b9ac02010-04-22 18:58:52 -0700422
Jeff Brown46b9ac02010-04-22 18:58:52 -0700423 @SuppressWarnings("unused")
Jeff Brown57c59372010-09-21 18:22:55 -0700424 public void notifyConfigurationChanged(long whenNanos) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800425 mWindowManagerService.mInputMonitor.notifyConfigurationChanged();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700426 }
427
428 @SuppressWarnings("unused")
429 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700430 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700431 }
432
433 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800434 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
435 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputWindowHandle);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700436 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700437
438 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800439 public long notifyANR(InputApplicationHandle inputApplicationHandle,
440 InputWindowHandle inputWindowHandle) {
441 return mWindowManagerService.mInputMonitor.notifyANR(
442 inputApplicationHandle, inputWindowHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700443 }
444
445 @SuppressWarnings("unused")
Jeff Brown1f245102010-11-18 20:53:46 -0800446 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700447 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
Jeff Brown1f245102010-11-18 20:53:46 -0800448 event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700449 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800450
451 @SuppressWarnings("unused")
452 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
453 return mWindowManagerService.mInputMonitor.interceptMotionBeforeQueueingWhenScreenOff(
454 policyFlags);
455 }
456
Jeff Brown349703e2010-06-22 01:27:15 -0700457 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800458 public boolean interceptKeyBeforeDispatching(InputWindowHandle focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800459 KeyEvent event, int policyFlags) {
460 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(
461 focus, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700462 }
463
464 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800465 public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800466 KeyEvent event, int policyFlags) {
467 return mWindowManagerService.mInputMonitor.dispatchUnhandledKey(
468 focus, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -0700469 }
470
471 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700472 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
473 return mContext.checkPermission(
474 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
475 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700476 }
477
478 @SuppressWarnings("unused")
Jeff Brown46b9ac02010-04-22 18:58:52 -0700479 public boolean filterTouchEvents() {
480 return mContext.getResources().getBoolean(
481 com.android.internal.R.bool.config_filterTouchEvents);
482 }
483
484 @SuppressWarnings("unused")
485 public boolean filterJumpyTouchEvents() {
486 return mContext.getResources().getBoolean(
487 com.android.internal.R.bool.config_filterJumpyTouchEvents);
488 }
Jeff Brownfe508922011-01-18 15:10:10 -0800489
490 @SuppressWarnings("unused")
491 public int getVirtualKeyQuietTimeMillis() {
492 return mContext.getResources().getInteger(
493 com.android.internal.R.integer.config_virtualKeyQuietTimeMillis);
494 }
495
Jeff Brown46b9ac02010-04-22 18:58:52 -0700496 @SuppressWarnings("unused")
Jeff Brown46b9ac02010-04-22 18:58:52 -0700497 public String[] getExcludedDeviceNames() {
498 ArrayList<String> names = new ArrayList<String>();
499
500 // Read partner-provided list of excluded input devices
501 XmlPullParser parser = null;
502 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
503 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
504 FileReader confreader = null;
505 try {
506 confreader = new FileReader(confFile);
507 parser = Xml.newPullParser();
508 parser.setInput(confreader);
509 XmlUtils.beginDocument(parser, "devices");
510
511 while (true) {
512 XmlUtils.nextElement(parser);
513 if (!"device".equals(parser.getName())) {
514 break;
515 }
516 String name = parser.getAttributeValue(null, "name");
517 if (name != null) {
518 names.add(name);
519 }
520 }
521 } catch (FileNotFoundException e) {
522 // It's ok if the file does not exist.
523 } catch (Exception e) {
524 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
525 } finally {
526 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
527 }
528
529 return names.toArray(new String[names.size()]);
530 }
Jeff Browna4547672011-03-02 21:38:11 -0800531
532 @SuppressWarnings("unused")
533 public int getKeyRepeatTimeout() {
534 return ViewConfiguration.getKeyRepeatTimeout();
535 }
536
537 @SuppressWarnings("unused")
538 public int getKeyRepeatDelay() {
539 return ViewConfiguration.getKeyRepeatDelay();
540 }
541
Jeff Brownae9fc032010-08-18 15:51:08 -0700542 @SuppressWarnings("unused")
Jeff Brown214eaf42011-05-26 19:17:02 -0700543 public int getTapTimeout() {
544 return ViewConfiguration.getTapTimeout();
545 }
546
547 @SuppressWarnings("unused")
548 public int getDoubleTapTimeout() {
549 return ViewConfiguration.getDoubleTapTimeout();
550 }
551
552 @SuppressWarnings("unused")
553 public int getLongPressTimeout() {
554 return ViewConfiguration.getLongPressTimeout();
555 }
556
557 @SuppressWarnings("unused")
558 public int getTouchSlop() {
559 return ViewConfiguration.get(mContext).getScaledTouchSlop();
560 }
561
562 @SuppressWarnings("unused")
Jeff Brownae9fc032010-08-18 15:51:08 -0700563 public int getMaxEventsPerSecond() {
564 int result = 0;
565 try {
566 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
567 } catch (NumberFormatException e) {
568 }
569 if (result < 1) {
makarand.karvekar88dd6e62011-03-02 17:11:14 -0600570 result = 55;
Jeff Brownae9fc032010-08-18 15:51:08 -0700571 }
572 return result;
573 }
Jeff Brown83c09682010-12-23 17:50:18 -0800574
575 @SuppressWarnings("unused")
576 public int getPointerLayer() {
577 return mWindowManagerService.mPolicy.windowTypeToLayerLw(
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800578 WindowManager.LayoutParams.TYPE_POINTER)
Jeff Brown83c09682010-12-23 17:50:18 -0800579 * WindowManagerService.TYPE_LAYER_MULTIPLIER
580 + WindowManagerService.TYPE_LAYER_OFFSET;
581 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800582
583 @SuppressWarnings("unused")
584 public PointerIcon getPointerIcon() {
Jeff Brown86ea1f52011-04-12 22:39:53 -0700585 return PointerIcon.getDefaultIcon(mContext);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800586 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700587 }
588}