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