Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | /* |
| 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 Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 17 | package com.android.server.input; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 18 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 19 | import com.android.internal.R; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 20 | import com.android.internal.util.XmlUtils; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 21 | import com.android.server.DisplayThread; |
| 22 | import com.android.server.LocalServices; |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 23 | import com.android.server.Watchdog; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 24 | |
| 25 | import org.xmlpull.v1.XmlPullParser; |
| 26 | |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 27 | import android.Manifest; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 28 | import android.app.Notification; |
| 29 | import android.app.NotificationManager; |
| 30 | import android.app.PendingIntent; |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 31 | import android.bluetooth.BluetoothAdapter; |
| 32 | import android.bluetooth.BluetoothDevice; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 33 | import android.content.BroadcastReceiver; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 34 | import android.content.ComponentName; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 35 | import android.content.Context; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 36 | import android.content.Intent; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 37 | import android.content.IntentFilter; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 38 | import android.content.pm.ActivityInfo; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 40 | import android.content.pm.ResolveInfo; |
| 41 | import android.content.pm.PackageManager.NameNotFoundException; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 42 | import android.content.res.Resources; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 43 | import android.content.res.Resources.NotFoundException; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 44 | import android.content.res.TypedArray; |
| 45 | import android.content.res.XmlResourceParser; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 46 | import android.database.ContentObserver; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 47 | import android.hardware.display.DisplayViewport; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 48 | import android.hardware.input.IInputDevicesChangedListener; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 49 | import android.hardware.input.IInputManager; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 50 | import android.hardware.input.InputManager; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 51 | import android.hardware.input.InputManagerInternal; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 52 | import android.hardware.input.KeyboardLayout; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 53 | import android.os.Binder; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 54 | import android.os.Bundle; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 55 | import android.os.Environment; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 56 | import android.os.Handler; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 57 | import android.os.IBinder; |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 58 | import android.os.Looper; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 59 | import android.os.Message; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 60 | import android.os.MessageQueue; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 61 | import android.os.Process; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 62 | import android.os.RemoteException; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 63 | import android.os.UserHandle; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 64 | import android.provider.Settings; |
| 65 | import android.provider.Settings.SettingNotFoundException; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 66 | import android.util.Log; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 67 | import android.util.Slog; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 68 | import android.util.SparseArray; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 69 | import android.util.Xml; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 70 | import android.view.IInputFilter; |
| 71 | import android.view.IInputFilterHost; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 72 | import android.view.InputChannel; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 73 | import android.view.InputDevice; |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 74 | import android.view.InputEvent; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 75 | import android.view.KeyEvent; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 76 | import android.view.PointerIcon; |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 77 | import android.view.ViewConfiguration; |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 78 | import android.view.WindowManagerPolicy; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 79 | import android.widget.Toast; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 80 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 81 | import java.io.File; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 82 | import java.io.FileDescriptor; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 83 | import java.io.FileNotFoundException; |
| 84 | import java.io.FileReader; |
| 85 | import java.io.IOException; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 86 | import java.io.InputStreamReader; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 87 | import java.io.PrintWriter; |
| 88 | import java.util.ArrayList; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 89 | import java.util.HashMap; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 90 | import java.util.HashSet; |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 91 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 92 | import libcore.io.Streams; |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 93 | import libcore.util.Objects; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Wraps the C++ InputManager and provides its callbacks. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 97 | */ |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 98 | public class InputManagerService extends IInputManager.Stub |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 99 | implements Watchdog.Monitor { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 100 | static final String TAG = "InputManager"; |
Jeff Brown | 1b9ba57 | 2012-05-21 10:54:18 -0700 | [diff] [blame] | 101 | static final boolean DEBUG = false; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 102 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 103 | private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml"; |
| 104 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 105 | private static final int MSG_DELIVER_INPUT_DEVICES_CHANGED = 1; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 106 | private static final int MSG_SWITCH_KEYBOARD_LAYOUT = 2; |
| 107 | private static final int MSG_RELOAD_KEYBOARD_LAYOUTS = 3; |
| 108 | private static final int MSG_UPDATE_KEYBOARD_LAYOUTS = 4; |
| 109 | private static final int MSG_RELOAD_DEVICE_ALIASES = 5; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 110 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 111 | // Pointer to native input manager service object. |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 112 | private final long mPtr; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 113 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 114 | private final Context mContext; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 115 | private final InputManagerHandler mHandler; |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 116 | |
| 117 | private WindowManagerCallbacks mWindowManagerCallbacks; |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 118 | private WiredAccessoryCallbacks mWiredAccessoryCallbacks; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 119 | private boolean mSystemReady; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 120 | private NotificationManager mNotificationManager; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 121 | |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 122 | // Persistent data store. Must be locked each time during use. |
| 123 | private final PersistentDataStore mDataStore = new PersistentDataStore(); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 124 | |
| 125 | // List of currently registered input devices changed listeners by process id. |
| 126 | private Object mInputDevicesLock = new Object(); |
| 127 | private boolean mInputDevicesChangedPending; // guarded by mInputDevicesLock |
| 128 | private InputDevice[] mInputDevices = new InputDevice[0]; |
| 129 | private final SparseArray<InputDevicesChangedListenerRecord> mInputDevicesChangedListeners = |
| 130 | new SparseArray<InputDevicesChangedListenerRecord>(); // guarded by mInputDevicesLock |
| 131 | private final ArrayList<InputDevicesChangedListenerRecord> |
| 132 | mTempInputDevicesChangedListenersToNotify = |
| 133 | new ArrayList<InputDevicesChangedListenerRecord>(); // handler thread only |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 134 | private final ArrayList<InputDevice> |
| 135 | mTempFullKeyboards = new ArrayList<InputDevice>(); // handler thread only |
| 136 | private boolean mKeyboardLayoutNotificationShown; |
| 137 | private PendingIntent mKeyboardLayoutIntent; |
| 138 | private Toast mSwitchedKeyboardLayoutToast; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 139 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 140 | // State for vibrator tokens. |
| 141 | private Object mVibratorLock = new Object(); |
| 142 | private HashMap<IBinder, VibratorToken> mVibratorTokens = |
| 143 | new HashMap<IBinder, VibratorToken>(); |
| 144 | private int mNextVibratorTokenValue; |
| 145 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 146 | // State for the currently installed input filter. |
| 147 | final Object mInputFilterLock = new Object(); |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 148 | IInputFilter mInputFilter; // guarded by mInputFilterLock |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 149 | InputFilterHost mInputFilterHost; // guarded by mInputFilterLock |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 150 | |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 151 | private static native long nativeInit(InputManagerService service, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 152 | Context context, MessageQueue messageQueue); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 153 | private static native void nativeStart(long ptr); |
| 154 | private static native void nativeSetDisplayViewport(long ptr, boolean external, |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 155 | int displayId, int rotation, |
| 156 | int logicalLeft, int logicalTop, int logicalRight, int logicalBottom, |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 157 | int physicalLeft, int physicalTop, int physicalRight, int physicalBottom, |
| 158 | int deviceWidth, int deviceHeight); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 159 | |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 160 | private static native int nativeGetScanCodeState(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 161 | int deviceId, int sourceMask, int scanCode); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 162 | private static native int nativeGetKeyCodeState(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 163 | int deviceId, int sourceMask, int keyCode); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 164 | private static native int nativeGetSwitchState(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 165 | int deviceId, int sourceMask, int sw); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 166 | private static native boolean nativeHasKeys(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 167 | int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 168 | private static native void nativeRegisterInputChannel(long ptr, InputChannel inputChannel, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 169 | InputWindowHandle inputWindowHandle, boolean monitor); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 170 | private static native void nativeUnregisterInputChannel(long ptr, InputChannel inputChannel); |
| 171 | private static native void nativeSetInputFilterEnabled(long ptr, boolean enable); |
| 172 | private static native int nativeInjectInputEvent(long ptr, InputEvent event, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 173 | int injectorPid, int injectorUid, int syncMode, int timeoutMillis, |
| 174 | int policyFlags); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 175 | private static native void nativeSetInputWindows(long ptr, InputWindowHandle[] windowHandles); |
| 176 | private static native void nativeSetInputDispatchMode(long ptr, boolean enabled, boolean frozen); |
| 177 | private static native void nativeSetSystemUiVisibility(long ptr, int visibility); |
| 178 | private static native void nativeSetFocusedApplication(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 179 | InputApplicationHandle application); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 180 | private static native boolean nativeTransferTouchFocus(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 181 | InputChannel fromChannel, InputChannel toChannel); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 182 | private static native void nativeSetPointerSpeed(long ptr, int speed); |
| 183 | private static native void nativeSetShowTouches(long ptr, boolean enabled); |
| 184 | private static native void nativeVibrate(long ptr, int deviceId, long[] pattern, |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 185 | int repeat, int token); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 186 | private static native void nativeCancelVibrate(long ptr, int deviceId, int token); |
| 187 | private static native void nativeReloadKeyboardLayouts(long ptr); |
| 188 | private static native void nativeReloadDeviceAliases(long ptr); |
| 189 | private static native String nativeDump(long ptr); |
| 190 | private static native void nativeMonitor(long ptr); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 191 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 192 | // Input event injection constants defined in InputDispatcher.h. |
| 193 | private static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0; |
| 194 | private static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1; |
| 195 | private static final int INPUT_EVENT_INJECTION_FAILED = 2; |
| 196 | private static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3; |
| 197 | |
| 198 | // Maximum number of milliseconds to wait for input event injection. |
| 199 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
| 200 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 201 | // Key states (may be returned by queries about the current state of a |
| 202 | // particular key code, scan code or switch). |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 203 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 204 | /** The key state is unknown or the requested key itself is not supported. */ |
| 205 | public static final int KEY_STATE_UNKNOWN = -1; |
| 206 | |
| 207 | /** The key is up. /*/ |
| 208 | public static final int KEY_STATE_UP = 0; |
| 209 | |
| 210 | /** The key is down. */ |
| 211 | public static final int KEY_STATE_DOWN = 1; |
| 212 | |
| 213 | /** The key is down but is a virtual key press that is being emulated by the system. */ |
| 214 | public static final int KEY_STATE_VIRTUAL = 2; |
| 215 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 216 | /** Scan code: Mouse / trackball button. */ |
| 217 | public static final int BTN_MOUSE = 0x110; |
| 218 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 219 | // Switch code values must match bionic/libc/kernel/common/linux/input.h |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 220 | /** Switch code: Lid switch. When set, lid is shut. */ |
| 221 | public static final int SW_LID = 0x00; |
| 222 | |
| 223 | /** Switch code: Keypad slide. When set, keyboard is exposed. */ |
| 224 | public static final int SW_KEYPAD_SLIDE = 0x0a; |
| 225 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 226 | /** Switch code: Headphone. When set, headphone is inserted. */ |
| 227 | public static final int SW_HEADPHONE_INSERT = 0x02; |
| 228 | |
| 229 | /** Switch code: Microphone. When set, microphone is inserted. */ |
| 230 | public static final int SW_MICROPHONE_INSERT = 0x04; |
| 231 | |
| 232 | /** Switch code: Headphone/Microphone Jack. When set, something is inserted. */ |
| 233 | public static final int SW_JACK_PHYSICAL_INSERT = 0x07; |
| 234 | |
| 235 | public static final int SW_LID_BIT = 1 << SW_LID; |
| 236 | public static final int SW_KEYPAD_SLIDE_BIT = 1 << SW_KEYPAD_SLIDE; |
| 237 | public static final int SW_HEADPHONE_INSERT_BIT = 1 << SW_HEADPHONE_INSERT; |
| 238 | public static final int SW_MICROPHONE_INSERT_BIT = 1 << SW_MICROPHONE_INSERT; |
| 239 | public static final int SW_JACK_PHYSICAL_INSERT_BIT = 1 << SW_JACK_PHYSICAL_INSERT; |
| 240 | public static final int SW_JACK_BITS = |
| 241 | SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_JACK_PHYSICAL_INSERT_BIT; |
| 242 | |
| 243 | /** Whether to use the dev/input/event or uevent subsystem for the audio jack. */ |
| 244 | final boolean mUseDevInputEventForAudioJack; |
| 245 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 246 | public InputManagerService(Context context) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 247 | this.mContext = context; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 248 | this.mHandler = new InputManagerHandler(DisplayThread.get().getLooper()); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 249 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 250 | mUseDevInputEventForAudioJack = |
| 251 | context.getResources().getBoolean(R.bool.config_useDevInputEventForAudioJack); |
| 252 | Slog.i(TAG, "Initializing input manager, mUseDevInputEventForAudioJack=" |
| 253 | + mUseDevInputEventForAudioJack); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 254 | mPtr = nativeInit(this, mContext, mHandler.getLooper().getQueue()); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 255 | |
| 256 | LocalServices.addService(InputManagerInternal.class, new LocalService()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 257 | } |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 258 | |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 259 | public void setWindowManagerCallbacks(WindowManagerCallbacks callbacks) { |
| 260 | mWindowManagerCallbacks = callbacks; |
| 261 | } |
| 262 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 263 | public void setWiredAccessoryCallbacks(WiredAccessoryCallbacks callbacks) { |
| 264 | mWiredAccessoryCallbacks = callbacks; |
| 265 | } |
| 266 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 267 | public void start() { |
| 268 | Slog.i(TAG, "Starting input manager"); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 269 | nativeStart(mPtr); |
| 270 | |
| 271 | // Add ourself to the Watchdog monitors. |
| 272 | Watchdog.getInstance().addMonitor(this); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 273 | |
| 274 | registerPointerSpeedSettingObserver(); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 275 | registerShowTouchesSettingObserver(); |
| 276 | |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 277 | mContext.registerReceiver(new BroadcastReceiver() { |
| 278 | @Override |
| 279 | public void onReceive(Context context, Intent intent) { |
| 280 | updatePointerSpeedFromSettings(); |
| 281 | updateShowTouchesFromSettings(); |
| 282 | } |
| 283 | }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler); |
| 284 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 285 | updatePointerSpeedFromSettings(); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 286 | updateShowTouchesFromSettings(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 287 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 288 | |
Matthew Xie | 9631314 | 2012-06-29 16:57:31 -0700 | [diff] [blame] | 289 | // TODO(BT) Pass in paramter for bluetooth system |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 290 | public void systemRunning() { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 291 | if (DEBUG) { |
| 292 | Slog.d(TAG, "System ready."); |
| 293 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 294 | mNotificationManager = (NotificationManager)mContext.getSystemService( |
| 295 | Context.NOTIFICATION_SERVICE); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 296 | mSystemReady = true; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 297 | |
| 298 | IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); |
| 299 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 300 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
Jeff Brown | 69b0716 | 2013-11-07 00:30:16 -0800 | [diff] [blame] | 301 | filter.addAction(Intent.ACTION_PACKAGE_REPLACED); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 302 | filter.addDataScheme("package"); |
| 303 | mContext.registerReceiver(new BroadcastReceiver() { |
| 304 | @Override |
| 305 | public void onReceive(Context context, Intent intent) { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 306 | updateKeyboardLayouts(); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 307 | } |
| 308 | }, filter, null, mHandler); |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 309 | |
| 310 | filter = new IntentFilter(BluetoothDevice.ACTION_ALIAS_CHANGED); |
| 311 | mContext.registerReceiver(new BroadcastReceiver() { |
| 312 | @Override |
| 313 | public void onReceive(Context context, Intent intent) { |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 314 | reloadDeviceAliases(); |
| 315 | } |
| 316 | }, filter, null, mHandler); |
| 317 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 318 | mHandler.sendEmptyMessage(MSG_RELOAD_DEVICE_ALIASES); |
| 319 | mHandler.sendEmptyMessage(MSG_UPDATE_KEYBOARD_LAYOUTS); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | private void reloadKeyboardLayouts() { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 323 | if (DEBUG) { |
| 324 | Slog.d(TAG, "Reloading keyboard layouts."); |
| 325 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 326 | nativeReloadKeyboardLayouts(mPtr); |
| 327 | } |
| 328 | |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 329 | private void reloadDeviceAliases() { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 330 | if (DEBUG) { |
| 331 | Slog.d(TAG, "Reloading device names."); |
| 332 | } |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 333 | nativeReloadDeviceAliases(mPtr); |
| 334 | } |
| 335 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 336 | private void setDisplayViewportsInternal(DisplayViewport defaultViewport, |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 337 | DisplayViewport externalTouchViewport) { |
| 338 | if (defaultViewport.valid) { |
| 339 | setDisplayViewport(false, defaultViewport); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 340 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 341 | |
| 342 | if (externalTouchViewport.valid) { |
| 343 | setDisplayViewport(true, externalTouchViewport); |
| 344 | } else if (defaultViewport.valid) { |
| 345 | setDisplayViewport(true, defaultViewport); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 346 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 347 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 348 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 349 | private void setDisplayViewport(boolean external, DisplayViewport viewport) { |
| 350 | nativeSetDisplayViewport(mPtr, external, |
| 351 | viewport.displayId, viewport.orientation, |
| 352 | viewport.logicalFrame.left, viewport.logicalFrame.top, |
| 353 | viewport.logicalFrame.right, viewport.logicalFrame.bottom, |
| 354 | viewport.physicalFrame.left, viewport.physicalFrame.top, |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 355 | viewport.physicalFrame.right, viewport.physicalFrame.bottom, |
| 356 | viewport.deviceWidth, viewport.deviceHeight); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 357 | } |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 358 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 359 | /** |
| 360 | * Gets the current state of a key or button by key code. |
| 361 | * @param deviceId The input device id, or -1 to consult all devices. |
| 362 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 363 | * consider all input sources. An input device is consulted if at least one of its |
| 364 | * non-class input source bits matches the specified source mask. |
| 365 | * @param keyCode The key code to check. |
| 366 | * @return The key state. |
| 367 | */ |
| 368 | public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 369 | return nativeGetKeyCodeState(mPtr, deviceId, sourceMask, keyCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 370 | } |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 371 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 372 | /** |
| 373 | * Gets the current state of a key or button by scan code. |
| 374 | * @param deviceId The input device id, or -1 to consult all devices. |
| 375 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 376 | * consider all input sources. An input device is consulted if at least one of its |
| 377 | * non-class input source bits matches the specified source mask. |
| 378 | * @param scanCode The scan code to check. |
| 379 | * @return The key state. |
| 380 | */ |
| 381 | public int getScanCodeState(int deviceId, int sourceMask, int scanCode) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 382 | return nativeGetScanCodeState(mPtr, deviceId, sourceMask, scanCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 385 | /** |
| 386 | * Gets the current state of a switch by switch code. |
| 387 | * @param deviceId The input device id, or -1 to consult all devices. |
| 388 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 389 | * consider all input sources. An input device is consulted if at least one of its |
| 390 | * non-class input source bits matches the specified source mask. |
| 391 | * @param switchCode The switch code to check. |
| 392 | * @return The switch state. |
| 393 | */ |
| 394 | public int getSwitchState(int deviceId, int sourceMask, int switchCode) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 395 | return nativeGetSwitchState(mPtr, deviceId, sourceMask, switchCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 398 | /** |
| 399 | * Determines whether the specified key codes are supported by a particular device. |
| 400 | * @param deviceId The input device id, or -1 to consult all devices. |
| 401 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 402 | * consider all input sources. An input device is consulted if at least one of its |
| 403 | * non-class input source bits matches the specified source mask. |
| 404 | * @param keyCodes The array of key codes to check. |
| 405 | * @param keyExists An array at least as large as keyCodes whose entries will be set |
| 406 | * to true or false based on the presence or absence of support for the corresponding |
| 407 | * key codes. |
| 408 | * @return True if the lookup was successful, false otherwise. |
| 409 | */ |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 410 | @Override // Binder call |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 411 | public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 412 | if (keyCodes == null) { |
| 413 | throw new IllegalArgumentException("keyCodes must not be null."); |
| 414 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 415 | if (keyExists == null || keyExists.length < keyCodes.length) { |
| 416 | throw new IllegalArgumentException("keyExists must not be null and must be at " |
| 417 | + "least as large as keyCodes."); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 420 | return nativeHasKeys(mPtr, deviceId, sourceMask, keyCodes, keyExists); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 423 | /** |
| 424 | * Creates an input channel that will receive all input from the input dispatcher. |
| 425 | * @param inputChannelName The input channel name. |
| 426 | * @return The input channel. |
| 427 | */ |
| 428 | public InputChannel monitorInput(String inputChannelName) { |
| 429 | if (inputChannelName == null) { |
| 430 | throw new IllegalArgumentException("inputChannelName must not be null."); |
| 431 | } |
| 432 | |
| 433 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 434 | nativeRegisterInputChannel(mPtr, inputChannels[0], null, true); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 435 | inputChannels[0].dispose(); // don't need to retain the Java object reference |
| 436 | return inputChannels[1]; |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Registers an input channel so that it can be used as an input event target. |
| 441 | * @param inputChannel The input channel to register. |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 442 | * @param inputWindowHandle The handle of the input window associated with the |
| 443 | * input channel, or null if none. |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 444 | */ |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 445 | public void registerInputChannel(InputChannel inputChannel, |
| 446 | InputWindowHandle inputWindowHandle) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 447 | if (inputChannel == null) { |
| 448 | throw new IllegalArgumentException("inputChannel must not be null."); |
| 449 | } |
| 450 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 451 | nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 454 | /** |
| 455 | * Unregisters an input channel. |
| 456 | * @param inputChannel The input channel to unregister. |
| 457 | */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 458 | public void unregisterInputChannel(InputChannel inputChannel) { |
| 459 | if (inputChannel == null) { |
| 460 | throw new IllegalArgumentException("inputChannel must not be null."); |
| 461 | } |
| 462 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 463 | nativeUnregisterInputChannel(mPtr, inputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 464 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 465 | |
| 466 | /** |
| 467 | * Sets an input filter that will receive all input events before they are dispatched. |
| 468 | * The input filter may then reinterpret input events or inject new ones. |
| 469 | * |
| 470 | * To ensure consistency, the input dispatcher automatically drops all events |
| 471 | * in progress whenever an input filter is installed or uninstalled. After an input |
| 472 | * filter is uninstalled, it can no longer send input events unless it is reinstalled. |
| 473 | * Any events it attempts to send after it has been uninstalled will be dropped. |
| 474 | * |
| 475 | * @param filter The input filter, or null to remove the current filter. |
| 476 | */ |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 477 | public void setInputFilter(IInputFilter filter) { |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 478 | synchronized (mInputFilterLock) { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 479 | final IInputFilter oldFilter = mInputFilter; |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 480 | if (oldFilter == filter) { |
| 481 | return; // nothing to do |
| 482 | } |
| 483 | |
| 484 | if (oldFilter != null) { |
| 485 | mInputFilter = null; |
| 486 | mInputFilterHost.disconnectLocked(); |
| 487 | mInputFilterHost = null; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 488 | try { |
| 489 | oldFilter.uninstall(); |
| 490 | } catch (RemoteException re) { |
| 491 | /* ignore */ |
| 492 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | if (filter != null) { |
| 496 | mInputFilter = filter; |
| 497 | mInputFilterHost = new InputFilterHost(); |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 498 | try { |
| 499 | filter.install(mInputFilterHost); |
| 500 | } catch (RemoteException re) { |
| 501 | /* ignore */ |
| 502 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 505 | nativeSetInputFilterEnabled(mPtr, filter != null); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 509 | @Override // Binder call |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 510 | public boolean injectInputEvent(InputEvent event, int mode) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 511 | if (event == null) { |
| 512 | throw new IllegalArgumentException("event must not be null"); |
| 513 | } |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 514 | if (mode != InputManager.INJECT_INPUT_EVENT_MODE_ASYNC |
| 515 | && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH |
| 516 | && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT) { |
| 517 | throw new IllegalArgumentException("mode is invalid"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 518 | } |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 519 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 520 | final int pid = Binder.getCallingPid(); |
| 521 | final int uid = Binder.getCallingUid(); |
| 522 | final long ident = Binder.clearCallingIdentity(); |
| 523 | final int result; |
| 524 | try { |
| 525 | result = nativeInjectInputEvent(mPtr, event, pid, uid, mode, |
| 526 | INJECTION_TIMEOUT_MILLIS, WindowManagerPolicy.FLAG_DISABLE_KEY_REPEAT); |
| 527 | } finally { |
| 528 | Binder.restoreCallingIdentity(ident); |
| 529 | } |
| 530 | switch (result) { |
| 531 | case INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 532 | Slog.w(TAG, "Input event injection from pid " + pid + " permission denied."); |
| 533 | throw new SecurityException( |
| 534 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 535 | case INPUT_EVENT_INJECTION_SUCCEEDED: |
| 536 | return true; |
| 537 | case INPUT_EVENT_INJECTION_TIMED_OUT: |
| 538 | Slog.w(TAG, "Input event injection from pid " + pid + " timed out."); |
| 539 | return false; |
| 540 | case INPUT_EVENT_INJECTION_FAILED: |
| 541 | default: |
| 542 | Slog.w(TAG, "Input event injection from pid " + pid + " failed."); |
| 543 | return false; |
| 544 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 545 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 546 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 547 | /** |
| 548 | * Gets information about the input device with the specified id. |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 549 | * @param deviceId The device id. |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 550 | * @return The input device or null if not found. |
| 551 | */ |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 552 | @Override // Binder call |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 553 | public InputDevice getInputDevice(int deviceId) { |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 554 | synchronized (mInputDevicesLock) { |
| 555 | final int count = mInputDevices.length; |
| 556 | for (int i = 0; i < count; i++) { |
| 557 | final InputDevice inputDevice = mInputDevices[i]; |
| 558 | if (inputDevice.getId() == deviceId) { |
| 559 | return inputDevice; |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | return null; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 564 | } |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 565 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 566 | /** |
| 567 | * Gets the ids of all input devices in the system. |
| 568 | * @return The input device ids. |
| 569 | */ |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 570 | @Override // Binder call |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 571 | public int[] getInputDeviceIds() { |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 572 | synchronized (mInputDevicesLock) { |
| 573 | final int count = mInputDevices.length; |
| 574 | int[] ids = new int[count]; |
| 575 | for (int i = 0; i < count; i++) { |
| 576 | ids[i] = mInputDevices[i].getId(); |
| 577 | } |
| 578 | return ids; |
| 579 | } |
| 580 | } |
| 581 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 582 | /** |
| 583 | * Gets all input devices in the system. |
| 584 | * @return The array of input devices. |
| 585 | */ |
| 586 | public InputDevice[] getInputDevices() { |
| 587 | synchronized (mInputDevicesLock) { |
| 588 | return mInputDevices; |
| 589 | } |
| 590 | } |
| 591 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 592 | @Override // Binder call |
| 593 | public void registerInputDevicesChangedListener(IInputDevicesChangedListener listener) { |
| 594 | if (listener == null) { |
| 595 | throw new IllegalArgumentException("listener must not be null"); |
| 596 | } |
| 597 | |
| 598 | synchronized (mInputDevicesLock) { |
| 599 | int callingPid = Binder.getCallingPid(); |
| 600 | if (mInputDevicesChangedListeners.get(callingPid) != null) { |
| 601 | throw new SecurityException("The calling process has already " |
| 602 | + "registered an InputDevicesChangedListener."); |
| 603 | } |
| 604 | |
| 605 | InputDevicesChangedListenerRecord record = |
| 606 | new InputDevicesChangedListenerRecord(callingPid, listener); |
| 607 | try { |
| 608 | IBinder binder = listener.asBinder(); |
| 609 | binder.linkToDeath(record, 0); |
| 610 | } catch (RemoteException ex) { |
| 611 | // give up |
| 612 | throw new RuntimeException(ex); |
| 613 | } |
| 614 | |
| 615 | mInputDevicesChangedListeners.put(callingPid, record); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | private void onInputDevicesChangedListenerDied(int pid) { |
| 620 | synchronized (mInputDevicesLock) { |
| 621 | mInputDevicesChangedListeners.remove(pid); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | // Must be called on handler. |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 626 | private void deliverInputDevicesChanged(InputDevice[] oldInputDevices) { |
| 627 | // Scan for changes. |
| 628 | int numFullKeyboardsAdded = 0; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 629 | mTempInputDevicesChangedListenersToNotify.clear(); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 630 | mTempFullKeyboards.clear(); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 631 | final int numListeners; |
| 632 | final int[] deviceIdAndGeneration; |
| 633 | synchronized (mInputDevicesLock) { |
| 634 | if (!mInputDevicesChangedPending) { |
| 635 | return; |
| 636 | } |
| 637 | mInputDevicesChangedPending = false; |
| 638 | |
| 639 | numListeners = mInputDevicesChangedListeners.size(); |
| 640 | for (int i = 0; i < numListeners; i++) { |
| 641 | mTempInputDevicesChangedListenersToNotify.add( |
| 642 | mInputDevicesChangedListeners.valueAt(i)); |
| 643 | } |
| 644 | |
| 645 | final int numDevices = mInputDevices.length; |
| 646 | deviceIdAndGeneration = new int[numDevices * 2]; |
| 647 | for (int i = 0; i < numDevices; i++) { |
| 648 | final InputDevice inputDevice = mInputDevices[i]; |
| 649 | deviceIdAndGeneration[i * 2] = inputDevice.getId(); |
| 650 | deviceIdAndGeneration[i * 2 + 1] = inputDevice.getGeneration(); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 651 | |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 652 | if (!inputDevice.isVirtual() && inputDevice.isFullKeyboard()) { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 653 | if (!containsInputDeviceWithDescriptor(oldInputDevices, |
| 654 | inputDevice.getDescriptor())) { |
| 655 | mTempFullKeyboards.add(numFullKeyboardsAdded++, inputDevice); |
| 656 | } else { |
| 657 | mTempFullKeyboards.add(inputDevice); |
| 658 | } |
| 659 | } |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 663 | // Notify listeners. |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 664 | for (int i = 0; i < numListeners; i++) { |
| 665 | mTempInputDevicesChangedListenersToNotify.get(i).notifyInputDevicesChanged( |
| 666 | deviceIdAndGeneration); |
| 667 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 668 | mTempInputDevicesChangedListenersToNotify.clear(); |
| 669 | |
| 670 | // Check for missing keyboard layouts. |
| 671 | if (mNotificationManager != null) { |
| 672 | final int numFullKeyboards = mTempFullKeyboards.size(); |
| 673 | boolean missingLayoutForExternalKeyboard = false; |
| 674 | boolean missingLayoutForExternalKeyboardAdded = false; |
| 675 | synchronized (mDataStore) { |
| 676 | for (int i = 0; i < numFullKeyboards; i++) { |
| 677 | final InputDevice inputDevice = mTempFullKeyboards.get(i); |
| 678 | if (mDataStore.getCurrentKeyboardLayout(inputDevice.getDescriptor()) == null) { |
| 679 | missingLayoutForExternalKeyboard = true; |
| 680 | if (i < numFullKeyboardsAdded) { |
| 681 | missingLayoutForExternalKeyboardAdded = true; |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | if (missingLayoutForExternalKeyboard) { |
| 687 | if (missingLayoutForExternalKeyboardAdded) { |
| 688 | showMissingKeyboardLayoutNotification(); |
| 689 | } |
| 690 | } else if (mKeyboardLayoutNotificationShown) { |
| 691 | hideMissingKeyboardLayoutNotification(); |
| 692 | } |
| 693 | } |
| 694 | mTempFullKeyboards.clear(); |
| 695 | } |
| 696 | |
| 697 | // Must be called on handler. |
| 698 | private void showMissingKeyboardLayoutNotification() { |
| 699 | if (!mKeyboardLayoutNotificationShown) { |
| 700 | if (mKeyboardLayoutIntent == null) { |
| 701 | final Intent intent = new Intent("android.settings.INPUT_METHOD_SETTINGS"); |
| 702 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 703 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 704 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 705 | mKeyboardLayoutIntent = PendingIntent.getActivityAsUser(mContext, 0, |
| 706 | intent, 0, null, UserHandle.CURRENT); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | Resources r = mContext.getResources(); |
| 710 | Notification notification = new Notification.Builder(mContext) |
| 711 | .setContentTitle(r.getString( |
| 712 | R.string.select_keyboard_layout_notification_title)) |
| 713 | .setContentText(r.getString( |
| 714 | R.string.select_keyboard_layout_notification_message)) |
| 715 | .setContentIntent(mKeyboardLayoutIntent) |
| 716 | .setSmallIcon(R.drawable.ic_settings_language) |
| 717 | .setPriority(Notification.PRIORITY_LOW) |
| 718 | .build(); |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 719 | mNotificationManager.notifyAsUser(null, |
| 720 | R.string.select_keyboard_layout_notification_title, |
| 721 | notification, UserHandle.ALL); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 722 | mKeyboardLayoutNotificationShown = true; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | // Must be called on handler. |
| 727 | private void hideMissingKeyboardLayoutNotification() { |
| 728 | if (mKeyboardLayoutNotificationShown) { |
| 729 | mKeyboardLayoutNotificationShown = false; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 730 | mNotificationManager.cancelAsUser(null, |
| 731 | R.string.select_keyboard_layout_notification_title, |
| 732 | UserHandle.ALL); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
| 736 | // Must be called on handler. |
| 737 | private void updateKeyboardLayouts() { |
| 738 | // Scan all input devices state for keyboard layouts that have been uninstalled. |
| 739 | final HashSet<String> availableKeyboardLayouts = new HashSet<String>(); |
| 740 | visitAllKeyboardLayouts(new KeyboardLayoutVisitor() { |
| 741 | @Override |
| 742 | public void visitKeyboardLayout(Resources resources, |
| 743 | String descriptor, String label, String collection, int keyboardLayoutResId) { |
| 744 | availableKeyboardLayouts.add(descriptor); |
| 745 | } |
| 746 | }); |
| 747 | synchronized (mDataStore) { |
| 748 | try { |
| 749 | mDataStore.removeUninstalledKeyboardLayouts(availableKeyboardLayouts); |
| 750 | } finally { |
| 751 | mDataStore.saveIfNeeded(); |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | // Reload keyboard layouts. |
| 756 | reloadKeyboardLayouts(); |
| 757 | } |
| 758 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 759 | private static boolean containsInputDeviceWithDescriptor(InputDevice[] inputDevices, |
| 760 | String descriptor) { |
| 761 | final int numDevices = inputDevices.length; |
| 762 | for (int i = 0; i < numDevices; i++) { |
| 763 | final InputDevice inputDevice = inputDevices[i]; |
| 764 | if (inputDevice.getDescriptor().equals(descriptor)) { |
| 765 | return true; |
| 766 | } |
| 767 | } |
| 768 | return false; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 769 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 770 | |
| 771 | @Override // Binder call |
| 772 | public KeyboardLayout[] getKeyboardLayouts() { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 773 | final ArrayList<KeyboardLayout> list = new ArrayList<KeyboardLayout>(); |
| 774 | visitAllKeyboardLayouts(new KeyboardLayoutVisitor() { |
| 775 | @Override |
| 776 | public void visitKeyboardLayout(Resources resources, |
Jeff Brown | d9fec5d | 2012-05-17 16:01:54 -0700 | [diff] [blame] | 777 | String descriptor, String label, String collection, int keyboardLayoutResId) { |
| 778 | list.add(new KeyboardLayout(descriptor, label, collection)); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 779 | } |
| 780 | }); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 781 | return list.toArray(new KeyboardLayout[list.size()]); |
| 782 | } |
| 783 | |
| 784 | @Override // Binder call |
| 785 | public KeyboardLayout getKeyboardLayout(String keyboardLayoutDescriptor) { |
| 786 | if (keyboardLayoutDescriptor == null) { |
| 787 | throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 788 | } |
| 789 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 790 | final KeyboardLayout[] result = new KeyboardLayout[1]; |
| 791 | visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() { |
| 792 | @Override |
| 793 | public void visitKeyboardLayout(Resources resources, |
Jeff Brown | d9fec5d | 2012-05-17 16:01:54 -0700 | [diff] [blame] | 794 | String descriptor, String label, String collection, int keyboardLayoutResId) { |
| 795 | result[0] = new KeyboardLayout(descriptor, label, collection); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 796 | } |
| 797 | }); |
| 798 | if (result[0] == null) { |
| 799 | Log.w(TAG, "Could not get keyboard layout with descriptor '" |
| 800 | + keyboardLayoutDescriptor + "'."); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 801 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 802 | return result[0]; |
| 803 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 804 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 805 | private void visitAllKeyboardLayouts(KeyboardLayoutVisitor visitor) { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 806 | final PackageManager pm = mContext.getPackageManager(); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 807 | Intent intent = new Intent(InputManager.ACTION_QUERY_KEYBOARD_LAYOUTS); |
| 808 | for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent, |
| 809 | PackageManager.GET_META_DATA)) { |
| 810 | visitKeyboardLayoutsInPackage(pm, resolveInfo.activityInfo, null, visitor); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 814 | private void visitKeyboardLayout(String keyboardLayoutDescriptor, |
| 815 | KeyboardLayoutVisitor visitor) { |
| 816 | KeyboardLayoutDescriptor d = KeyboardLayoutDescriptor.parse(keyboardLayoutDescriptor); |
| 817 | if (d != null) { |
| 818 | final PackageManager pm = mContext.getPackageManager(); |
| 819 | try { |
| 820 | ActivityInfo receiver = pm.getReceiverInfo( |
| 821 | new ComponentName(d.packageName, d.receiverName), |
| 822 | PackageManager.GET_META_DATA); |
| 823 | visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, visitor); |
| 824 | } catch (NameNotFoundException ex) { |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver, |
| 830 | String keyboardName, KeyboardLayoutVisitor visitor) { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 831 | Bundle metaData = receiver.metaData; |
| 832 | if (metaData == null) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 833 | return; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS); |
| 837 | if (configResId == 0) { |
| 838 | Log.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS |
| 839 | + "' on receiver " + receiver.packageName + "/" + receiver.name); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 840 | return; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Jeff Brown | d9fec5d | 2012-05-17 16:01:54 -0700 | [diff] [blame] | 843 | CharSequence receiverLabel = receiver.loadLabel(pm); |
| 844 | String collection = receiverLabel != null ? receiverLabel.toString() : ""; |
| 845 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 846 | try { |
| 847 | Resources resources = pm.getResourcesForApplication(receiver.applicationInfo); |
| 848 | XmlResourceParser parser = resources.getXml(configResId); |
| 849 | try { |
| 850 | XmlUtils.beginDocument(parser, "keyboard-layouts"); |
| 851 | |
| 852 | for (;;) { |
| 853 | XmlUtils.nextElement(parser); |
| 854 | String element = parser.getName(); |
| 855 | if (element == null) { |
| 856 | break; |
| 857 | } |
| 858 | if (element.equals("keyboard-layout")) { |
| 859 | TypedArray a = resources.obtainAttributes( |
| 860 | parser, com.android.internal.R.styleable.KeyboardLayout); |
| 861 | try { |
| 862 | String name = a.getString( |
| 863 | com.android.internal.R.styleable.KeyboardLayout_name); |
| 864 | String label = a.getString( |
| 865 | com.android.internal.R.styleable.KeyboardLayout_label); |
Jeff Brown | 2f09576 | 2012-05-10 21:29:33 -0700 | [diff] [blame] | 866 | int keyboardLayoutResId = a.getResourceId( |
| 867 | com.android.internal.R.styleable.KeyboardLayout_keyboardLayout, |
| 868 | 0); |
| 869 | if (name == null || label == null || keyboardLayoutResId == 0) { |
| 870 | Log.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' " |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 871 | + "attributes in keyboard layout " |
| 872 | + "resource from receiver " |
| 873 | + receiver.packageName + "/" + receiver.name); |
| 874 | } else { |
| 875 | String descriptor = KeyboardLayoutDescriptor.format( |
| 876 | receiver.packageName, receiver.name, name); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 877 | if (keyboardName == null || name.equals(keyboardName)) { |
| 878 | visitor.visitKeyboardLayout(resources, descriptor, |
Jeff Brown | d9fec5d | 2012-05-17 16:01:54 -0700 | [diff] [blame] | 879 | label, collection, keyboardLayoutResId); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | } finally { |
| 883 | a.recycle(); |
| 884 | } |
| 885 | } else { |
| 886 | Log.w(TAG, "Skipping unrecognized element '" + element |
| 887 | + "' in keyboard layout resource from receiver " |
| 888 | + receiver.packageName + "/" + receiver.name); |
| 889 | } |
| 890 | } |
| 891 | } finally { |
| 892 | parser.close(); |
| 893 | } |
| 894 | } catch (Exception ex) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 895 | Log.w(TAG, "Could not parse keyboard layout resource from receiver " |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 896 | + receiver.packageName + "/" + receiver.name, ex); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 897 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | @Override // Binder call |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 901 | public String getCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor) { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 902 | if (inputDeviceDescriptor == null) { |
| 903 | throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
| 904 | } |
| 905 | |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 906 | synchronized (mDataStore) { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 907 | return mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor); |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 908 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | @Override // Binder call |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 912 | public void setCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor, |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 913 | String keyboardLayoutDescriptor) { |
| 914 | if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT, |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 915 | "setCurrentKeyboardLayoutForInputDevice()")) { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 916 | throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission"); |
| 917 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 918 | if (inputDeviceDescriptor == null) { |
| 919 | throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
| 920 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 921 | if (keyboardLayoutDescriptor == null) { |
| 922 | throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 923 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 924 | |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 925 | synchronized (mDataStore) { |
| 926 | try { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 927 | if (mDataStore.setCurrentKeyboardLayout( |
| 928 | inputDeviceDescriptor, keyboardLayoutDescriptor)) { |
| 929 | mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS); |
| 930 | } |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 931 | } finally { |
| 932 | mDataStore.saveIfNeeded(); |
| 933 | } |
| 934 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 935 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 936 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 937 | @Override // Binder call |
| 938 | public String[] getKeyboardLayoutsForInputDevice(String inputDeviceDescriptor) { |
| 939 | if (inputDeviceDescriptor == null) { |
| 940 | throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
| 941 | } |
| 942 | |
| 943 | synchronized (mDataStore) { |
| 944 | return mDataStore.getKeyboardLayouts(inputDeviceDescriptor); |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | @Override // Binder call |
| 949 | public void addKeyboardLayoutForInputDevice(String inputDeviceDescriptor, |
| 950 | String keyboardLayoutDescriptor) { |
| 951 | if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT, |
| 952 | "addKeyboardLayoutForInputDevice()")) { |
| 953 | throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission"); |
| 954 | } |
| 955 | if (inputDeviceDescriptor == null) { |
| 956 | throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
| 957 | } |
| 958 | if (keyboardLayoutDescriptor == null) { |
| 959 | throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 960 | } |
| 961 | |
| 962 | synchronized (mDataStore) { |
| 963 | try { |
| 964 | String oldLayout = mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor); |
| 965 | if (mDataStore.addKeyboardLayout(inputDeviceDescriptor, keyboardLayoutDescriptor) |
| 966 | && !Objects.equal(oldLayout, |
| 967 | mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor))) { |
| 968 | mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS); |
| 969 | } |
| 970 | } finally { |
| 971 | mDataStore.saveIfNeeded(); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 972 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
| 976 | @Override // Binder call |
| 977 | public void removeKeyboardLayoutForInputDevice(String inputDeviceDescriptor, |
| 978 | String keyboardLayoutDescriptor) { |
| 979 | if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT, |
| 980 | "removeKeyboardLayoutForInputDevice()")) { |
| 981 | throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission"); |
| 982 | } |
| 983 | if (inputDeviceDescriptor == null) { |
| 984 | throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
| 985 | } |
| 986 | if (keyboardLayoutDescriptor == null) { |
| 987 | throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 988 | } |
| 989 | |
| 990 | synchronized (mDataStore) { |
| 991 | try { |
| 992 | String oldLayout = mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor); |
| 993 | if (mDataStore.removeKeyboardLayout(inputDeviceDescriptor, |
| 994 | keyboardLayoutDescriptor) |
| 995 | && !Objects.equal(oldLayout, |
| 996 | mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor))) { |
| 997 | mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS); |
| 998 | } |
| 999 | } finally { |
| 1000 | mDataStore.saveIfNeeded(); |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | public void switchKeyboardLayout(int deviceId, int direction) { |
| 1006 | mHandler.obtainMessage(MSG_SWITCH_KEYBOARD_LAYOUT, deviceId, direction).sendToTarget(); |
| 1007 | } |
| 1008 | |
| 1009 | // Must be called on handler. |
| 1010 | private void handleSwitchKeyboardLayout(int deviceId, int direction) { |
| 1011 | final InputDevice device = getInputDevice(deviceId); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1012 | if (device != null) { |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1013 | final String inputDeviceDescriptor = device.getDescriptor(); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1014 | final boolean changed; |
| 1015 | final String keyboardLayoutDescriptor; |
| 1016 | synchronized (mDataStore) { |
| 1017 | try { |
| 1018 | changed = mDataStore.switchKeyboardLayout(inputDeviceDescriptor, direction); |
| 1019 | keyboardLayoutDescriptor = mDataStore.getCurrentKeyboardLayout( |
| 1020 | inputDeviceDescriptor); |
| 1021 | } finally { |
| 1022 | mDataStore.saveIfNeeded(); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | if (changed) { |
| 1027 | if (mSwitchedKeyboardLayoutToast != null) { |
| 1028 | mSwitchedKeyboardLayoutToast.cancel(); |
| 1029 | mSwitchedKeyboardLayoutToast = null; |
| 1030 | } |
| 1031 | if (keyboardLayoutDescriptor != null) { |
| 1032 | KeyboardLayout keyboardLayout = getKeyboardLayout(keyboardLayoutDescriptor); |
| 1033 | if (keyboardLayout != null) { |
| 1034 | mSwitchedKeyboardLayoutToast = Toast.makeText( |
| 1035 | mContext, keyboardLayout.getLabel(), Toast.LENGTH_SHORT); |
| 1036 | mSwitchedKeyboardLayoutToast.show(); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | reloadKeyboardLayouts(); |
| 1041 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1042 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1045 | public void setInputWindows(InputWindowHandle[] windowHandles) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1046 | nativeSetInputWindows(mPtr, windowHandles); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1049 | public void setFocusedApplication(InputApplicationHandle application) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1050 | nativeSetFocusedApplication(mPtr, application); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1053 | public void setInputDispatchMode(boolean enabled, boolean frozen) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1054 | nativeSetInputDispatchMode(mPtr, enabled, frozen); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1055 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 1056 | |
| 1057 | public void setSystemUiVisibility(int visibility) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1058 | nativeSetSystemUiVisibility(mPtr, visibility); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 1059 | } |
| 1060 | |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1061 | /** |
| 1062 | * Atomically transfers touch focus from one window to another as identified by |
| 1063 | * their input channels. It is possible for multiple windows to have |
| 1064 | * touch focus if they support split touch dispatch |
| 1065 | * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this |
| 1066 | * method only transfers touch focus of the specified window without affecting |
| 1067 | * other windows that may also have touch focus at the same time. |
| 1068 | * @param fromChannel The channel of a window that currently has touch focus. |
| 1069 | * @param toChannel The channel of the window that should receive touch focus in |
| 1070 | * place of the first. |
| 1071 | * @return True if the transfer was successful. False if the window with the |
| 1072 | * specified channel did not actually have touch focus at the time of the request. |
| 1073 | */ |
| 1074 | public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) { |
| 1075 | if (fromChannel == null) { |
| 1076 | throw new IllegalArgumentException("fromChannel must not be null."); |
| 1077 | } |
| 1078 | if (toChannel == null) { |
| 1079 | throw new IllegalArgumentException("toChannel must not be null."); |
| 1080 | } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1081 | return nativeTransferTouchFocus(mPtr, fromChannel, toChannel); |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1082 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 1083 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1084 | @Override // Binder call |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1085 | public void tryPointerSpeed(int speed) { |
| 1086 | if (!checkCallingPermission(android.Manifest.permission.SET_POINTER_SPEED, |
| 1087 | "tryPointerSpeed()")) { |
| 1088 | throw new SecurityException("Requires SET_POINTER_SPEED permission"); |
| 1089 | } |
| 1090 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1091 | if (speed < InputManager.MIN_POINTER_SPEED || speed > InputManager.MAX_POINTER_SPEED) { |
| 1092 | throw new IllegalArgumentException("speed out of range"); |
| 1093 | } |
| 1094 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1095 | setPointerSpeedUnchecked(speed); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | public void updatePointerSpeedFromSettings() { |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1099 | int speed = getPointerSpeedSetting(); |
| 1100 | setPointerSpeedUnchecked(speed); |
| 1101 | } |
| 1102 | |
| 1103 | private void setPointerSpeedUnchecked(int speed) { |
| 1104 | speed = Math.min(Math.max(speed, InputManager.MIN_POINTER_SPEED), |
| 1105 | InputManager.MAX_POINTER_SPEED); |
| 1106 | nativeSetPointerSpeed(mPtr, speed); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | private void registerPointerSpeedSettingObserver() { |
| 1110 | mContext.getContentResolver().registerContentObserver( |
| 1111 | Settings.System.getUriFor(Settings.System.POINTER_SPEED), true, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1112 | new ContentObserver(mHandler) { |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1113 | @Override |
| 1114 | public void onChange(boolean selfChange) { |
| 1115 | updatePointerSpeedFromSettings(); |
| 1116 | } |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 1117 | }, UserHandle.USER_ALL); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1120 | private int getPointerSpeedSetting() { |
| 1121 | int speed = InputManager.DEFAULT_POINTER_SPEED; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1122 | try { |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 1123 | speed = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 1124 | Settings.System.POINTER_SPEED, UserHandle.USER_CURRENT); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1125 | } catch (SettingNotFoundException snfe) { |
| 1126 | } |
| 1127 | return speed; |
| 1128 | } |
| 1129 | |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1130 | public void updateShowTouchesFromSettings() { |
| 1131 | int setting = getShowTouchesSetting(0); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1132 | nativeSetShowTouches(mPtr, setting != 0); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | private void registerShowTouchesSettingObserver() { |
| 1136 | mContext.getContentResolver().registerContentObserver( |
| 1137 | Settings.System.getUriFor(Settings.System.SHOW_TOUCHES), true, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1138 | new ContentObserver(mHandler) { |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1139 | @Override |
| 1140 | public void onChange(boolean selfChange) { |
| 1141 | updateShowTouchesFromSettings(); |
| 1142 | } |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 1143 | }, UserHandle.USER_ALL); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | private int getShowTouchesSetting(int defaultValue) { |
| 1147 | int result = defaultValue; |
| 1148 | try { |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 1149 | result = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 1150 | Settings.System.SHOW_TOUCHES, UserHandle.USER_CURRENT); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1151 | } catch (SettingNotFoundException snfe) { |
| 1152 | } |
| 1153 | return result; |
| 1154 | } |
| 1155 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1156 | // Binder call |
| 1157 | @Override |
| 1158 | public void vibrate(int deviceId, long[] pattern, int repeat, IBinder token) { |
| 1159 | if (repeat >= pattern.length) { |
| 1160 | throw new ArrayIndexOutOfBoundsException(); |
| 1161 | } |
| 1162 | |
| 1163 | VibratorToken v; |
| 1164 | synchronized (mVibratorLock) { |
| 1165 | v = mVibratorTokens.get(token); |
| 1166 | if (v == null) { |
| 1167 | v = new VibratorToken(deviceId, token, mNextVibratorTokenValue++); |
| 1168 | try { |
| 1169 | token.linkToDeath(v, 0); |
| 1170 | } catch (RemoteException ex) { |
| 1171 | // give up |
| 1172 | throw new RuntimeException(ex); |
| 1173 | } |
| 1174 | mVibratorTokens.put(token, v); |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | synchronized (v) { |
| 1179 | v.mVibrating = true; |
| 1180 | nativeVibrate(mPtr, deviceId, pattern, repeat, v.mTokenValue); |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | // Binder call |
| 1185 | @Override |
| 1186 | public void cancelVibrate(int deviceId, IBinder token) { |
| 1187 | VibratorToken v; |
| 1188 | synchronized (mVibratorLock) { |
| 1189 | v = mVibratorTokens.get(token); |
| 1190 | if (v == null || v.mDeviceId != deviceId) { |
| 1191 | return; // nothing to cancel |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | cancelVibrateIfNeeded(v); |
| 1196 | } |
| 1197 | |
| 1198 | void onVibratorTokenDied(VibratorToken v) { |
| 1199 | synchronized (mVibratorLock) { |
| 1200 | mVibratorTokens.remove(v.mToken); |
| 1201 | } |
| 1202 | |
| 1203 | cancelVibrateIfNeeded(v); |
| 1204 | } |
| 1205 | |
| 1206 | private void cancelVibrateIfNeeded(VibratorToken v) { |
| 1207 | synchronized (v) { |
| 1208 | if (v.mVibrating) { |
| 1209 | nativeCancelVibrate(mPtr, v.mDeviceId, v.mTokenValue); |
| 1210 | v.mVibrating = false; |
| 1211 | } |
| 1212 | } |
| 1213 | } |
| 1214 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1215 | @Override |
| 1216 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 1217 | if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP) |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1218 | != PackageManager.PERMISSION_GRANTED) { |
| 1219 | pw.println("Permission Denial: can't dump InputManager from from pid=" |
| 1220 | + Binder.getCallingPid() |
| 1221 | + ", uid=" + Binder.getCallingUid()); |
| 1222 | return; |
| 1223 | } |
| 1224 | |
| 1225 | pw.println("INPUT MANAGER (dumpsys input)\n"); |
| 1226 | String dumpStr = nativeDump(mPtr); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1227 | if (dumpStr != null) { |
| 1228 | pw.println(dumpStr); |
| 1229 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1230 | } |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1231 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1232 | private boolean checkCallingPermission(String permission, String func) { |
| 1233 | // Quick check: if the calling permission is me, it's all okay. |
| 1234 | if (Binder.getCallingPid() == Process.myPid()) { |
| 1235 | return true; |
| 1236 | } |
| 1237 | |
| 1238 | if (mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED) { |
| 1239 | return true; |
| 1240 | } |
| 1241 | String msg = "Permission Denial: " + func + " from pid=" |
| 1242 | + Binder.getCallingPid() |
| 1243 | + ", uid=" + Binder.getCallingUid() |
| 1244 | + " requires " + permission; |
| 1245 | Slog.w(TAG, msg); |
| 1246 | return false; |
| 1247 | } |
| 1248 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1249 | // Called by the heartbeat to ensure locks are not held indefinitely (for deadlock detection). |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1250 | @Override |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 1251 | public void monitor() { |
| 1252 | synchronized (mInputFilterLock) { } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1253 | nativeMonitor(mPtr); |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1256 | // Native callback. |
| 1257 | private void notifyConfigurationChanged(long whenNanos) { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1258 | mWindowManagerCallbacks.notifyConfigurationChanged(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | // Native callback. |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1262 | private void notifyInputDevicesChanged(InputDevice[] inputDevices) { |
| 1263 | synchronized (mInputDevicesLock) { |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1264 | if (!mInputDevicesChangedPending) { |
| 1265 | mInputDevicesChangedPending = true; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1266 | mHandler.obtainMessage(MSG_DELIVER_INPUT_DEVICES_CHANGED, |
| 1267 | mInputDevices).sendToTarget(); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1268 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1269 | |
| 1270 | mInputDevices = inputDevices; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | // Native callback. |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 1275 | private void notifySwitch(long whenNanos, int switchValues, int switchMask) { |
| 1276 | if (DEBUG) { |
| 1277 | Slog.d(TAG, "notifySwitch: values=" + Integer.toHexString(switchValues) |
| 1278 | + ", mask=" + Integer.toHexString(switchMask)); |
| 1279 | } |
| 1280 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1281 | if ((switchMask & SW_LID_BIT) != 0) { |
| 1282 | final boolean lidOpen = ((switchValues & SW_LID_BIT) == 0); |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 1283 | mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, lidOpen); |
Jeff Brown | 5338428 | 2012-08-20 20:16:01 -0700 | [diff] [blame] | 1284 | } |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1285 | |
| 1286 | if (mUseDevInputEventForAudioJack && (switchMask & SW_JACK_BITS) != 0) { |
| 1287 | mWiredAccessoryCallbacks.notifyWiredAccessoryChanged(whenNanos, switchValues, |
| 1288 | switchMask); |
| 1289 | } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | // Native callback. |
| 1293 | private void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1294 | mWindowManagerCallbacks.notifyInputChannelBroken(inputWindowHandle); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | // Native callback. |
| 1298 | private long notifyANR(InputApplicationHandle inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 1299 | InputWindowHandle inputWindowHandle, String reason) { |
| 1300 | return mWindowManagerCallbacks.notifyANR( |
| 1301 | inputApplicationHandle, inputWindowHandle, reason); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | // Native callback. |
| 1305 | final boolean filterInputEvent(InputEvent event, int policyFlags) { |
| 1306 | synchronized (mInputFilterLock) { |
| 1307 | if (mInputFilter != null) { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 1308 | try { |
| 1309 | mInputFilter.filterInputEvent(event, policyFlags); |
| 1310 | } catch (RemoteException e) { |
| 1311 | /* ignore */ |
| 1312 | } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1313 | return false; |
| 1314 | } |
| 1315 | } |
| 1316 | event.recycle(); |
| 1317 | return true; |
| 1318 | } |
| 1319 | |
| 1320 | // Native callback. |
| 1321 | private int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1322 | return mWindowManagerCallbacks.interceptKeyBeforeQueueing( |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1323 | event, policyFlags, isScreenOn); |
| 1324 | } |
| 1325 | |
| 1326 | // Native callback. |
| 1327 | private int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1328 | return mWindowManagerCallbacks.interceptMotionBeforeQueueingWhenScreenOff(policyFlags); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | // Native callback. |
| 1332 | private long interceptKeyBeforeDispatching(InputWindowHandle focus, |
| 1333 | KeyEvent event, int policyFlags) { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1334 | return mWindowManagerCallbacks.interceptKeyBeforeDispatching(focus, event, policyFlags); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | // Native callback. |
| 1338 | private KeyEvent dispatchUnhandledKey(InputWindowHandle focus, |
| 1339 | KeyEvent event, int policyFlags) { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1340 | return mWindowManagerCallbacks.dispatchUnhandledKey(focus, event, policyFlags); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | // Native callback. |
| 1344 | private boolean checkInjectEventsPermission(int injectorPid, int injectorUid) { |
| 1345 | return mContext.checkPermission(android.Manifest.permission.INJECT_EVENTS, |
| 1346 | injectorPid, injectorUid) == PackageManager.PERMISSION_GRANTED; |
| 1347 | } |
| 1348 | |
| 1349 | // Native callback. |
| 1350 | private int getVirtualKeyQuietTimeMillis() { |
| 1351 | return mContext.getResources().getInteger( |
| 1352 | com.android.internal.R.integer.config_virtualKeyQuietTimeMillis); |
| 1353 | } |
| 1354 | |
| 1355 | // Native callback. |
| 1356 | private String[] getExcludedDeviceNames() { |
| 1357 | ArrayList<String> names = new ArrayList<String>(); |
| 1358 | |
| 1359 | // Read partner-provided list of excluded input devices |
| 1360 | XmlPullParser parser = null; |
| 1361 | // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system". |
| 1362 | File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH); |
| 1363 | FileReader confreader = null; |
| 1364 | try { |
| 1365 | confreader = new FileReader(confFile); |
| 1366 | parser = Xml.newPullParser(); |
| 1367 | parser.setInput(confreader); |
| 1368 | XmlUtils.beginDocument(parser, "devices"); |
| 1369 | |
| 1370 | while (true) { |
| 1371 | XmlUtils.nextElement(parser); |
| 1372 | if (!"device".equals(parser.getName())) { |
| 1373 | break; |
| 1374 | } |
| 1375 | String name = parser.getAttributeValue(null, "name"); |
| 1376 | if (name != null) { |
| 1377 | names.add(name); |
| 1378 | } |
| 1379 | } |
| 1380 | } catch (FileNotFoundException e) { |
| 1381 | // It's ok if the file does not exist. |
| 1382 | } catch (Exception e) { |
| 1383 | Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e); |
| 1384 | } finally { |
| 1385 | try { if (confreader != null) confreader.close(); } catch (IOException e) { } |
| 1386 | } |
| 1387 | |
| 1388 | return names.toArray(new String[names.size()]); |
| 1389 | } |
| 1390 | |
| 1391 | // Native callback. |
| 1392 | private int getKeyRepeatTimeout() { |
| 1393 | return ViewConfiguration.getKeyRepeatTimeout(); |
| 1394 | } |
| 1395 | |
| 1396 | // Native callback. |
| 1397 | private int getKeyRepeatDelay() { |
| 1398 | return ViewConfiguration.getKeyRepeatDelay(); |
| 1399 | } |
| 1400 | |
| 1401 | // Native callback. |
| 1402 | private int getHoverTapTimeout() { |
| 1403 | return ViewConfiguration.getHoverTapTimeout(); |
| 1404 | } |
| 1405 | |
| 1406 | // Native callback. |
| 1407 | private int getHoverTapSlop() { |
| 1408 | return ViewConfiguration.getHoverTapSlop(); |
| 1409 | } |
| 1410 | |
| 1411 | // Native callback. |
| 1412 | private int getDoubleTapTimeout() { |
| 1413 | return ViewConfiguration.getDoubleTapTimeout(); |
| 1414 | } |
| 1415 | |
| 1416 | // Native callback. |
| 1417 | private int getLongPressTimeout() { |
| 1418 | return ViewConfiguration.getLongPressTimeout(); |
| 1419 | } |
| 1420 | |
| 1421 | // Native callback. |
| 1422 | private int getPointerLayer() { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1423 | return mWindowManagerCallbacks.getPointerLayer(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | // Native callback. |
| 1427 | private PointerIcon getPointerIcon() { |
| 1428 | return PointerIcon.getDefaultIcon(mContext); |
| 1429 | } |
| 1430 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1431 | // Native callback. |
| 1432 | private String[] getKeyboardLayoutOverlay(String inputDeviceDescriptor) { |
| 1433 | if (!mSystemReady) { |
| 1434 | return null; |
| 1435 | } |
| 1436 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1437 | String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice( |
| 1438 | inputDeviceDescriptor); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1439 | if (keyboardLayoutDescriptor == null) { |
| 1440 | return null; |
| 1441 | } |
| 1442 | |
| 1443 | final String[] result = new String[2]; |
| 1444 | visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() { |
| 1445 | @Override |
| 1446 | public void visitKeyboardLayout(Resources resources, |
Jeff Brown | d9fec5d | 2012-05-17 16:01:54 -0700 | [diff] [blame] | 1447 | String descriptor, String label, String collection, int keyboardLayoutResId) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1448 | try { |
| 1449 | result[0] = descriptor; |
| 1450 | result[1] = Streams.readFully(new InputStreamReader( |
Jeff Brown | 2f09576 | 2012-05-10 21:29:33 -0700 | [diff] [blame] | 1451 | resources.openRawResource(keyboardLayoutResId))); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1452 | } catch (IOException ex) { |
| 1453 | } catch (NotFoundException ex) { |
| 1454 | } |
| 1455 | } |
| 1456 | }); |
| 1457 | if (result[0] == null) { |
| 1458 | Log.w(TAG, "Could not get keyboard layout with descriptor '" |
| 1459 | + keyboardLayoutDescriptor + "'."); |
| 1460 | return null; |
| 1461 | } |
| 1462 | return result; |
| 1463 | } |
| 1464 | |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1465 | // Native callback. |
| 1466 | private String getDeviceAlias(String uniqueId) { |
Matthew Xie | 9631314 | 2012-06-29 16:57:31 -0700 | [diff] [blame] | 1467 | if (BluetoothAdapter.checkBluetoothAddress(uniqueId)) { |
| 1468 | // TODO(BT) mBluetoothService.getRemoteAlias(uniqueId) |
| 1469 | return null; |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1470 | } |
| 1471 | return null; |
| 1472 | } |
| 1473 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1474 | /** |
| 1475 | * Callback interface implemented by the Window Manager. |
| 1476 | */ |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1477 | public interface WindowManagerCallbacks { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1478 | public void notifyConfigurationChanged(); |
| 1479 | |
| 1480 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen); |
| 1481 | |
| 1482 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle); |
| 1483 | |
| 1484 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 1485 | InputWindowHandle inputWindowHandle, String reason); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1486 | |
| 1487 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn); |
| 1488 | |
| 1489 | public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags); |
| 1490 | |
| 1491 | public long interceptKeyBeforeDispatching(InputWindowHandle focus, |
| 1492 | KeyEvent event, int policyFlags); |
| 1493 | |
| 1494 | public KeyEvent dispatchUnhandledKey(InputWindowHandle focus, |
| 1495 | KeyEvent event, int policyFlags); |
| 1496 | |
| 1497 | public int getPointerLayer(); |
| 1498 | } |
| 1499 | |
| 1500 | /** |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1501 | * Callback interface implemented by WiredAccessoryObserver. |
| 1502 | */ |
| 1503 | public interface WiredAccessoryCallbacks { |
| 1504 | public void notifyWiredAccessoryChanged(long whenNanos, int switchValues, int switchMask); |
| 1505 | } |
| 1506 | |
| 1507 | /** |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1508 | * Private handler for the input manager. |
| 1509 | */ |
| 1510 | private final class InputManagerHandler extends Handler { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1511 | public InputManagerHandler(Looper looper) { |
| 1512 | super(looper, null, true /*async*/); |
Jeff Brown | a2910d0 | 2012-08-25 12:29:46 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1515 | @Override |
| 1516 | public void handleMessage(Message msg) { |
| 1517 | switch (msg.what) { |
| 1518 | case MSG_DELIVER_INPUT_DEVICES_CHANGED: |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1519 | deliverInputDevicesChanged((InputDevice[])msg.obj); |
| 1520 | break; |
| 1521 | case MSG_SWITCH_KEYBOARD_LAYOUT: |
| 1522 | handleSwitchKeyboardLayout(msg.arg1, msg.arg2); |
| 1523 | break; |
| 1524 | case MSG_RELOAD_KEYBOARD_LAYOUTS: |
| 1525 | reloadKeyboardLayouts(); |
| 1526 | break; |
| 1527 | case MSG_UPDATE_KEYBOARD_LAYOUTS: |
| 1528 | updateKeyboardLayouts(); |
| 1529 | break; |
| 1530 | case MSG_RELOAD_DEVICE_ALIASES: |
| 1531 | reloadDeviceAliases(); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1532 | break; |
| 1533 | } |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | /** |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1538 | * Hosting interface for input filters to call back into the input manager. |
| 1539 | */ |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 1540 | private final class InputFilterHost extends IInputFilterHost.Stub { |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1541 | private boolean mDisconnected; |
| 1542 | |
| 1543 | public void disconnectLocked() { |
| 1544 | mDisconnected = true; |
| 1545 | } |
| 1546 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1547 | @Override |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1548 | public void sendInputEvent(InputEvent event, int policyFlags) { |
| 1549 | if (event == null) { |
| 1550 | throw new IllegalArgumentException("event must not be null"); |
| 1551 | } |
| 1552 | |
| 1553 | synchronized (mInputFilterLock) { |
| 1554 | if (!mDisconnected) { |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1555 | nativeInjectInputEvent(mPtr, event, 0, 0, |
| 1556 | InputManager.INJECT_INPUT_EVENT_MODE_ASYNC, 0, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1557 | policyFlags | WindowManagerPolicy.FLAG_FILTERED); |
| 1558 | } |
| 1559 | } |
| 1560 | } |
| 1561 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1562 | |
| 1563 | private static final class KeyboardLayoutDescriptor { |
| 1564 | public String packageName; |
| 1565 | public String receiverName; |
| 1566 | public String keyboardLayoutName; |
| 1567 | |
| 1568 | public static String format(String packageName, |
| 1569 | String receiverName, String keyboardName) { |
| 1570 | return packageName + "/" + receiverName + "/" + keyboardName; |
| 1571 | } |
| 1572 | |
| 1573 | public static KeyboardLayoutDescriptor parse(String descriptor) { |
| 1574 | int pos = descriptor.indexOf('/'); |
| 1575 | if (pos < 0 || pos + 1 == descriptor.length()) { |
| 1576 | return null; |
| 1577 | } |
| 1578 | int pos2 = descriptor.indexOf('/', pos + 1); |
| 1579 | if (pos2 < pos + 2 || pos2 + 1 == descriptor.length()) { |
| 1580 | return null; |
| 1581 | } |
| 1582 | |
| 1583 | KeyboardLayoutDescriptor result = new KeyboardLayoutDescriptor(); |
| 1584 | result.packageName = descriptor.substring(0, pos); |
| 1585 | result.receiverName = descriptor.substring(pos + 1, pos2); |
| 1586 | result.keyboardLayoutName = descriptor.substring(pos2 + 1); |
| 1587 | return result; |
| 1588 | } |
| 1589 | } |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1590 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1591 | private interface KeyboardLayoutVisitor { |
| 1592 | void visitKeyboardLayout(Resources resources, |
Jeff Brown | d9fec5d | 2012-05-17 16:01:54 -0700 | [diff] [blame] | 1593 | String descriptor, String label, String collection, int keyboardLayoutResId); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1596 | private final class InputDevicesChangedListenerRecord implements DeathRecipient { |
| 1597 | private final int mPid; |
| 1598 | private final IInputDevicesChangedListener mListener; |
| 1599 | |
| 1600 | public InputDevicesChangedListenerRecord(int pid, IInputDevicesChangedListener listener) { |
| 1601 | mPid = pid; |
| 1602 | mListener = listener; |
| 1603 | } |
| 1604 | |
| 1605 | @Override |
| 1606 | public void binderDied() { |
| 1607 | if (DEBUG) { |
| 1608 | Slog.d(TAG, "Input devices changed listener for pid " + mPid + " died."); |
| 1609 | } |
| 1610 | onInputDevicesChangedListenerDied(mPid); |
| 1611 | } |
| 1612 | |
| 1613 | public void notifyInputDevicesChanged(int[] info) { |
| 1614 | try { |
| 1615 | mListener.onInputDevicesChanged(info); |
| 1616 | } catch (RemoteException ex) { |
| 1617 | Slog.w(TAG, "Failed to notify process " |
| 1618 | + mPid + " that input devices changed, assuming it died.", ex); |
| 1619 | binderDied(); |
| 1620 | } |
| 1621 | } |
| 1622 | } |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1623 | |
| 1624 | private final class VibratorToken implements DeathRecipient { |
| 1625 | public final int mDeviceId; |
| 1626 | public final IBinder mToken; |
| 1627 | public final int mTokenValue; |
| 1628 | |
| 1629 | public boolean mVibrating; |
| 1630 | |
| 1631 | public VibratorToken(int deviceId, IBinder token, int tokenValue) { |
| 1632 | mDeviceId = deviceId; |
| 1633 | mToken = token; |
| 1634 | mTokenValue = tokenValue; |
| 1635 | } |
| 1636 | |
| 1637 | @Override |
| 1638 | public void binderDied() { |
| 1639 | if (DEBUG) { |
| 1640 | Slog.d(TAG, "Vibrator token died."); |
| 1641 | } |
| 1642 | onVibratorTokenDied(this); |
| 1643 | } |
| 1644 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1645 | |
| 1646 | private final class LocalService extends InputManagerInternal { |
| 1647 | @Override |
| 1648 | public void setDisplayViewports( |
| 1649 | DisplayViewport defaultViewport, DisplayViewport externalTouchViewport) { |
| 1650 | setDisplayViewportsInternal(defaultViewport, externalTouchViewport); |
| 1651 | } |
| 1652 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1653 | } |