summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorRoboErik <epastern@google.com>2014-01-08 22:07:14 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-01-08 22:07:14 +0000
commit2dfae9bea104c0594fd5641f9704f34b204abd87 (patch)
treed46a6a7cee4aa886cedd5efefbc99401150478ae /services
parentfd3c089b1a153875d06cc46a68105e47ad390e59 (diff)
parentfb290df3c9a6f37ec050163029e25844de2f8590 (diff)
downloadframeworks_base-2dfae9bea104c0594fd5641f9704f34b204abd87.zip
frameworks_base-2dfae9bea104c0594fd5641f9704f34b204abd87.tar.gz
frameworks_base-2dfae9bea104c0594fd5641f9704f34b204abd87.tar.bz2
Merge "b/12068020 Make kb layouts only unique to vendor/product"
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/input/InputManagerService.java132
-rw-r--r--services/core/jni/com_android_server_input_InputManagerService.cpp27
2 files changed, 106 insertions, 53 deletions
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index 9178664..825a31d 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -46,6 +46,7 @@ import android.content.res.XmlResourceParser;
import android.database.ContentObserver;
import android.hardware.input.IInputDevicesChangedListener;
import android.hardware.input.IInputManager;
+import android.hardware.input.InputDeviceIdentifier;
import android.hardware.input.InputManager;
import android.hardware.input.KeyboardLayout;
import android.os.Binder;
@@ -378,7 +379,7 @@ public class InputManagerService extends IInputManager.Stub
public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
return nativeGetScanCodeState(mPtr, deviceId, sourceMask, scanCode);
}
-
+
/**
* Gets the current state of a switch by switch code.
* @param deviceId The input device id, or -1 to consult all devices.
@@ -413,10 +414,10 @@ public class InputManagerService extends IInputManager.Stub
throw new IllegalArgumentException("keyExists must not be null and must be at "
+ "least as large as keyCodes.");
}
-
+
return nativeHasKeys(mPtr, deviceId, sourceMask, keyCodes, keyExists);
}
-
+
/**
* Creates an input channel that will receive all input from the input dispatcher.
* @param inputChannelName The input channel name.
@@ -426,7 +427,7 @@ public class InputManagerService extends IInputManager.Stub
if (inputChannelName == null) {
throw new IllegalArgumentException("inputChannelName must not be null.");
}
-
+
InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
nativeRegisterInputChannel(mPtr, inputChannels[0], null, true);
inputChannels[0].dispose(); // don't need to retain the Java object reference
@@ -444,10 +445,10 @@ public class InputManagerService extends IInputManager.Stub
if (inputChannel == null) {
throw new IllegalArgumentException("inputChannel must not be null.");
}
-
+
nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, false);
}
-
+
/**
* Unregisters an input channel.
* @param inputChannel The input channel to unregister.
@@ -456,7 +457,7 @@ public class InputManagerService extends IInputManager.Stub
if (inputChannel == null) {
throw new IllegalArgumentException("inputChannel must not be null.");
}
-
+
nativeUnregisterInputChannel(mPtr, inputChannel);
}
@@ -894,35 +895,62 @@ public class InputManagerService extends IInputManager.Stub
}
}
- @Override // Binder call
- public String getCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor) {
- if (inputDeviceDescriptor == null) {
- throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
+ /**
+ * Builds a layout descriptor for the vendor/product. This returns the
+ * descriptor for ids that aren't useful (such as the default 0, 0).
+ */
+ private String getLayoutDescriptor(InputDeviceIdentifier identifier) {
+ if (identifier == null || identifier.getDescriptor() == null) {
+ throw new IllegalArgumentException("identifier and descriptor must not be null");
+ }
+
+ if (identifier.getVendorId() == 0 && identifier.getProductId() == 0) {
+ return identifier.getDescriptor();
}
+ StringBuilder bob = new StringBuilder();
+ bob.append("vendor:").append(identifier.getVendorId());
+ bob.append(",product:").append(identifier.getProductId());
+ return bob.toString();
+ }
+
+ @Override // Binder call
+ public String getCurrentKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier) {
+ String key = getLayoutDescriptor(identifier);
synchronized (mDataStore) {
- return mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor);
+ String layout = null;
+ // try loading it using the layout descriptor if we have it
+ layout = mDataStore.getCurrentKeyboardLayout(key);
+ if (layout == null && !key.equals(identifier.getDescriptor())) {
+ // if it doesn't exist fall back to the device descriptor
+ layout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor());
+ }
+ if (DEBUG) {
+ Slog.d(TAG, "Loaded keyboard layout id for " + key + " and got "
+ + layout);
+ }
+ return layout;
}
}
@Override // Binder call
- public void setCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
+ public void setCurrentKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
String keyboardLayoutDescriptor) {
if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
"setCurrentKeyboardLayoutForInputDevice()")) {
throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
}
- if (inputDeviceDescriptor == null) {
- throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
- }
if (keyboardLayoutDescriptor == null) {
throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
}
+ String key = getLayoutDescriptor(identifier);
synchronized (mDataStore) {
try {
- if (mDataStore.setCurrentKeyboardLayout(
- inputDeviceDescriptor, keyboardLayoutDescriptor)) {
+ if (mDataStore.setCurrentKeyboardLayout(key, keyboardLayoutDescriptor)) {
+ if (DEBUG) {
+ Slog.d(TAG, "Saved keyboard layout using " + key);
+ }
mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
}
} finally {
@@ -932,36 +960,39 @@ public class InputManagerService extends IInputManager.Stub
}
@Override // Binder call
- public String[] getKeyboardLayoutsForInputDevice(String inputDeviceDescriptor) {
- if (inputDeviceDescriptor == null) {
- throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
- }
-
+ public String[] getKeyboardLayoutsForInputDevice(InputDeviceIdentifier identifier) {
+ String key = getLayoutDescriptor(identifier);
synchronized (mDataStore) {
- return mDataStore.getKeyboardLayouts(inputDeviceDescriptor);
+ String[] layouts = mDataStore.getKeyboardLayouts(key);
+ if ((layouts == null || layouts.length == 0)
+ && !key.equals(identifier.getDescriptor())) {
+ layouts = mDataStore.getKeyboardLayouts(identifier.getDescriptor());
+ }
+ return layouts;
}
}
@Override // Binder call
- public void addKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
+ public void addKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
String keyboardLayoutDescriptor) {
if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
"addKeyboardLayoutForInputDevice()")) {
throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
}
- if (inputDeviceDescriptor == null) {
- throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
- }
if (keyboardLayoutDescriptor == null) {
throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
}
+ String key = getLayoutDescriptor(identifier);
synchronized (mDataStore) {
try {
- String oldLayout = mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor);
- if (mDataStore.addKeyboardLayout(inputDeviceDescriptor, keyboardLayoutDescriptor)
+ String oldLayout = mDataStore.getCurrentKeyboardLayout(key);
+ if (oldLayout == null && !key.equals(identifier.getDescriptor())) {
+ oldLayout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor());
+ }
+ if (mDataStore.addKeyboardLayout(key, keyboardLayoutDescriptor)
&& !Objects.equal(oldLayout,
- mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor))) {
+ mDataStore.getCurrentKeyboardLayout(key))) {
mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
}
} finally {
@@ -971,26 +1002,31 @@ public class InputManagerService extends IInputManager.Stub
}
@Override // Binder call
- public void removeKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
+ public void removeKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
String keyboardLayoutDescriptor) {
if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
"removeKeyboardLayoutForInputDevice()")) {
throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
}
- if (inputDeviceDescriptor == null) {
- throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
- }
if (keyboardLayoutDescriptor == null) {
throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
}
+ String key = getLayoutDescriptor(identifier);
synchronized (mDataStore) {
try {
- String oldLayout = mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor);
- if (mDataStore.removeKeyboardLayout(inputDeviceDescriptor,
- keyboardLayoutDescriptor)
- && !Objects.equal(oldLayout,
- mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor))) {
+ String oldLayout = mDataStore.getCurrentKeyboardLayout(key);
+ if (oldLayout == null && !key.equals(identifier.getDescriptor())) {
+ oldLayout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor());
+ }
+ boolean removed = mDataStore.removeKeyboardLayout(key, keyboardLayoutDescriptor);
+ if (!key.equals(identifier.getDescriptor())) {
+ // We need to remove from both places to ensure it is gone
+ removed |= mDataStore.removeKeyboardLayout(identifier.getDescriptor(),
+ keyboardLayoutDescriptor);
+ }
+ if (removed && !Objects.equal(oldLayout,
+ mDataStore.getCurrentKeyboardLayout(key))) {
mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
}
} finally {
@@ -1007,14 +1043,15 @@ public class InputManagerService extends IInputManager.Stub
private void handleSwitchKeyboardLayout(int deviceId, int direction) {
final InputDevice device = getInputDevice(deviceId);
if (device != null) {
- final String inputDeviceDescriptor = device.getDescriptor();
final boolean changed;
final String keyboardLayoutDescriptor;
+
+ String key = getLayoutDescriptor(device.getIdentifier());
synchronized (mDataStore) {
try {
- changed = mDataStore.switchKeyboardLayout(inputDeviceDescriptor, direction);
+ changed = mDataStore.switchKeyboardLayout(key, direction);
keyboardLayoutDescriptor = mDataStore.getCurrentKeyboardLayout(
- inputDeviceDescriptor);
+ key);
} finally {
mDataStore.saveIfNeeded();
}
@@ -1042,11 +1079,11 @@ public class InputManagerService extends IInputManager.Stub
public void setInputWindows(InputWindowHandle[] windowHandles) {
nativeSetInputWindows(mPtr, windowHandles);
}
-
+
public void setFocusedApplication(InputApplicationHandle application) {
nativeSetFocusedApplication(mPtr, application);
}
-
+
public void setInputDispatchMode(boolean enabled, boolean frozen) {
nativeSetInputDispatchMode(mPtr, enabled, frozen);
}
@@ -1426,13 +1463,12 @@ public class InputManagerService extends IInputManager.Stub
}
// Native callback.
- private String[] getKeyboardLayoutOverlay(String inputDeviceDescriptor) {
+ private String[] getKeyboardLayoutOverlay(InputDeviceIdentifier identifier) {
if (!mSystemReady) {
return null;
}
- String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(
- inputDeviceDescriptor);
+ String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(identifier);
if (keyboardLayoutDescriptor == null) {
return null;
}
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
index 10ad278..43fbe9d 100644
--- a/services/core/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -99,6 +99,12 @@ static struct {
jclass clazz;
} gMotionEventClassInfo;
+static struct {
+ jclass clazz;
+ jmethodID constructor;
+} gInputDeviceIdentifierInfo;
+
+
// --- Global functions ---
@@ -183,7 +189,7 @@ public:
virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
- virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor);
+ virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier);
virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
/* --- InputDispatcherPolicyInterface implementation --- */
@@ -492,13 +498,16 @@ void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>
}
sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
- const String8& inputDeviceDescriptor) {
+ const InputDeviceIdentifier& identifier) {
JNIEnv* env = jniEnv();
sp<KeyCharacterMap> result;
- ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string()));
+ ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.string()));
+ ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz,
+ gInputDeviceIdentifierInfo.constructor, descriptor.get(),
+ identifier.vendor, identifier.product));
ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
- gServiceClassInfo.getKeyboardLayoutOverlay, descriptorObj.get())));
+ gServiceClassInfo.getKeyboardLayoutOverlay, identifierObj.get())));
if (arrayObj.get()) {
ScopedLocalRef<jstring> filenameObj(env,
jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
@@ -1446,7 +1455,8 @@ int register_android_server_InputManager(JNIEnv* env) {
"getPointerIcon", "()Landroid/view/PointerIcon;");
GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
- "getKeyboardLayoutOverlay", "(Ljava/lang/String;)[Ljava/lang/String;");
+ "getKeyboardLayoutOverlay",
+ "(Landroid/hardware/input/InputDeviceIdentifier;)[Ljava/lang/String;");
GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
"getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
@@ -1466,6 +1476,13 @@ int register_android_server_InputManager(JNIEnv* env) {
FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
+ // InputDeviceIdentifier
+
+ FIND_CLASS(gInputDeviceIdentifierInfo.clazz, "android/hardware/input/InputDeviceIdentifier");
+ gInputDeviceIdentifierInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceIdentifierInfo.clazz));
+ GET_METHOD_ID(gInputDeviceIdentifierInfo.constructor, gInputDeviceIdentifierInfo.clazz,
+ "<init>", "(Ljava/lang/String;II)V");
+
return 0;
}