Do not share key mappings with JNI object
The key mapping information between the native key mappings and the KeyCharacterMap object available in Java is currently shared, which means that a read can be attempted while it's being modified. Bug: 274058082 Test: Patch tested by Oppo Change-Id: I745008a0a8ea30830660c45dcebee917b3913d13
This commit is contained in:
@@ -42,6 +42,13 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// b/274058082: Pass a copy of the key character map to avoid concurrent
|
||||||
|
// access
|
||||||
|
std::shared_ptr<KeyCharacterMap> map = deviceInfo.getKeyCharacterMap();
|
||||||
|
if (map != nullptr) {
|
||||||
|
map = std::make_shared<KeyCharacterMap>(*map);
|
||||||
|
}
|
||||||
|
|
||||||
ScopedLocalRef<jstring> descriptorObj(env,
|
ScopedLocalRef<jstring> descriptorObj(env,
|
||||||
env->NewStringUTF(deviceInfo.getIdentifier().descriptor.c_str()));
|
env->NewStringUTF(deviceInfo.getIdentifier().descriptor.c_str()));
|
||||||
if (!descriptorObj.get()) {
|
if (!descriptorObj.get()) {
|
||||||
@@ -49,8 +56,8 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScopedLocalRef<jobject> kcmObj(env,
|
ScopedLocalRef<jobject> kcmObj(env,
|
||||||
android_view_KeyCharacterMap_create(env, deviceInfo.getId(),
|
android_view_KeyCharacterMap_create(env, deviceInfo.getId(),
|
||||||
deviceInfo.getKeyCharacterMap()));
|
map));
|
||||||
if (!kcmObj.get()) {
|
if (!kcmObj.get()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user