Skip to content

Commit 3d27bd3

Browse files
Josep del RioAndroid Build Coastguard Worker
authored andcommitted
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 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3d993de0d1ada8065d1fe561f690c8f82b6a7d4b) Merged-In: I745008a0a8ea30830660c45dcebee917b3913d13 Change-Id: I745008a0a8ea30830660c45dcebee917b3913d13
1 parent 8f00d3e commit 3d27bd3

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

core/jni/android_view_InputDevice.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,22 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi
4242
return NULL;
4343
}
4444

45+
// b/274058082: Pass a copy of the key character map to avoid concurrent
46+
// access
47+
std::shared_ptr<KeyCharacterMap> map = deviceInfo.getKeyCharacterMap();
48+
if (map != nullptr) {
49+
map = std::make_shared<KeyCharacterMap>(*map);
50+
}
51+
4552
ScopedLocalRef<jstring> descriptorObj(env,
4653
env->NewStringUTF(deviceInfo.getIdentifier().descriptor.c_str()));
4754
if (!descriptorObj.get()) {
4855
return NULL;
4956
}
5057

5158
ScopedLocalRef<jobject> kcmObj(env,
52-
android_view_KeyCharacterMap_create(env, deviceInfo.getId(),
53-
deviceInfo.getKeyCharacterMap()));
59+
android_view_KeyCharacterMap_create(env, deviceInfo.getId(),
60+
map));
5461
if (!kcmObj.get()) {
5562
return NULL;
5663
}

0 commit comments

Comments
 (0)