blob: a32f7c1344fe22769448c87c94c99c08463a1906 [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
Jeff Brown4532e612012-04-05 14:27:12 -070017package com.android.server.input;
Jeff Brown46b9ac02010-04-22 18:58:52 -070018
Jeff Brown38f96e52014-02-11 14:32:56 -080019import android.view.Display;
Jeff Browncf39bdf2012-05-18 14:41:19 -070020import com.android.internal.R;
Jeff Brown46b9ac02010-04-22 18:58:52 -070021import com.android.internal.util.XmlUtils;
Jeff Brown4ccb8232014-01-16 22:16:42 -080022import com.android.server.DisplayThread;
23import com.android.server.LocalServices;
Jeff Brown89ef0722011-08-10 16:25:21 -070024import com.android.server.Watchdog;
Jeff Brown46b9ac02010-04-22 18:58:52 -070025
26import org.xmlpull.v1.XmlPullParser;
27
Jeff Browna3bc5652012-04-17 11:42:25 -070028import android.Manifest;
Jeff Browncf39bdf2012-05-18 14:41:19 -070029import android.app.Notification;
30import android.app.NotificationManager;
31import android.app.PendingIntent;
Jeff Brown5bbd4b42012-04-20 19:28:00 -070032import android.bluetooth.BluetoothAdapter;
33import android.bluetooth.BluetoothDevice;
Jeff Brown6ec6f792012-04-17 16:52:41 -070034import android.content.BroadcastReceiver;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070035import android.content.ComponentName;
Jeff Brown46b9ac02010-04-22 18:58:52 -070036import android.content.Context;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070037import android.content.Intent;
Jeff Brown6ec6f792012-04-17 16:52:41 -070038import android.content.IntentFilter;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070039import android.content.pm.ActivityInfo;
Jeff Brown349703e2010-06-22 01:27:15 -070040import android.content.pm.PackageManager;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070041import android.content.pm.ResolveInfo;
42import android.content.pm.PackageManager.NameNotFoundException;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070043import android.content.res.Resources;
Jeff Brown6ec6f792012-04-17 16:52:41 -070044import android.content.res.Resources.NotFoundException;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070045import android.content.res.TypedArray;
46import android.content.res.XmlResourceParser;
Jeff Brown1a84fd12011-06-02 01:26:32 -070047import android.database.ContentObserver;
Jeff Brown4ccb8232014-01-16 22:16:42 -080048import android.hardware.display.DisplayViewport;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070049import android.hardware.input.IInputDevicesChangedListener;
Svetoslav Ganovc9c9a482012-07-16 08:46:07 -070050import android.hardware.input.IInputManager;
RoboErikca9eef62013-12-16 11:27:55 -080051import android.hardware.input.InputDeviceIdentifier;
Jeff Brownac143512012-04-05 18:57:33 -070052import android.hardware.input.InputManager;
Jeff Brown4ccb8232014-01-16 22:16:42 -080053import android.hardware.input.InputManagerInternal;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070054import android.hardware.input.KeyboardLayout;
Jeff Brown4532e612012-04-05 14:27:12 -070055import android.os.Binder;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070056import android.os.Bundle;
Jeff Brown46b9ac02010-04-22 18:58:52 -070057import android.os.Environment;
Jeff Brown4532e612012-04-05 14:27:12 -070058import android.os.Handler;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070059import android.os.IBinder;
Jeff Browna9d131c2012-09-20 16:48:17 -070060import android.os.Looper;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070061import android.os.Message;
Jeff Brown05dc66a2011-03-02 14:41:58 -080062import android.os.MessageQueue;
Jeff Brownac143512012-04-05 18:57:33 -070063import android.os.Process;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070064import android.os.RemoteException;
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -070065import android.os.UserHandle;
Jeff Brown1a84fd12011-06-02 01:26:32 -070066import android.provider.Settings;
67import android.provider.Settings.SettingNotFoundException;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070068import android.util.Log;
Jeff Brown46b9ac02010-04-22 18:58:52 -070069import android.util.Slog;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070070import android.util.SparseArray;
Jeff Brown46b9ac02010-04-22 18:58:52 -070071import android.util.Xml;
Svetoslav Ganovc9c9a482012-07-16 08:46:07 -070072import android.view.IInputFilter;
73import android.view.IInputFilterHost;
Jeff Brown46b9ac02010-04-22 18:58:52 -070074import android.view.InputChannel;
Jeff Brown8d608662010-08-30 03:02:23 -070075import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -070076import android.view.InputEvent;
Jeff Brown1f245102010-11-18 20:53:46 -080077import android.view.KeyEvent;
Jeff Brown2352b972011-04-12 22:39:53 -070078import android.view.PointerIcon;
Jeff Browna4547672011-03-02 21:38:11 -080079import android.view.ViewConfiguration;
Jeff Brown0029c662011-03-30 02:25:18 -070080import android.view.WindowManagerPolicy;
Jeff Browncf39bdf2012-05-18 14:41:19 -070081import android.widget.Toast;
Jeff Brown46b9ac02010-04-22 18:58:52 -070082
Jeff Brown46b9ac02010-04-22 18:58:52 -070083import java.io.File;
Jeff Brown4532e612012-04-05 14:27:12 -070084import java.io.FileDescriptor;
Jeff Brown46b9ac02010-04-22 18:58:52 -070085import java.io.FileNotFoundException;
86import java.io.FileReader;
87import java.io.IOException;
Jeff Brown6ec6f792012-04-17 16:52:41 -070088import java.io.InputStreamReader;
Jeff Brown46b9ac02010-04-22 18:58:52 -070089import java.io.PrintWriter;
90import java.util.ArrayList;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070091import java.util.HashMap;
Jeff Browncf39bdf2012-05-18 14:41:19 -070092import java.util.HashSet;
Jeff Browna3bc5652012-04-17 11:42:25 -070093
Jeff Brown6ec6f792012-04-17 16:52:41 -070094import libcore.io.Streams;
Jeff Browna3bc5652012-04-17 11:42:25 -070095import libcore.util.Objects;
Jeff Brown46b9ac02010-04-22 18:58:52 -070096
97/*
98 * Wraps the C++ InputManager and provides its callbacks.
Jeff Brown46b9ac02010-04-22 18:58:52 -070099 */
Jeff Brownd728bf52012-09-08 18:05:28 -0700100public class InputManagerService extends IInputManager.Stub
Jeff Brown4ccb8232014-01-16 22:16:42 -0800101 implements Watchdog.Monitor {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700102 static final String TAG = "InputManager";
Jeff Brown1b9ba572012-05-21 10:54:18 -0700103 static final boolean DEBUG = false;
Jeff Brownb6997262010-10-08 22:31:17 -0700104
Jeff Brown4532e612012-04-05 14:27:12 -0700105 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
106
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700107 private static final int MSG_DELIVER_INPUT_DEVICES_CHANGED = 1;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700108 private static final int MSG_SWITCH_KEYBOARD_LAYOUT = 2;
109 private static final int MSG_RELOAD_KEYBOARD_LAYOUTS = 3;
110 private static final int MSG_UPDATE_KEYBOARD_LAYOUTS = 4;
111 private static final int MSG_RELOAD_DEVICE_ALIASES = 5;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700112
Jeff Brown4532e612012-04-05 14:27:12 -0700113 // Pointer to native input manager service object.
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000114 private final long mPtr;
Jeff Brown4532e612012-04-05 14:27:12 -0700115
Jeff Brown46b9ac02010-04-22 18:58:52 -0700116 private final Context mContext;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700117 private final InputManagerHandler mHandler;
Jeff Browna9d131c2012-09-20 16:48:17 -0700118
119 private WindowManagerCallbacks mWindowManagerCallbacks;
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700120 private WiredAccessoryCallbacks mWiredAccessoryCallbacks;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700121 private boolean mSystemReady;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700122 private NotificationManager mNotificationManager;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700123
Jeff Browna3bc5652012-04-17 11:42:25 -0700124 // Persistent data store. Must be locked each time during use.
125 private final PersistentDataStore mDataStore = new PersistentDataStore();
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700126
127 // List of currently registered input devices changed listeners by process id.
128 private Object mInputDevicesLock = new Object();
129 private boolean mInputDevicesChangedPending; // guarded by mInputDevicesLock
130 private InputDevice[] mInputDevices = new InputDevice[0];
131 private final SparseArray<InputDevicesChangedListenerRecord> mInputDevicesChangedListeners =
132 new SparseArray<InputDevicesChangedListenerRecord>(); // guarded by mInputDevicesLock
133 private final ArrayList<InputDevicesChangedListenerRecord>
134 mTempInputDevicesChangedListenersToNotify =
135 new ArrayList<InputDevicesChangedListenerRecord>(); // handler thread only
Jeff Browncf39bdf2012-05-18 14:41:19 -0700136 private final ArrayList<InputDevice>
137 mTempFullKeyboards = new ArrayList<InputDevice>(); // handler thread only
138 private boolean mKeyboardLayoutNotificationShown;
139 private PendingIntent mKeyboardLayoutIntent;
140 private Toast mSwitchedKeyboardLayoutToast;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700141
Jeff Browna47425a2012-04-13 04:09:27 -0700142 // State for vibrator tokens.
143 private Object mVibratorLock = new Object();
144 private HashMap<IBinder, VibratorToken> mVibratorTokens =
145 new HashMap<IBinder, VibratorToken>();
146 private int mNextVibratorTokenValue;
147
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700148 // State for the currently installed input filter.
149 final Object mInputFilterLock = new Object();
Svetoslav Ganovc9c9a482012-07-16 08:46:07 -0700150 IInputFilter mInputFilter; // guarded by mInputFilterLock
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700151 InputFilterHost mInputFilterHost; // guarded by mInputFilterLock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700152
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000153 private static native long nativeInit(InputManagerService service,
Jeff Brown4532e612012-04-05 14:27:12 -0700154 Context context, MessageQueue messageQueue);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000155 private static native void nativeStart(long ptr);
156 private static native void nativeSetDisplayViewport(long ptr, boolean external,
Jeff Brownd728bf52012-09-08 18:05:28 -0700157 int displayId, int rotation,
158 int logicalLeft, int logicalTop, int logicalRight, int logicalBottom,
Jeff Brown83d616a2012-09-09 20:33:43 -0700159 int physicalLeft, int physicalTop, int physicalRight, int physicalBottom,
160 int deviceWidth, int deviceHeight);
Jeff Brownd728bf52012-09-08 18:05:28 -0700161
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000162 private static native int nativeGetScanCodeState(long ptr,
Jeff Brown4532e612012-04-05 14:27:12 -0700163 int deviceId, int sourceMask, int scanCode);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000164 private static native int nativeGetKeyCodeState(long ptr,
Jeff Brown4532e612012-04-05 14:27:12 -0700165 int deviceId, int sourceMask, int keyCode);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000166 private static native int nativeGetSwitchState(long ptr,
Jeff Brown4532e612012-04-05 14:27:12 -0700167 int deviceId, int sourceMask, int sw);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000168 private static native boolean nativeHasKeys(long ptr,
Jeff Brown4532e612012-04-05 14:27:12 -0700169 int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000170 private static native void nativeRegisterInputChannel(long ptr, InputChannel inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800171 InputWindowHandle inputWindowHandle, boolean monitor);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000172 private static native void nativeUnregisterInputChannel(long ptr, InputChannel inputChannel);
173 private static native void nativeSetInputFilterEnabled(long ptr, boolean enable);
Jeff Brown38f96e52014-02-11 14:32:56 -0800174 private static native int nativeInjectInputEvent(long ptr, InputEvent event, int displayId,
Jeff Brown0029c662011-03-30 02:25:18 -0700175 int injectorPid, int injectorUid, int syncMode, int timeoutMillis,
176 int policyFlags);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000177 private static native void nativeSetInputWindows(long ptr, InputWindowHandle[] windowHandles);
178 private static native void nativeSetInputDispatchMode(long ptr, boolean enabled, boolean frozen);
179 private static native void nativeSetSystemUiVisibility(long ptr, int visibility);
180 private static native void nativeSetFocusedApplication(long ptr,
Jeff Brown4532e612012-04-05 14:27:12 -0700181 InputApplicationHandle application);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000182 private static native boolean nativeTransferTouchFocus(long ptr,
Jeff Brown4532e612012-04-05 14:27:12 -0700183 InputChannel fromChannel, InputChannel toChannel);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000184 private static native void nativeSetPointerSpeed(long ptr, int speed);
185 private static native void nativeSetShowTouches(long ptr, boolean enabled);
Jeff Brown037c33e2014-04-09 00:31:55 -0700186 private static native void nativeSetInteractive(long ptr, boolean interactive);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000187 private static native void nativeVibrate(long ptr, int deviceId, long[] pattern,
Jeff Browna47425a2012-04-13 04:09:27 -0700188 int repeat, int token);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +0000189 private static native void nativeCancelVibrate(long ptr, int deviceId, int token);
190 private static native void nativeReloadKeyboardLayouts(long ptr);
191 private static native void nativeReloadDeviceAliases(long ptr);
192 private static native String nativeDump(long ptr);
193 private static native void nativeMonitor(long ptr);
Jeff Brown4532e612012-04-05 14:27:12 -0700194
Jeff Brownac143512012-04-05 18:57:33 -0700195 // Input event injection constants defined in InputDispatcher.h.
196 private static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
197 private static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
198 private static final int INPUT_EVENT_INJECTION_FAILED = 2;
199 private static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
200
201 // Maximum number of milliseconds to wait for input event injection.
202 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
203
Jeff Brown6d0fec22010-07-23 21:28:06 -0700204 // Key states (may be returned by queries about the current state of a
205 // particular key code, scan code or switch).
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700206
Jeff Brown6d0fec22010-07-23 21:28:06 -0700207 /** The key state is unknown or the requested key itself is not supported. */
208 public static final int KEY_STATE_UNKNOWN = -1;
209
210 /** The key is up. /*/
211 public static final int KEY_STATE_UP = 0;
212
213 /** The key is down. */
214 public static final int KEY_STATE_DOWN = 1;
215
216 /** The key is down but is a virtual key press that is being emulated by the system. */
217 public static final int KEY_STATE_VIRTUAL = 2;
218
Jeff Brownc458ce92012-04-30 14:58:40 -0700219 /** Scan code: Mouse / trackball button. */
220 public static final int BTN_MOUSE = 0x110;
221
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700222 // Switch code values must match bionic/libc/kernel/common/linux/input.h
Jeff Brownc458ce92012-04-30 14:58:40 -0700223 /** Switch code: Lid switch. When set, lid is shut. */
224 public static final int SW_LID = 0x00;
225
226 /** Switch code: Keypad slide. When set, keyboard is exposed. */
227 public static final int SW_KEYPAD_SLIDE = 0x0a;
228
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700229 /** Switch code: Headphone. When set, headphone is inserted. */
230 public static final int SW_HEADPHONE_INSERT = 0x02;
231
232 /** Switch code: Microphone. When set, microphone is inserted. */
233 public static final int SW_MICROPHONE_INSERT = 0x04;
234
235 /** Switch code: Headphone/Microphone Jack. When set, something is inserted. */
236 public static final int SW_JACK_PHYSICAL_INSERT = 0x07;
237
238 public static final int SW_LID_BIT = 1 << SW_LID;
239 public static final int SW_KEYPAD_SLIDE_BIT = 1 << SW_KEYPAD_SLIDE;
240 public static final int SW_HEADPHONE_INSERT_BIT = 1 << SW_HEADPHONE_INSERT;
241 public static final int SW_MICROPHONE_INSERT_BIT = 1 << SW_MICROPHONE_INSERT;
242 public static final int SW_JACK_PHYSICAL_INSERT_BIT = 1 << SW_JACK_PHYSICAL_INSERT;
243 public static final int SW_JACK_BITS =
244 SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_JACK_PHYSICAL_INSERT_BIT;
245
246 /** Whether to use the dev/input/event or uevent subsystem for the audio jack. */
247 final boolean mUseDevInputEventForAudioJack;
248
Jeff Brown4ccb8232014-01-16 22:16:42 -0800249 public InputManagerService(Context context) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700250 this.mContext = context;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800251 this.mHandler = new InputManagerHandler(DisplayThread.get().getLooper());
Jeff Brown05dc66a2011-03-02 14:41:58 -0800252
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700253 mUseDevInputEventForAudioJack =
254 context.getResources().getBoolean(R.bool.config_useDevInputEventForAudioJack);
255 Slog.i(TAG, "Initializing input manager, mUseDevInputEventForAudioJack="
256 + mUseDevInputEventForAudioJack);
Jeff Brown4532e612012-04-05 14:27:12 -0700257 mPtr = nativeInit(this, mContext, mHandler.getLooper().getQueue());
Jeff Brown4ccb8232014-01-16 22:16:42 -0800258
259 LocalServices.addService(InputManagerInternal.class, new LocalService());
Jeff Brown46b9ac02010-04-22 18:58:52 -0700260 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700261
Jeff Browna9d131c2012-09-20 16:48:17 -0700262 public void setWindowManagerCallbacks(WindowManagerCallbacks callbacks) {
263 mWindowManagerCallbacks = callbacks;
264 }
265
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700266 public void setWiredAccessoryCallbacks(WiredAccessoryCallbacks callbacks) {
267 mWiredAccessoryCallbacks = callbacks;
268 }
269
Jeff Brown46b9ac02010-04-22 18:58:52 -0700270 public void start() {
271 Slog.i(TAG, "Starting input manager");
Jeff Brown4532e612012-04-05 14:27:12 -0700272 nativeStart(mPtr);
273
274 // Add ourself to the Watchdog monitors.
275 Watchdog.getInstance().addMonitor(this);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700276
277 registerPointerSpeedSettingObserver();
Jeff Browndaf4a122011-08-26 17:14:14 -0700278 registerShowTouchesSettingObserver();
279
Jeff Brownd4935962012-09-25 13:27:20 -0700280 mContext.registerReceiver(new BroadcastReceiver() {
281 @Override
282 public void onReceive(Context context, Intent intent) {
283 updatePointerSpeedFromSettings();
284 updateShowTouchesFromSettings();
285 }
286 }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
287
Jeff Brown1a84fd12011-06-02 01:26:32 -0700288 updatePointerSpeedFromSettings();
Jeff Browndaf4a122011-08-26 17:14:14 -0700289 updateShowTouchesFromSettings();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700290 }
Jeff Brown6ec6f792012-04-17 16:52:41 -0700291
Matthew Xie96313142012-06-29 16:57:31 -0700292 // TODO(BT) Pass in paramter for bluetooth system
Svetoslav Ganova0027152013-06-25 14:59:53 -0700293 public void systemRunning() {
Jeff Brown6ec6f792012-04-17 16:52:41 -0700294 if (DEBUG) {
295 Slog.d(TAG, "System ready.");
296 }
Jeff Browncf39bdf2012-05-18 14:41:19 -0700297 mNotificationManager = (NotificationManager)mContext.getSystemService(
298 Context.NOTIFICATION_SERVICE);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700299 mSystemReady = true;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700300
301 IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
302 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
303 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
Jeff Brown69b07162013-11-07 00:30:16 -0800304 filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700305 filter.addDataScheme("package");
306 mContext.registerReceiver(new BroadcastReceiver() {
307 @Override
308 public void onReceive(Context context, Intent intent) {
Jeff Browncf39bdf2012-05-18 14:41:19 -0700309 updateKeyboardLayouts();
Jeff Brown6ec6f792012-04-17 16:52:41 -0700310 }
311 }, filter, null, mHandler);
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700312
313 filter = new IntentFilter(BluetoothDevice.ACTION_ALIAS_CHANGED);
314 mContext.registerReceiver(new BroadcastReceiver() {
315 @Override
316 public void onReceive(Context context, Intent intent) {
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700317 reloadDeviceAliases();
318 }
319 }, filter, null, mHandler);
320
Jeff Browncf39bdf2012-05-18 14:41:19 -0700321 mHandler.sendEmptyMessage(MSG_RELOAD_DEVICE_ALIASES);
322 mHandler.sendEmptyMessage(MSG_UPDATE_KEYBOARD_LAYOUTS);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700323 }
324
325 private void reloadKeyboardLayouts() {
Jeff Browncf39bdf2012-05-18 14:41:19 -0700326 if (DEBUG) {
327 Slog.d(TAG, "Reloading keyboard layouts.");
328 }
Jeff Brown6ec6f792012-04-17 16:52:41 -0700329 nativeReloadKeyboardLayouts(mPtr);
330 }
331
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700332 private void reloadDeviceAliases() {
Jeff Browncf39bdf2012-05-18 14:41:19 -0700333 if (DEBUG) {
334 Slog.d(TAG, "Reloading device names.");
335 }
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700336 nativeReloadDeviceAliases(mPtr);
337 }
338
Jeff Brown4ccb8232014-01-16 22:16:42 -0800339 private void setDisplayViewportsInternal(DisplayViewport defaultViewport,
Jeff Brownd728bf52012-09-08 18:05:28 -0700340 DisplayViewport externalTouchViewport) {
341 if (defaultViewport.valid) {
342 setDisplayViewport(false, defaultViewport);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700343 }
Jeff Brownd728bf52012-09-08 18:05:28 -0700344
345 if (externalTouchViewport.valid) {
346 setDisplayViewport(true, externalTouchViewport);
347 } else if (defaultViewport.valid) {
348 setDisplayViewport(true, defaultViewport);
Jeff Brownb6997262010-10-08 22:31:17 -0700349 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700350 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700351
Jeff Brownd728bf52012-09-08 18:05:28 -0700352 private void setDisplayViewport(boolean external, DisplayViewport viewport) {
353 nativeSetDisplayViewport(mPtr, external,
354 viewport.displayId, viewport.orientation,
355 viewport.logicalFrame.left, viewport.logicalFrame.top,
356 viewport.logicalFrame.right, viewport.logicalFrame.bottom,
357 viewport.physicalFrame.left, viewport.physicalFrame.top,
Jeff Brown83d616a2012-09-09 20:33:43 -0700358 viewport.physicalFrame.right, viewport.physicalFrame.bottom,
359 viewport.deviceWidth, viewport.deviceHeight);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700360 }
Jeff Brownac143512012-04-05 18:57:33 -0700361
Jeff Brown6d0fec22010-07-23 21:28:06 -0700362 /**
363 * Gets the current state of a key or button by key code.
364 * @param deviceId The input device id, or -1 to consult all devices.
365 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
366 * consider all input sources. An input device is consulted if at least one of its
367 * non-class input source bits matches the specified source mask.
368 * @param keyCode The key code to check.
369 * @return The key state.
370 */
371 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
Jeff Brown4532e612012-04-05 14:27:12 -0700372 return nativeGetKeyCodeState(mPtr, deviceId, sourceMask, keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700373 }
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700374
Jeff Brown6d0fec22010-07-23 21:28:06 -0700375 /**
376 * Gets the current state of a key or button by scan code.
377 * @param deviceId The input device id, or -1 to consult all devices.
378 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
379 * consider all input sources. An input device is consulted if at least one of its
380 * non-class input source bits matches the specified source mask.
381 * @param scanCode The scan code to check.
382 * @return The key state.
383 */
384 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
Jeff Brown4532e612012-04-05 14:27:12 -0700385 return nativeGetScanCodeState(mPtr, deviceId, sourceMask, scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700386 }
RoboErikca9eef62013-12-16 11:27:55 -0800387
Jeff Brown6d0fec22010-07-23 21:28:06 -0700388 /**
389 * Gets the current state of a switch by switch code.
390 * @param deviceId The input device id, or -1 to consult all devices.
391 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
392 * consider all input sources. An input device is consulted if at least one of its
393 * non-class input source bits matches the specified source mask.
394 * @param switchCode The switch code to check.
395 * @return The switch state.
396 */
397 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
Jeff Brown4532e612012-04-05 14:27:12 -0700398 return nativeGetSwitchState(mPtr, deviceId, sourceMask, switchCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700399 }
400
Jeff Brown6d0fec22010-07-23 21:28:06 -0700401 /**
402 * Determines whether the specified key codes are supported by a particular device.
403 * @param deviceId The input device id, or -1 to consult all devices.
404 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
405 * consider all input sources. An input device is consulted if at least one of its
406 * non-class input source bits matches the specified source mask.
407 * @param keyCodes The array of key codes to check.
408 * @param keyExists An array at least as large as keyCodes whose entries will be set
409 * to true or false based on the presence or absence of support for the corresponding
410 * key codes.
411 * @return True if the lookup was successful, false otherwise.
412 */
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700413 @Override // Binder call
Jeff Brown6d0fec22010-07-23 21:28:06 -0700414 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700415 if (keyCodes == null) {
416 throw new IllegalArgumentException("keyCodes must not be null.");
417 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700418 if (keyExists == null || keyExists.length < keyCodes.length) {
419 throw new IllegalArgumentException("keyExists must not be null and must be at "
420 + "least as large as keyCodes.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700421 }
RoboErikca9eef62013-12-16 11:27:55 -0800422
Jeff Brown4532e612012-04-05 14:27:12 -0700423 return nativeHasKeys(mPtr, deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700424 }
RoboErikca9eef62013-12-16 11:27:55 -0800425
Jeff Browna41ca772010-08-11 14:46:32 -0700426 /**
427 * Creates an input channel that will receive all input from the input dispatcher.
428 * @param inputChannelName The input channel name.
429 * @return The input channel.
430 */
431 public InputChannel monitorInput(String inputChannelName) {
432 if (inputChannelName == null) {
433 throw new IllegalArgumentException("inputChannelName must not be null.");
434 }
RoboErikca9eef62013-12-16 11:27:55 -0800435
Jeff Browna41ca772010-08-11 14:46:32 -0700436 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
Jeff Brown4532e612012-04-05 14:27:12 -0700437 nativeRegisterInputChannel(mPtr, inputChannels[0], null, true);
Jeff Browna41ca772010-08-11 14:46:32 -0700438 inputChannels[0].dispose(); // don't need to retain the Java object reference
439 return inputChannels[1];
440 }
441
442 /**
443 * Registers an input channel so that it can be used as an input event target.
444 * @param inputChannel The input channel to register.
Jeff Brown928e0542011-01-10 11:17:36 -0800445 * @param inputWindowHandle The handle of the input window associated with the
446 * input channel, or null if none.
Jeff Browna41ca772010-08-11 14:46:32 -0700447 */
Jeff Brown928e0542011-01-10 11:17:36 -0800448 public void registerInputChannel(InputChannel inputChannel,
449 InputWindowHandle inputWindowHandle) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700450 if (inputChannel == null) {
451 throw new IllegalArgumentException("inputChannel must not be null.");
452 }
RoboErikca9eef62013-12-16 11:27:55 -0800453
Jeff Brown4532e612012-04-05 14:27:12 -0700454 nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, false);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700455 }
RoboErikca9eef62013-12-16 11:27:55 -0800456
Jeff Browna41ca772010-08-11 14:46:32 -0700457 /**
458 * Unregisters an input channel.
459 * @param inputChannel The input channel to unregister.
460 */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700461 public void unregisterInputChannel(InputChannel inputChannel) {
462 if (inputChannel == null) {
463 throw new IllegalArgumentException("inputChannel must not be null.");
464 }
RoboErikca9eef62013-12-16 11:27:55 -0800465
Jeff Brown4532e612012-04-05 14:27:12 -0700466 nativeUnregisterInputChannel(mPtr, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700467 }
Jeff Brown0029c662011-03-30 02:25:18 -0700468
469 /**
470 * Sets an input filter that will receive all input events before they are dispatched.
471 * The input filter may then reinterpret input events or inject new ones.
472 *
473 * To ensure consistency, the input dispatcher automatically drops all events
474 * in progress whenever an input filter is installed or uninstalled. After an input
475 * filter is uninstalled, it can no longer send input events unless it is reinstalled.
476 * Any events it attempts to send after it has been uninstalled will be dropped.
477 *
478 * @param filter The input filter, or null to remove the current filter.
479 */
Svetoslav Ganovc9c9a482012-07-16 08:46:07 -0700480 public void setInputFilter(IInputFilter filter) {
Jeff Brown0029c662011-03-30 02:25:18 -0700481 synchronized (mInputFilterLock) {
Svetoslav Ganovc9c9a482012-07-16 08:46:07 -0700482 final IInputFilter oldFilter = mInputFilter;
Jeff Brown0029c662011-03-30 02:25:18 -0700483 if (oldFilter == filter) {
484 return; // nothing to do
485 }
486
487 if (oldFilter != null) {
488 mInputFilter = null;
489 mInputFilterHost.disconnectLocked();
490 mInputFilterHost = null;
Svetoslav Ganovc9c9a482012-07-16 08:46:07 -0700491 try {
492 oldFilter.uninstall();
493 } catch (RemoteException re) {
494 /* ignore */
495 }
Jeff Brown0029c662011-03-30 02:25:18 -0700496 }
497
498 if (filter != null) {
499 mInputFilter = filter;
500 mInputFilterHost = new InputFilterHost();
Svetoslav Ganovc9c9a482012-07-16 08:46:07 -0700501 try {
502 filter.install(mInputFilterHost);
503 } catch (RemoteException re) {
504 /* ignore */
505 }
Jeff Brown0029c662011-03-30 02:25:18 -0700506 }
507
Jeff Brown4532e612012-04-05 14:27:12 -0700508 nativeSetInputFilterEnabled(mPtr, filter != null);
Jeff Brown0029c662011-03-30 02:25:18 -0700509 }
510 }
511
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700512 @Override // Binder call
Jeff Brownac143512012-04-05 18:57:33 -0700513 public boolean injectInputEvent(InputEvent event, int mode) {
Jeff Brown38f96e52014-02-11 14:32:56 -0800514 return injectInputEventInternal(event, Display.DEFAULT_DISPLAY, mode);
515 }
516
517 private boolean injectInputEventInternal(InputEvent event, int displayId, int mode) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700518 if (event == null) {
519 throw new IllegalArgumentException("event must not be null");
520 }
Jeff Brownac143512012-04-05 18:57:33 -0700521 if (mode != InputManager.INJECT_INPUT_EVENT_MODE_ASYNC
522 && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH
523 && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT) {
524 throw new IllegalArgumentException("mode is invalid");
Jeff Brown7fbdc842010-06-17 20:52:56 -0700525 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700526
Jeff Brownac143512012-04-05 18:57:33 -0700527 final int pid = Binder.getCallingPid();
528 final int uid = Binder.getCallingUid();
529 final long ident = Binder.clearCallingIdentity();
530 final int result;
531 try {
Jeff Brown38f96e52014-02-11 14:32:56 -0800532 result = nativeInjectInputEvent(mPtr, event, displayId, pid, uid, mode,
Jeff Brownac143512012-04-05 18:57:33 -0700533 INJECTION_TIMEOUT_MILLIS, WindowManagerPolicy.FLAG_DISABLE_KEY_REPEAT);
534 } finally {
535 Binder.restoreCallingIdentity(ident);
536 }
537 switch (result) {
538 case INPUT_EVENT_INJECTION_PERMISSION_DENIED:
539 Slog.w(TAG, "Input event injection from pid " + pid + " permission denied.");
540 throw new SecurityException(
541 "Injecting to another application requires INJECT_EVENTS permission");
542 case INPUT_EVENT_INJECTION_SUCCEEDED:
543 return true;
544 case INPUT_EVENT_INJECTION_TIMED_OUT:
545 Slog.w(TAG, "Input event injection from pid " + pid + " timed out.");
546 return false;
547 case INPUT_EVENT_INJECTION_FAILED:
548 default:
549 Slog.w(TAG, "Input event injection from pid " + pid + " failed.");
550 return false;
551 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700552 }
Jeff Brown0029c662011-03-30 02:25:18 -0700553
Jeff Brown8d608662010-08-30 03:02:23 -0700554 /**
555 * Gets information about the input device with the specified id.
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700556 * @param deviceId The device id.
Jeff Brown8d608662010-08-30 03:02:23 -0700557 * @return The input device or null if not found.
558 */
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700559 @Override // Binder call
Jeff Brown8d608662010-08-30 03:02:23 -0700560 public InputDevice getInputDevice(int deviceId) {
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700561 synchronized (mInputDevicesLock) {
562 final int count = mInputDevices.length;
563 for (int i = 0; i < count; i++) {
564 final InputDevice inputDevice = mInputDevices[i];
565 if (inputDevice.getId() == deviceId) {
566 return inputDevice;
567 }
568 }
569 }
570 return null;
Jeff Brown8d608662010-08-30 03:02:23 -0700571 }
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700572
Jeff Brown8d608662010-08-30 03:02:23 -0700573 /**
574 * Gets the ids of all input devices in the system.
575 * @return The input device ids.
576 */
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700577 @Override // Binder call
Jeff Brown8d608662010-08-30 03:02:23 -0700578 public int[] getInputDeviceIds() {
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700579 synchronized (mInputDevicesLock) {
580 final int count = mInputDevices.length;
581 int[] ids = new int[count];
582 for (int i = 0; i < count; i++) {
583 ids[i] = mInputDevices[i].getId();
584 }
585 return ids;
586 }
587 }
588
Jeff Browndaa37532012-05-01 15:54:03 -0700589 /**
590 * Gets all input devices in the system.
591 * @return The array of input devices.
592 */
593 public InputDevice[] getInputDevices() {
594 synchronized (mInputDevicesLock) {
595 return mInputDevices;
596 }
597 }
598
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700599 @Override // Binder call
600 public void registerInputDevicesChangedListener(IInputDevicesChangedListener listener) {
601 if (listener == null) {
602 throw new IllegalArgumentException("listener must not be null");
603 }
604
605 synchronized (mInputDevicesLock) {
606 int callingPid = Binder.getCallingPid();
607 if (mInputDevicesChangedListeners.get(callingPid) != null) {
608 throw new SecurityException("The calling process has already "
609 + "registered an InputDevicesChangedListener.");
610 }
611
612 InputDevicesChangedListenerRecord record =
613 new InputDevicesChangedListenerRecord(callingPid, listener);
614 try {
615 IBinder binder = listener.asBinder();
616 binder.linkToDeath(record, 0);
617 } catch (RemoteException ex) {
618 // give up
619 throw new RuntimeException(ex);
620 }
621
622 mInputDevicesChangedListeners.put(callingPid, record);
623 }
624 }
625
626 private void onInputDevicesChangedListenerDied(int pid) {
627 synchronized (mInputDevicesLock) {
628 mInputDevicesChangedListeners.remove(pid);
629 }
630 }
631
632 // Must be called on handler.
Jeff Browncf39bdf2012-05-18 14:41:19 -0700633 private void deliverInputDevicesChanged(InputDevice[] oldInputDevices) {
634 // Scan for changes.
635 int numFullKeyboardsAdded = 0;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700636 mTempInputDevicesChangedListenersToNotify.clear();
Jeff Browncf39bdf2012-05-18 14:41:19 -0700637 mTempFullKeyboards.clear();
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700638 final int numListeners;
639 final int[] deviceIdAndGeneration;
640 synchronized (mInputDevicesLock) {
641 if (!mInputDevicesChangedPending) {
642 return;
643 }
644 mInputDevicesChangedPending = false;
645
646 numListeners = mInputDevicesChangedListeners.size();
647 for (int i = 0; i < numListeners; i++) {
648 mTempInputDevicesChangedListenersToNotify.add(
649 mInputDevicesChangedListeners.valueAt(i));
650 }
651
652 final int numDevices = mInputDevices.length;
653 deviceIdAndGeneration = new int[numDevices * 2];
654 for (int i = 0; i < numDevices; i++) {
655 final InputDevice inputDevice = mInputDevices[i];
656 deviceIdAndGeneration[i * 2] = inputDevice.getId();
657 deviceIdAndGeneration[i * 2 + 1] = inputDevice.getGeneration();
Jeff Browncf39bdf2012-05-18 14:41:19 -0700658
Jeff Brown7e4ff4b2012-05-30 14:32:16 -0700659 if (!inputDevice.isVirtual() && inputDevice.isFullKeyboard()) {
Jeff Browncf39bdf2012-05-18 14:41:19 -0700660 if (!containsInputDeviceWithDescriptor(oldInputDevices,
661 inputDevice.getDescriptor())) {
662 mTempFullKeyboards.add(numFullKeyboardsAdded++, inputDevice);
663 } else {
664 mTempFullKeyboards.add(inputDevice);
665 }
666 }
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700667 }
668 }
669
Jeff Browncf39bdf2012-05-18 14:41:19 -0700670 // Notify listeners.
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700671 for (int i = 0; i < numListeners; i++) {
672 mTempInputDevicesChangedListenersToNotify.get(i).notifyInputDevicesChanged(
673 deviceIdAndGeneration);
674 }
Jeff Browncf39bdf2012-05-18 14:41:19 -0700675 mTempInputDevicesChangedListenersToNotify.clear();
676
677 // Check for missing keyboard layouts.
678 if (mNotificationManager != null) {
679 final int numFullKeyboards = mTempFullKeyboards.size();
680 boolean missingLayoutForExternalKeyboard = false;
681 boolean missingLayoutForExternalKeyboardAdded = false;
682 synchronized (mDataStore) {
683 for (int i = 0; i < numFullKeyboards; i++) {
684 final InputDevice inputDevice = mTempFullKeyboards.get(i);
685 if (mDataStore.getCurrentKeyboardLayout(inputDevice.getDescriptor()) == null) {
686 missingLayoutForExternalKeyboard = true;
687 if (i < numFullKeyboardsAdded) {
688 missingLayoutForExternalKeyboardAdded = true;
689 }
690 }
691 }
692 }
693 if (missingLayoutForExternalKeyboard) {
694 if (missingLayoutForExternalKeyboardAdded) {
695 showMissingKeyboardLayoutNotification();
696 }
697 } else if (mKeyboardLayoutNotificationShown) {
698 hideMissingKeyboardLayoutNotification();
699 }
700 }
701 mTempFullKeyboards.clear();
702 }
703
704 // Must be called on handler.
705 private void showMissingKeyboardLayoutNotification() {
706 if (!mKeyboardLayoutNotificationShown) {
707 if (mKeyboardLayoutIntent == null) {
708 final Intent intent = new Intent("android.settings.INPUT_METHOD_SETTINGS");
709 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
710 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
711 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -0700712 mKeyboardLayoutIntent = PendingIntent.getActivityAsUser(mContext, 0,
713 intent, 0, null, UserHandle.CURRENT);
Jeff Browncf39bdf2012-05-18 14:41:19 -0700714 }
715
716 Resources r = mContext.getResources();
717 Notification notification = new Notification.Builder(mContext)
718 .setContentTitle(r.getString(
719 R.string.select_keyboard_layout_notification_title))
720 .setContentText(r.getString(
721 R.string.select_keyboard_layout_notification_message))
722 .setContentIntent(mKeyboardLayoutIntent)
723 .setSmallIcon(R.drawable.ic_settings_language)
724 .setPriority(Notification.PRIORITY_LOW)
725 .build();
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -0700726 mNotificationManager.notifyAsUser(null,
727 R.string.select_keyboard_layout_notification_title,
728 notification, UserHandle.ALL);
Jeff Browncf39bdf2012-05-18 14:41:19 -0700729 mKeyboardLayoutNotificationShown = true;
730 }
731 }
732
733 // Must be called on handler.
734 private void hideMissingKeyboardLayoutNotification() {
735 if (mKeyboardLayoutNotificationShown) {
736 mKeyboardLayoutNotificationShown = false;
Dianne Hackborn50cdf7c32012-09-23 17:08:57 -0700737 mNotificationManager.cancelAsUser(null,
738 R.string.select_keyboard_layout_notification_title,
739 UserHandle.ALL);
Jeff Browncf39bdf2012-05-18 14:41:19 -0700740 }
741 }
742
743 // Must be called on handler.
744 private void updateKeyboardLayouts() {
745 // Scan all input devices state for keyboard layouts that have been uninstalled.
746 final HashSet<String> availableKeyboardLayouts = new HashSet<String>();
747 visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
748 @Override
749 public void visitKeyboardLayout(Resources resources,
750 String descriptor, String label, String collection, int keyboardLayoutResId) {
751 availableKeyboardLayouts.add(descriptor);
752 }
753 });
754 synchronized (mDataStore) {
755 try {
756 mDataStore.removeUninstalledKeyboardLayouts(availableKeyboardLayouts);
757 } finally {
758 mDataStore.saveIfNeeded();
759 }
760 }
761
762 // Reload keyboard layouts.
763 reloadKeyboardLayouts();
764 }
765
Jeff Browncf39bdf2012-05-18 14:41:19 -0700766 private static boolean containsInputDeviceWithDescriptor(InputDevice[] inputDevices,
767 String descriptor) {
768 final int numDevices = inputDevices.length;
769 for (int i = 0; i < numDevices; i++) {
770 final InputDevice inputDevice = inputDevices[i];
771 if (inputDevice.getDescriptor().equals(descriptor)) {
772 return true;
773 }
774 }
775 return false;
Jeff Brown8d608662010-08-30 03:02:23 -0700776 }
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700777
778 @Override // Binder call
779 public KeyboardLayout[] getKeyboardLayouts() {
Jeff Brown6ec6f792012-04-17 16:52:41 -0700780 final ArrayList<KeyboardLayout> list = new ArrayList<KeyboardLayout>();
781 visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
782 @Override
783 public void visitKeyboardLayout(Resources resources,
Jeff Brownd9fec5d2012-05-17 16:01:54 -0700784 String descriptor, String label, String collection, int keyboardLayoutResId) {
785 list.add(new KeyboardLayout(descriptor, label, collection));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700786 }
787 });
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700788 return list.toArray(new KeyboardLayout[list.size()]);
789 }
790
791 @Override // Binder call
792 public KeyboardLayout getKeyboardLayout(String keyboardLayoutDescriptor) {
793 if (keyboardLayoutDescriptor == null) {
794 throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
795 }
796
Jeff Brown6ec6f792012-04-17 16:52:41 -0700797 final KeyboardLayout[] result = new KeyboardLayout[1];
798 visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
799 @Override
800 public void visitKeyboardLayout(Resources resources,
Jeff Brownd9fec5d2012-05-17 16:01:54 -0700801 String descriptor, String label, String collection, int keyboardLayoutResId) {
802 result[0] = new KeyboardLayout(descriptor, label, collection);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700803 }
804 });
805 if (result[0] == null) {
806 Log.w(TAG, "Could not get keyboard layout with descriptor '"
807 + keyboardLayoutDescriptor + "'.");
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700808 }
Jeff Brown6ec6f792012-04-17 16:52:41 -0700809 return result[0];
810 }
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700811
Jeff Brown6ec6f792012-04-17 16:52:41 -0700812 private void visitAllKeyboardLayouts(KeyboardLayoutVisitor visitor) {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700813 final PackageManager pm = mContext.getPackageManager();
Jeff Brown6ec6f792012-04-17 16:52:41 -0700814 Intent intent = new Intent(InputManager.ACTION_QUERY_KEYBOARD_LAYOUTS);
815 for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent,
816 PackageManager.GET_META_DATA)) {
817 visitKeyboardLayoutsInPackage(pm, resolveInfo.activityInfo, null, visitor);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700818 }
819 }
820
Jeff Brown6ec6f792012-04-17 16:52:41 -0700821 private void visitKeyboardLayout(String keyboardLayoutDescriptor,
822 KeyboardLayoutVisitor visitor) {
823 KeyboardLayoutDescriptor d = KeyboardLayoutDescriptor.parse(keyboardLayoutDescriptor);
824 if (d != null) {
825 final PackageManager pm = mContext.getPackageManager();
826 try {
827 ActivityInfo receiver = pm.getReceiverInfo(
828 new ComponentName(d.packageName, d.receiverName),
829 PackageManager.GET_META_DATA);
830 visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, visitor);
831 } catch (NameNotFoundException ex) {
832 }
833 }
834 }
835
836 private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver,
837 String keyboardName, KeyboardLayoutVisitor visitor) {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700838 Bundle metaData = receiver.metaData;
839 if (metaData == null) {
Jeff Brown6ec6f792012-04-17 16:52:41 -0700840 return;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700841 }
842
843 int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS);
844 if (configResId == 0) {
845 Log.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS
846 + "' on receiver " + receiver.packageName + "/" + receiver.name);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700847 return;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700848 }
849
Jeff Brownd9fec5d2012-05-17 16:01:54 -0700850 CharSequence receiverLabel = receiver.loadLabel(pm);
851 String collection = receiverLabel != null ? receiverLabel.toString() : "";
852
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700853 try {
854 Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
855 XmlResourceParser parser = resources.getXml(configResId);
856 try {
857 XmlUtils.beginDocument(parser, "keyboard-layouts");
858
859 for (;;) {
860 XmlUtils.nextElement(parser);
861 String element = parser.getName();
862 if (element == null) {
863 break;
864 }
865 if (element.equals("keyboard-layout")) {
866 TypedArray a = resources.obtainAttributes(
867 parser, com.android.internal.R.styleable.KeyboardLayout);
868 try {
869 String name = a.getString(
870 com.android.internal.R.styleable.KeyboardLayout_name);
871 String label = a.getString(
872 com.android.internal.R.styleable.KeyboardLayout_label);
Jeff Brown2f095762012-05-10 21:29:33 -0700873 int keyboardLayoutResId = a.getResourceId(
874 com.android.internal.R.styleable.KeyboardLayout_keyboardLayout,
875 0);
876 if (name == null || label == null || keyboardLayoutResId == 0) {
877 Log.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' "
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700878 + "attributes in keyboard layout "
879 + "resource from receiver "
880 + receiver.packageName + "/" + receiver.name);
881 } else {
882 String descriptor = KeyboardLayoutDescriptor.format(
883 receiver.packageName, receiver.name, name);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700884 if (keyboardName == null || name.equals(keyboardName)) {
885 visitor.visitKeyboardLayout(resources, descriptor,
Jeff Brownd9fec5d2012-05-17 16:01:54 -0700886 label, collection, keyboardLayoutResId);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700887 }
888 }
889 } finally {
890 a.recycle();
891 }
892 } else {
893 Log.w(TAG, "Skipping unrecognized element '" + element
894 + "' in keyboard layout resource from receiver "
895 + receiver.packageName + "/" + receiver.name);
896 }
897 }
898 } finally {
899 parser.close();
900 }
901 } catch (Exception ex) {
Jeff Brown6ec6f792012-04-17 16:52:41 -0700902 Log.w(TAG, "Could not parse keyboard layout resource from receiver "
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700903 + receiver.packageName + "/" + receiver.name, ex);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700904 }
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700905 }
906
RoboErikca9eef62013-12-16 11:27:55 -0800907 /**
908 * Builds a layout descriptor for the vendor/product. This returns the
909 * descriptor for ids that aren't useful (such as the default 0, 0).
910 */
911 private String getLayoutDescriptor(InputDeviceIdentifier identifier) {
912 if (identifier == null || identifier.getDescriptor() == null) {
913 throw new IllegalArgumentException("identifier and descriptor must not be null");
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700914 }
915
RoboErikca9eef62013-12-16 11:27:55 -0800916 if (identifier.getVendorId() == 0 && identifier.getProductId() == 0) {
917 return identifier.getDescriptor();
918 }
919 StringBuilder bob = new StringBuilder();
920 bob.append("vendor:").append(identifier.getVendorId());
921 bob.append(",product:").append(identifier.getProductId());
922 return bob.toString();
923 }
924
925 @Override // Binder call
926 public String getCurrentKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier) {
927
928 String key = getLayoutDescriptor(identifier);
Jeff Browna3bc5652012-04-17 11:42:25 -0700929 synchronized (mDataStore) {
RoboErikca9eef62013-12-16 11:27:55 -0800930 String layout = null;
931 // try loading it using the layout descriptor if we have it
932 layout = mDataStore.getCurrentKeyboardLayout(key);
933 if (layout == null && !key.equals(identifier.getDescriptor())) {
934 // if it doesn't exist fall back to the device descriptor
935 layout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor());
936 }
937 if (DEBUG) {
938 Slog.d(TAG, "Loaded keyboard layout id for " + key + " and got "
939 + layout);
940 }
941 return layout;
Jeff Browna3bc5652012-04-17 11:42:25 -0700942 }
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700943 }
944
945 @Override // Binder call
RoboErikca9eef62013-12-16 11:27:55 -0800946 public void setCurrentKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700947 String keyboardLayoutDescriptor) {
948 if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
Jeff Browncf39bdf2012-05-18 14:41:19 -0700949 "setCurrentKeyboardLayoutForInputDevice()")) {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700950 throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
951 }
Jeff Browncf39bdf2012-05-18 14:41:19 -0700952 if (keyboardLayoutDescriptor == null) {
953 throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
954 }
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700955
RoboErikca9eef62013-12-16 11:27:55 -0800956 String key = getLayoutDescriptor(identifier);
Jeff Browna3bc5652012-04-17 11:42:25 -0700957 synchronized (mDataStore) {
958 try {
RoboErikca9eef62013-12-16 11:27:55 -0800959 if (mDataStore.setCurrentKeyboardLayout(key, keyboardLayoutDescriptor)) {
960 if (DEBUG) {
961 Slog.d(TAG, "Saved keyboard layout using " + key);
962 }
Jeff Browncf39bdf2012-05-18 14:41:19 -0700963 mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
964 }
Jeff Browna3bc5652012-04-17 11:42:25 -0700965 } finally {
966 mDataStore.saveIfNeeded();
967 }
968 }
Jeff Browncf39bdf2012-05-18 14:41:19 -0700969 }
Jeff Brown6ec6f792012-04-17 16:52:41 -0700970
Jeff Browncf39bdf2012-05-18 14:41:19 -0700971 @Override // Binder call
RoboErikca9eef62013-12-16 11:27:55 -0800972 public String[] getKeyboardLayoutsForInputDevice(InputDeviceIdentifier identifier) {
973 String key = getLayoutDescriptor(identifier);
Jeff Browncf39bdf2012-05-18 14:41:19 -0700974 synchronized (mDataStore) {
RoboErikca9eef62013-12-16 11:27:55 -0800975 String[] layouts = mDataStore.getKeyboardLayouts(key);
976 if ((layouts == null || layouts.length == 0)
977 && !key.equals(identifier.getDescriptor())) {
978 layouts = mDataStore.getKeyboardLayouts(identifier.getDescriptor());
979 }
980 return layouts;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700981 }
982 }
983
984 @Override // Binder call
RoboErikca9eef62013-12-16 11:27:55 -0800985 public void addKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
Jeff Browncf39bdf2012-05-18 14:41:19 -0700986 String keyboardLayoutDescriptor) {
987 if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
988 "addKeyboardLayoutForInputDevice()")) {
989 throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
990 }
Jeff Browncf39bdf2012-05-18 14:41:19 -0700991 if (keyboardLayoutDescriptor == null) {
992 throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
993 }
994
RoboErikca9eef62013-12-16 11:27:55 -0800995 String key = getLayoutDescriptor(identifier);
Jeff Browncf39bdf2012-05-18 14:41:19 -0700996 synchronized (mDataStore) {
997 try {
RoboErikca9eef62013-12-16 11:27:55 -0800998 String oldLayout = mDataStore.getCurrentKeyboardLayout(key);
999 if (oldLayout == null && !key.equals(identifier.getDescriptor())) {
1000 oldLayout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor());
1001 }
1002 if (mDataStore.addKeyboardLayout(key, keyboardLayoutDescriptor)
Jeff Browncf39bdf2012-05-18 14:41:19 -07001003 && !Objects.equal(oldLayout,
RoboErikca9eef62013-12-16 11:27:55 -08001004 mDataStore.getCurrentKeyboardLayout(key))) {
Jeff Browncf39bdf2012-05-18 14:41:19 -07001005 mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
1006 }
1007 } finally {
1008 mDataStore.saveIfNeeded();
Jeff Brown6ec6f792012-04-17 16:52:41 -07001009 }
Jeff Browncf39bdf2012-05-18 14:41:19 -07001010 }
1011 }
1012
1013 @Override // Binder call
RoboErikca9eef62013-12-16 11:27:55 -08001014 public void removeKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
Jeff Browncf39bdf2012-05-18 14:41:19 -07001015 String keyboardLayoutDescriptor) {
1016 if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
1017 "removeKeyboardLayoutForInputDevice()")) {
1018 throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
1019 }
Jeff Browncf39bdf2012-05-18 14:41:19 -07001020 if (keyboardLayoutDescriptor == null) {
1021 throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
1022 }
1023
RoboErikca9eef62013-12-16 11:27:55 -08001024 String key = getLayoutDescriptor(identifier);
Jeff Browncf39bdf2012-05-18 14:41:19 -07001025 synchronized (mDataStore) {
1026 try {
RoboErikca9eef62013-12-16 11:27:55 -08001027 String oldLayout = mDataStore.getCurrentKeyboardLayout(key);
1028 if (oldLayout == null && !key.equals(identifier.getDescriptor())) {
1029 oldLayout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor());
1030 }
1031 boolean removed = mDataStore.removeKeyboardLayout(key, keyboardLayoutDescriptor);
1032 if (!key.equals(identifier.getDescriptor())) {
1033 // We need to remove from both places to ensure it is gone
1034 removed |= mDataStore.removeKeyboardLayout(identifier.getDescriptor(),
1035 keyboardLayoutDescriptor);
1036 }
1037 if (removed && !Objects.equal(oldLayout,
1038 mDataStore.getCurrentKeyboardLayout(key))) {
Jeff Browncf39bdf2012-05-18 14:41:19 -07001039 mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
1040 }
1041 } finally {
1042 mDataStore.saveIfNeeded();
1043 }
1044 }
1045 }
1046
1047 public void switchKeyboardLayout(int deviceId, int direction) {
1048 mHandler.obtainMessage(MSG_SWITCH_KEYBOARD_LAYOUT, deviceId, direction).sendToTarget();
1049 }
1050
1051 // Must be called on handler.
1052 private void handleSwitchKeyboardLayout(int deviceId, int direction) {
1053 final InputDevice device = getInputDevice(deviceId);
Jeff Browncf39bdf2012-05-18 14:41:19 -07001054 if (device != null) {
1055 final boolean changed;
1056 final String keyboardLayoutDescriptor;
RoboErikca9eef62013-12-16 11:27:55 -08001057
1058 String key = getLayoutDescriptor(device.getIdentifier());
Jeff Browncf39bdf2012-05-18 14:41:19 -07001059 synchronized (mDataStore) {
1060 try {
RoboErikca9eef62013-12-16 11:27:55 -08001061 changed = mDataStore.switchKeyboardLayout(key, direction);
Jeff Browncf39bdf2012-05-18 14:41:19 -07001062 keyboardLayoutDescriptor = mDataStore.getCurrentKeyboardLayout(
RoboErikca9eef62013-12-16 11:27:55 -08001063 key);
Jeff Browncf39bdf2012-05-18 14:41:19 -07001064 } finally {
1065 mDataStore.saveIfNeeded();
1066 }
1067 }
1068
1069 if (changed) {
1070 if (mSwitchedKeyboardLayoutToast != null) {
1071 mSwitchedKeyboardLayoutToast.cancel();
1072 mSwitchedKeyboardLayoutToast = null;
1073 }
1074 if (keyboardLayoutDescriptor != null) {
1075 KeyboardLayout keyboardLayout = getKeyboardLayout(keyboardLayoutDescriptor);
1076 if (keyboardLayout != null) {
1077 mSwitchedKeyboardLayoutToast = Toast.makeText(
1078 mContext, keyboardLayout.getLabel(), Toast.LENGTH_SHORT);
1079 mSwitchedKeyboardLayoutToast.show();
1080 }
1081 }
1082
1083 reloadKeyboardLayouts();
1084 }
Jeff Brown6ec6f792012-04-17 16:52:41 -07001085 }
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001086 }
1087
Jeff Brown9302c872011-07-13 22:51:29 -07001088 public void setInputWindows(InputWindowHandle[] windowHandles) {
Jeff Brown4532e612012-04-05 14:27:12 -07001089 nativeSetInputWindows(mPtr, windowHandles);
Jeff Brown349703e2010-06-22 01:27:15 -07001090 }
RoboErikca9eef62013-12-16 11:27:55 -08001091
Jeff Brown9302c872011-07-13 22:51:29 -07001092 public void setFocusedApplication(InputApplicationHandle application) {
Jeff Brown4532e612012-04-05 14:27:12 -07001093 nativeSetFocusedApplication(mPtr, application);
Jeff Brown349703e2010-06-22 01:27:15 -07001094 }
RoboErikca9eef62013-12-16 11:27:55 -08001095
Jeff Brown349703e2010-06-22 01:27:15 -07001096 public void setInputDispatchMode(boolean enabled, boolean frozen) {
Jeff Brown4532e612012-04-05 14:27:12 -07001097 nativeSetInputDispatchMode(mPtr, enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001098 }
Jeff Brown05dc66a2011-03-02 14:41:58 -08001099
1100 public void setSystemUiVisibility(int visibility) {
Jeff Brown4532e612012-04-05 14:27:12 -07001101 nativeSetSystemUiVisibility(mPtr, visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001102 }
1103
Jeff Browne6504122010-09-27 14:52:15 -07001104 /**
1105 * Atomically transfers touch focus from one window to another as identified by
1106 * their input channels. It is possible for multiple windows to have
1107 * touch focus if they support split touch dispatch
1108 * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
1109 * method only transfers touch focus of the specified window without affecting
1110 * other windows that may also have touch focus at the same time.
1111 * @param fromChannel The channel of a window that currently has touch focus.
1112 * @param toChannel The channel of the window that should receive touch focus in
1113 * place of the first.
1114 * @return True if the transfer was successful. False if the window with the
1115 * specified channel did not actually have touch focus at the time of the request.
1116 */
1117 public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) {
1118 if (fromChannel == null) {
1119 throw new IllegalArgumentException("fromChannel must not be null.");
1120 }
1121 if (toChannel == null) {
1122 throw new IllegalArgumentException("toChannel must not be null.");
1123 }
Jeff Brown4532e612012-04-05 14:27:12 -07001124 return nativeTransferTouchFocus(mPtr, fromChannel, toChannel);
Jeff Browne6504122010-09-27 14:52:15 -07001125 }
Jeff Brown05dc66a2011-03-02 14:41:58 -08001126
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001127 @Override // Binder call
Jeff Brownac143512012-04-05 18:57:33 -07001128 public void tryPointerSpeed(int speed) {
1129 if (!checkCallingPermission(android.Manifest.permission.SET_POINTER_SPEED,
1130 "tryPointerSpeed()")) {
1131 throw new SecurityException("Requires SET_POINTER_SPEED permission");
1132 }
1133
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001134 if (speed < InputManager.MIN_POINTER_SPEED || speed > InputManager.MAX_POINTER_SPEED) {
1135 throw new IllegalArgumentException("speed out of range");
1136 }
1137
Jeff Brownac143512012-04-05 18:57:33 -07001138 setPointerSpeedUnchecked(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001139 }
1140
1141 public void updatePointerSpeedFromSettings() {
Jeff Brownac143512012-04-05 18:57:33 -07001142 int speed = getPointerSpeedSetting();
1143 setPointerSpeedUnchecked(speed);
1144 }
1145
1146 private void setPointerSpeedUnchecked(int speed) {
1147 speed = Math.min(Math.max(speed, InputManager.MIN_POINTER_SPEED),
1148 InputManager.MAX_POINTER_SPEED);
1149 nativeSetPointerSpeed(mPtr, speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001150 }
1151
1152 private void registerPointerSpeedSettingObserver() {
1153 mContext.getContentResolver().registerContentObserver(
1154 Settings.System.getUriFor(Settings.System.POINTER_SPEED), true,
Jeff Brown4532e612012-04-05 14:27:12 -07001155 new ContentObserver(mHandler) {
Jeff Brown1a84fd12011-06-02 01:26:32 -07001156 @Override
1157 public void onChange(boolean selfChange) {
1158 updatePointerSpeedFromSettings();
1159 }
Jeff Brownd4935962012-09-25 13:27:20 -07001160 }, UserHandle.USER_ALL);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001161 }
1162
Jeff Brownac143512012-04-05 18:57:33 -07001163 private int getPointerSpeedSetting() {
1164 int speed = InputManager.DEFAULT_POINTER_SPEED;
Jeff Brown1a84fd12011-06-02 01:26:32 -07001165 try {
Jeff Brownd4935962012-09-25 13:27:20 -07001166 speed = Settings.System.getIntForUser(mContext.getContentResolver(),
1167 Settings.System.POINTER_SPEED, UserHandle.USER_CURRENT);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001168 } catch (SettingNotFoundException snfe) {
1169 }
1170 return speed;
1171 }
1172
Jeff Browndaf4a122011-08-26 17:14:14 -07001173 public void updateShowTouchesFromSettings() {
1174 int setting = getShowTouchesSetting(0);
Jeff Brown4532e612012-04-05 14:27:12 -07001175 nativeSetShowTouches(mPtr, setting != 0);
Jeff Browndaf4a122011-08-26 17:14:14 -07001176 }
1177
1178 private void registerShowTouchesSettingObserver() {
1179 mContext.getContentResolver().registerContentObserver(
1180 Settings.System.getUriFor(Settings.System.SHOW_TOUCHES), true,
Jeff Brown4532e612012-04-05 14:27:12 -07001181 new ContentObserver(mHandler) {
Jeff Browndaf4a122011-08-26 17:14:14 -07001182 @Override
1183 public void onChange(boolean selfChange) {
1184 updateShowTouchesFromSettings();
1185 }
Jeff Brownd4935962012-09-25 13:27:20 -07001186 }, UserHandle.USER_ALL);
Jeff Browndaf4a122011-08-26 17:14:14 -07001187 }
1188
1189 private int getShowTouchesSetting(int defaultValue) {
1190 int result = defaultValue;
1191 try {
Jeff Brownd4935962012-09-25 13:27:20 -07001192 result = Settings.System.getIntForUser(mContext.getContentResolver(),
1193 Settings.System.SHOW_TOUCHES, UserHandle.USER_CURRENT);
Jeff Browndaf4a122011-08-26 17:14:14 -07001194 } catch (SettingNotFoundException snfe) {
1195 }
1196 return result;
1197 }
1198
Jeff Browna47425a2012-04-13 04:09:27 -07001199 // Binder call
1200 @Override
1201 public void vibrate(int deviceId, long[] pattern, int repeat, IBinder token) {
1202 if (repeat >= pattern.length) {
1203 throw new ArrayIndexOutOfBoundsException();
1204 }
1205
1206 VibratorToken v;
1207 synchronized (mVibratorLock) {
1208 v = mVibratorTokens.get(token);
1209 if (v == null) {
1210 v = new VibratorToken(deviceId, token, mNextVibratorTokenValue++);
1211 try {
1212 token.linkToDeath(v, 0);
1213 } catch (RemoteException ex) {
1214 // give up
1215 throw new RuntimeException(ex);
1216 }
1217 mVibratorTokens.put(token, v);
1218 }
1219 }
1220
1221 synchronized (v) {
1222 v.mVibrating = true;
1223 nativeVibrate(mPtr, deviceId, pattern, repeat, v.mTokenValue);
1224 }
1225 }
1226
1227 // Binder call
1228 @Override
1229 public void cancelVibrate(int deviceId, IBinder token) {
1230 VibratorToken v;
1231 synchronized (mVibratorLock) {
1232 v = mVibratorTokens.get(token);
1233 if (v == null || v.mDeviceId != deviceId) {
1234 return; // nothing to cancel
1235 }
1236 }
1237
1238 cancelVibrateIfNeeded(v);
1239 }
1240
1241 void onVibratorTokenDied(VibratorToken v) {
1242 synchronized (mVibratorLock) {
1243 mVibratorTokens.remove(v.mToken);
1244 }
1245
1246 cancelVibrateIfNeeded(v);
1247 }
1248
1249 private void cancelVibrateIfNeeded(VibratorToken v) {
1250 synchronized (v) {
1251 if (v.mVibrating) {
1252 nativeCancelVibrate(mPtr, v.mDeviceId, v.mTokenValue);
1253 v.mVibrating = false;
1254 }
1255 }
1256 }
1257
Jeff Brown4532e612012-04-05 14:27:12 -07001258 @Override
1259 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Jeff Browna3bc5652012-04-17 11:42:25 -07001260 if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
Jeff Brown4532e612012-04-05 14:27:12 -07001261 != PackageManager.PERMISSION_GRANTED) {
1262 pw.println("Permission Denial: can't dump InputManager from from pid="
1263 + Binder.getCallingPid()
1264 + ", uid=" + Binder.getCallingUid());
1265 return;
1266 }
1267
1268 pw.println("INPUT MANAGER (dumpsys input)\n");
1269 String dumpStr = nativeDump(mPtr);
Jeff Browne33348b2010-07-15 23:54:05 -07001270 if (dumpStr != null) {
1271 pw.println(dumpStr);
1272 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001273 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001274
Jeff Brownac143512012-04-05 18:57:33 -07001275 private boolean checkCallingPermission(String permission, String func) {
1276 // Quick check: if the calling permission is me, it's all okay.
1277 if (Binder.getCallingPid() == Process.myPid()) {
1278 return true;
1279 }
1280
1281 if (mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED) {
1282 return true;
1283 }
1284 String msg = "Permission Denial: " + func + " from pid="
1285 + Binder.getCallingPid()
1286 + ", uid=" + Binder.getCallingUid()
1287 + " requires " + permission;
1288 Slog.w(TAG, msg);
1289 return false;
1290 }
1291
Jeff Brown4532e612012-04-05 14:27:12 -07001292 // Called by the heartbeat to ensure locks are not held indefinitely (for deadlock detection).
Craig Mautner2f39e9f2012-09-21 11:39:54 -07001293 @Override
Jeff Brown89ef0722011-08-10 16:25:21 -07001294 public void monitor() {
1295 synchronized (mInputFilterLock) { }
Jeff Brown4532e612012-04-05 14:27:12 -07001296 nativeMonitor(mPtr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001297 }
1298
Jeff Brown4532e612012-04-05 14:27:12 -07001299 // Native callback.
1300 private void notifyConfigurationChanged(long whenNanos) {
Jeff Browna9d131c2012-09-20 16:48:17 -07001301 mWindowManagerCallbacks.notifyConfigurationChanged();
Jeff Brown4532e612012-04-05 14:27:12 -07001302 }
1303
1304 // Native callback.
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001305 private void notifyInputDevicesChanged(InputDevice[] inputDevices) {
1306 synchronized (mInputDevicesLock) {
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001307 if (!mInputDevicesChangedPending) {
1308 mInputDevicesChangedPending = true;
Jeff Browncf39bdf2012-05-18 14:41:19 -07001309 mHandler.obtainMessage(MSG_DELIVER_INPUT_DEVICES_CHANGED,
1310 mInputDevices).sendToTarget();
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001311 }
Jeff Browncf39bdf2012-05-18 14:41:19 -07001312
1313 mInputDevices = inputDevices;
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001314 }
1315 }
1316
1317 // Native callback.
Jeff Brownbcc046a2012-09-27 20:46:43 -07001318 private void notifySwitch(long whenNanos, int switchValues, int switchMask) {
1319 if (DEBUG) {
1320 Slog.d(TAG, "notifySwitch: values=" + Integer.toHexString(switchValues)
1321 + ", mask=" + Integer.toHexString(switchMask));
1322 }
1323
Craig Mautner2f39e9f2012-09-21 11:39:54 -07001324 if ((switchMask & SW_LID_BIT) != 0) {
1325 final boolean lidOpen = ((switchValues & SW_LID_BIT) == 0);
Jeff Brownbcc046a2012-09-27 20:46:43 -07001326 mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown53384282012-08-20 20:16:01 -07001327 }
Craig Mautner2f39e9f2012-09-21 11:39:54 -07001328
1329 if (mUseDevInputEventForAudioJack && (switchMask & SW_JACK_BITS) != 0) {
1330 mWiredAccessoryCallbacks.notifyWiredAccessoryChanged(whenNanos, switchValues,
1331 switchMask);
1332 }
Jeff Brown4532e612012-04-05 14:27:12 -07001333 }
1334
1335 // Native callback.
1336 private void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
Jeff Browna9d131c2012-09-20 16:48:17 -07001337 mWindowManagerCallbacks.notifyInputChannelBroken(inputWindowHandle);
Jeff Brown4532e612012-04-05 14:27:12 -07001338 }
1339
1340 // Native callback.
1341 private long notifyANR(InputApplicationHandle inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -07001342 InputWindowHandle inputWindowHandle, String reason) {
1343 return mWindowManagerCallbacks.notifyANR(
1344 inputApplicationHandle, inputWindowHandle, reason);
Jeff Brown4532e612012-04-05 14:27:12 -07001345 }
1346
1347 // Native callback.
1348 final boolean filterInputEvent(InputEvent event, int policyFlags) {
1349 synchronized (mInputFilterLock) {
1350 if (mInputFilter != null) {
Svetoslav Ganovc9c9a482012-07-16 08:46:07 -07001351 try {
1352 mInputFilter.filterInputEvent(event, policyFlags);
1353 } catch (RemoteException e) {
1354 /* ignore */
1355 }
Jeff Brown4532e612012-04-05 14:27:12 -07001356 return false;
1357 }
1358 }
1359 event.recycle();
1360 return true;
1361 }
1362
1363 // Native callback.
Jeff Brown037c33e2014-04-09 00:31:55 -07001364 private int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
1365 return mWindowManagerCallbacks.interceptKeyBeforeQueueing(event, policyFlags);
Jeff Brown4532e612012-04-05 14:27:12 -07001366 }
1367
1368 // Native callback.
Jeff Brown037c33e2014-04-09 00:31:55 -07001369 private int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
1370 return mWindowManagerCallbacks.interceptWakeMotionBeforeQueueing(
Jeff Brown26875502014-01-30 21:47:47 -08001371 whenNanos, policyFlags);
Jeff Brown4532e612012-04-05 14:27:12 -07001372 }
1373
1374 // Native callback.
1375 private long interceptKeyBeforeDispatching(InputWindowHandle focus,
1376 KeyEvent event, int policyFlags) {
Jeff Browna9d131c2012-09-20 16:48:17 -07001377 return mWindowManagerCallbacks.interceptKeyBeforeDispatching(focus, event, policyFlags);
Jeff Brown4532e612012-04-05 14:27:12 -07001378 }
1379
1380 // Native callback.
1381 private KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
1382 KeyEvent event, int policyFlags) {
Jeff Browna9d131c2012-09-20 16:48:17 -07001383 return mWindowManagerCallbacks.dispatchUnhandledKey(focus, event, policyFlags);
Jeff Brown4532e612012-04-05 14:27:12 -07001384 }
1385
1386 // Native callback.
1387 private boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
1388 return mContext.checkPermission(android.Manifest.permission.INJECT_EVENTS,
1389 injectorPid, injectorUid) == PackageManager.PERMISSION_GRANTED;
1390 }
1391
1392 // Native callback.
1393 private int getVirtualKeyQuietTimeMillis() {
1394 return mContext.getResources().getInteger(
1395 com.android.internal.R.integer.config_virtualKeyQuietTimeMillis);
1396 }
1397
1398 // Native callback.
1399 private String[] getExcludedDeviceNames() {
1400 ArrayList<String> names = new ArrayList<String>();
1401
1402 // Read partner-provided list of excluded input devices
1403 XmlPullParser parser = null;
1404 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
1405 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
1406 FileReader confreader = null;
1407 try {
1408 confreader = new FileReader(confFile);
1409 parser = Xml.newPullParser();
1410 parser.setInput(confreader);
1411 XmlUtils.beginDocument(parser, "devices");
1412
1413 while (true) {
1414 XmlUtils.nextElement(parser);
1415 if (!"device".equals(parser.getName())) {
1416 break;
1417 }
1418 String name = parser.getAttributeValue(null, "name");
1419 if (name != null) {
1420 names.add(name);
1421 }
1422 }
1423 } catch (FileNotFoundException e) {
1424 // It's ok if the file does not exist.
1425 } catch (Exception e) {
1426 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
1427 } finally {
1428 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
1429 }
1430
1431 return names.toArray(new String[names.size()]);
1432 }
1433
1434 // Native callback.
1435 private int getKeyRepeatTimeout() {
1436 return ViewConfiguration.getKeyRepeatTimeout();
1437 }
1438
1439 // Native callback.
1440 private int getKeyRepeatDelay() {
1441 return ViewConfiguration.getKeyRepeatDelay();
1442 }
1443
1444 // Native callback.
1445 private int getHoverTapTimeout() {
1446 return ViewConfiguration.getHoverTapTimeout();
1447 }
1448
1449 // Native callback.
1450 private int getHoverTapSlop() {
1451 return ViewConfiguration.getHoverTapSlop();
1452 }
1453
1454 // Native callback.
1455 private int getDoubleTapTimeout() {
1456 return ViewConfiguration.getDoubleTapTimeout();
1457 }
1458
1459 // Native callback.
1460 private int getLongPressTimeout() {
1461 return ViewConfiguration.getLongPressTimeout();
1462 }
1463
1464 // Native callback.
1465 private int getPointerLayer() {
Jeff Browna9d131c2012-09-20 16:48:17 -07001466 return mWindowManagerCallbacks.getPointerLayer();
Jeff Brown4532e612012-04-05 14:27:12 -07001467 }
1468
1469 // Native callback.
1470 private PointerIcon getPointerIcon() {
1471 return PointerIcon.getDefaultIcon(mContext);
1472 }
1473
Jeff Brown6ec6f792012-04-17 16:52:41 -07001474 // Native callback.
RoboErikca9eef62013-12-16 11:27:55 -08001475 private String[] getKeyboardLayoutOverlay(InputDeviceIdentifier identifier) {
Jeff Brown6ec6f792012-04-17 16:52:41 -07001476 if (!mSystemReady) {
1477 return null;
1478 }
1479
RoboErikca9eef62013-12-16 11:27:55 -08001480 String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(identifier);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001481 if (keyboardLayoutDescriptor == null) {
1482 return null;
1483 }
1484
1485 final String[] result = new String[2];
1486 visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
1487 @Override
1488 public void visitKeyboardLayout(Resources resources,
Jeff Brownd9fec5d2012-05-17 16:01:54 -07001489 String descriptor, String label, String collection, int keyboardLayoutResId) {
Jeff Brown6ec6f792012-04-17 16:52:41 -07001490 try {
1491 result[0] = descriptor;
1492 result[1] = Streams.readFully(new InputStreamReader(
Jeff Brown2f095762012-05-10 21:29:33 -07001493 resources.openRawResource(keyboardLayoutResId)));
Jeff Brown6ec6f792012-04-17 16:52:41 -07001494 } catch (IOException ex) {
1495 } catch (NotFoundException ex) {
1496 }
1497 }
1498 });
1499 if (result[0] == null) {
1500 Log.w(TAG, "Could not get keyboard layout with descriptor '"
1501 + keyboardLayoutDescriptor + "'.");
1502 return null;
1503 }
1504 return result;
1505 }
1506
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001507 // Native callback.
1508 private String getDeviceAlias(String uniqueId) {
Matthew Xie96313142012-06-29 16:57:31 -07001509 if (BluetoothAdapter.checkBluetoothAddress(uniqueId)) {
1510 // TODO(BT) mBluetoothService.getRemoteAlias(uniqueId)
1511 return null;
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001512 }
1513 return null;
1514 }
1515
Jeff Brown4532e612012-04-05 14:27:12 -07001516 /**
1517 * Callback interface implemented by the Window Manager.
1518 */
Jeff Browna9d131c2012-09-20 16:48:17 -07001519 public interface WindowManagerCallbacks {
Jeff Brown4532e612012-04-05 14:27:12 -07001520 public void notifyConfigurationChanged();
1521
1522 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
1523
1524 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle);
1525
1526 public long notifyANR(InputApplicationHandle inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -07001527 InputWindowHandle inputWindowHandle, String reason);
Jeff Brown4532e612012-04-05 14:27:12 -07001528
Jeff Brown037c33e2014-04-09 00:31:55 -07001529 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);
Jeff Brown4532e612012-04-05 14:27:12 -07001530
Jeff Brown037c33e2014-04-09 00:31:55 -07001531 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags);
Jeff Brown4532e612012-04-05 14:27:12 -07001532
1533 public long interceptKeyBeforeDispatching(InputWindowHandle focus,
1534 KeyEvent event, int policyFlags);
1535
1536 public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
1537 KeyEvent event, int policyFlags);
1538
1539 public int getPointerLayer();
1540 }
1541
1542 /**
Craig Mautner2f39e9f2012-09-21 11:39:54 -07001543 * Callback interface implemented by WiredAccessoryObserver.
1544 */
1545 public interface WiredAccessoryCallbacks {
1546 public void notifyWiredAccessoryChanged(long whenNanos, int switchValues, int switchMask);
1547 }
1548
1549 /**
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001550 * Private handler for the input manager.
1551 */
1552 private final class InputManagerHandler extends Handler {
Jeff Browna9d131c2012-09-20 16:48:17 -07001553 public InputManagerHandler(Looper looper) {
1554 super(looper, null, true /*async*/);
Jeff Browna2910d02012-08-25 12:29:46 -07001555 }
1556
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001557 @Override
1558 public void handleMessage(Message msg) {
1559 switch (msg.what) {
1560 case MSG_DELIVER_INPUT_DEVICES_CHANGED:
Jeff Browncf39bdf2012-05-18 14:41:19 -07001561 deliverInputDevicesChanged((InputDevice[])msg.obj);
1562 break;
1563 case MSG_SWITCH_KEYBOARD_LAYOUT:
1564 handleSwitchKeyboardLayout(msg.arg1, msg.arg2);
1565 break;
1566 case MSG_RELOAD_KEYBOARD_LAYOUTS:
1567 reloadKeyboardLayouts();
1568 break;
1569 case MSG_UPDATE_KEYBOARD_LAYOUTS:
1570 updateKeyboardLayouts();
1571 break;
1572 case MSG_RELOAD_DEVICE_ALIASES:
1573 reloadDeviceAliases();
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001574 break;
1575 }
1576 }
1577 }
1578
1579 /**
Jeff Brown4532e612012-04-05 14:27:12 -07001580 * Hosting interface for input filters to call back into the input manager.
1581 */
Svetoslav Ganovc9c9a482012-07-16 08:46:07 -07001582 private final class InputFilterHost extends IInputFilterHost.Stub {
Jeff Brown0029c662011-03-30 02:25:18 -07001583 private boolean mDisconnected;
1584
1585 public void disconnectLocked() {
1586 mDisconnected = true;
1587 }
1588
Craig Mautner2f39e9f2012-09-21 11:39:54 -07001589 @Override
Jeff Brown0029c662011-03-30 02:25:18 -07001590 public void sendInputEvent(InputEvent event, int policyFlags) {
1591 if (event == null) {
1592 throw new IllegalArgumentException("event must not be null");
1593 }
1594
1595 synchronized (mInputFilterLock) {
1596 if (!mDisconnected) {
Jeff Brown38f96e52014-02-11 14:32:56 -08001597 nativeInjectInputEvent(mPtr, event, Display.DEFAULT_DISPLAY, 0, 0,
Jeff Brownac143512012-04-05 18:57:33 -07001598 InputManager.INJECT_INPUT_EVENT_MODE_ASYNC, 0,
Jeff Brown0029c662011-03-30 02:25:18 -07001599 policyFlags | WindowManagerPolicy.FLAG_FILTERED);
1600 }
1601 }
1602 }
1603 }
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001604
1605 private static final class KeyboardLayoutDescriptor {
1606 public String packageName;
1607 public String receiverName;
1608 public String keyboardLayoutName;
1609
1610 public static String format(String packageName,
1611 String receiverName, String keyboardName) {
1612 return packageName + "/" + receiverName + "/" + keyboardName;
1613 }
1614
1615 public static KeyboardLayoutDescriptor parse(String descriptor) {
1616 int pos = descriptor.indexOf('/');
1617 if (pos < 0 || pos + 1 == descriptor.length()) {
1618 return null;
1619 }
1620 int pos2 = descriptor.indexOf('/', pos + 1);
1621 if (pos2 < pos + 2 || pos2 + 1 == descriptor.length()) {
1622 return null;
1623 }
1624
1625 KeyboardLayoutDescriptor result = new KeyboardLayoutDescriptor();
1626 result.packageName = descriptor.substring(0, pos);
1627 result.receiverName = descriptor.substring(pos + 1, pos2);
1628 result.keyboardLayoutName = descriptor.substring(pos2 + 1);
1629 return result;
1630 }
1631 }
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001632
Jeff Brown6ec6f792012-04-17 16:52:41 -07001633 private interface KeyboardLayoutVisitor {
1634 void visitKeyboardLayout(Resources resources,
Jeff Brownd9fec5d2012-05-17 16:01:54 -07001635 String descriptor, String label, String collection, int keyboardLayoutResId);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001636 }
1637
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001638 private final class InputDevicesChangedListenerRecord implements DeathRecipient {
1639 private final int mPid;
1640 private final IInputDevicesChangedListener mListener;
1641
1642 public InputDevicesChangedListenerRecord(int pid, IInputDevicesChangedListener listener) {
1643 mPid = pid;
1644 mListener = listener;
1645 }
1646
1647 @Override
1648 public void binderDied() {
1649 if (DEBUG) {
1650 Slog.d(TAG, "Input devices changed listener for pid " + mPid + " died.");
1651 }
1652 onInputDevicesChangedListenerDied(mPid);
1653 }
1654
1655 public void notifyInputDevicesChanged(int[] info) {
1656 try {
1657 mListener.onInputDevicesChanged(info);
1658 } catch (RemoteException ex) {
1659 Slog.w(TAG, "Failed to notify process "
1660 + mPid + " that input devices changed, assuming it died.", ex);
1661 binderDied();
1662 }
1663 }
1664 }
Jeff Browna47425a2012-04-13 04:09:27 -07001665
1666 private final class VibratorToken implements DeathRecipient {
1667 public final int mDeviceId;
1668 public final IBinder mToken;
1669 public final int mTokenValue;
1670
1671 public boolean mVibrating;
1672
1673 public VibratorToken(int deviceId, IBinder token, int tokenValue) {
1674 mDeviceId = deviceId;
1675 mToken = token;
1676 mTokenValue = tokenValue;
1677 }
1678
1679 @Override
1680 public void binderDied() {
1681 if (DEBUG) {
1682 Slog.d(TAG, "Vibrator token died.");
1683 }
1684 onVibratorTokenDied(this);
1685 }
1686 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001687
1688 private final class LocalService extends InputManagerInternal {
1689 @Override
1690 public void setDisplayViewports(
1691 DisplayViewport defaultViewport, DisplayViewport externalTouchViewport) {
1692 setDisplayViewportsInternal(defaultViewport, externalTouchViewport);
1693 }
Jeff Brown38f96e52014-02-11 14:32:56 -08001694
1695 @Override
1696 public boolean injectInputEvent(InputEvent event, int displayId, int mode) {
1697 return injectInputEventInternal(event, displayId, mode);
1698 }
Jeff Brown037c33e2014-04-09 00:31:55 -07001699
1700 @Override
1701 public void setInteractive(boolean interactive) {
1702 nativeSetInteractive(mPtr, interactive);
1703 }
Jeff Brown4ccb8232014-01-16 22:16:42 -08001704 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001705}