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

Commit 3d8cc938 authored by Arpit Singh's avatar Arpit Singh
Browse files

Refactor android_view_MotionEvent_obtainAsCopyFromNative implementation

Remove custom copying logic from
android_view_MotionEvent_obtainAsCopyFromNative and refactor it to use
existing android_view_MotionEvent_obtainFromNative to reduce
duplicate divergent logic.

Bug: 324375527
Test: atest MotionEventTest
Change-Id: Ib7c6533fb6e0a0203e68a109d1b912082dafc239
parent 14ee29ab
Loading
Loading
Loading
Loading
+2 −16
Original line number Diff line number Diff line
@@ -84,23 +84,9 @@ static void android_view_MotionEvent_setNativePtr(JNIEnv* env, jobject eventObj,
}

jobject android_view_MotionEvent_obtainAsCopy(JNIEnv* env, const MotionEvent& event) {
    jobject eventObj = env->CallStaticObjectMethod(gMotionEventClassInfo.clazz,
            gMotionEventClassInfo.obtain);
    if (env->ExceptionCheck() || !eventObj) {
        ALOGE("An exception occurred while obtaining a motion event.");
        LOGE_EX(env);
        env->ExceptionClear();
        return NULL;
    }

    MotionEvent* destEvent = android_view_MotionEvent_getNativePtr(env, eventObj);
    if (!destEvent) {
        destEvent = new MotionEvent();
        android_view_MotionEvent_setNativePtr(env, eventObj, destEvent);
    }

    std::unique_ptr<MotionEvent> destEvent = std::make_unique<MotionEvent>();
    destEvent->copyFrom(&event, true);
    return eventObj;
    return android_view_MotionEvent_obtainFromNative(env, std::move(destEvent));
}

jobject android_view_MotionEvent_obtainFromNative(JNIEnv* env, std::unique_ptr<MotionEvent> event) {