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
diff --git a/core/jni/android_view_MotionEvent.cpp b/core/jni/android_view_MotionEvent.cpp
index 2e9f179..33fbdb8 100644
--- a/core/jni/android_view_MotionEvent.cpp
+++ b/core/jni/android_view_MotionEvent.cpp
@@ -84,23 +84,9 @@
 }
 
 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) {