Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b3c4620 authored by Josep del Rio's avatar Josep del Rio Committed by Josep del Río
Browse files

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.

Because the code changed between R and S, this CL fixes it just
for R; the patch for versions S+ is ag/23785419

Bug: 274058082
Test: Presubmit
Change-Id: I3be94534dcda365da473f82347ae2e3f57bb1b42
Merged-In: I745008a0a8ea30830660c45dcebee917b3913d13
parent c424f6ec
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
 * limitations under the License.
 */

#include <binder/Parcel.h>
#include <input/Input.h>

#include <android_runtime/AndroidRuntime.h>
@@ -48,9 +49,16 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi
        return NULL;
    }

    sp<KeyCharacterMap> map = deviceInfo.getKeyCharacterMap();
    if (map != nullptr) {
        Parcel parcel;
        map->writeToParcel(&parcel);
        map = map->readFromParcel(&parcel);
    }

    ScopedLocalRef<jobject> kcmObj(env,
                                   android_view_KeyCharacterMap_create(env, deviceInfo.getId(),
            deviceInfo.getKeyCharacterMap()));
                                                                       map));
    if (!kcmObj.get()) {
        return NULL;
    }