diff options
| author | 2024-02-16 13:40:15 +0000 | |
|---|---|---|
| committer | 2024-02-21 16:35:01 +0000 | |
| commit | 3d8cc938500d687fa071cbd91d245fe10daba59f (patch) | |
| tree | c3f70e26c35d9fbcb8fb4a54067fe47e0277f8c5 | |
| parent | 14ee29abbf9d8353982de0353548023fb590bdf5 (diff) | |
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
| -rw-r--r-- | core/jni/android_view_MotionEvent.cpp | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/core/jni/android_view_MotionEvent.cpp b/core/jni/android_view_MotionEvent.cpp index 2e9f1790a4a5..33fbdb83cf48 100644 --- a/core/jni/android_view_MotionEvent.cpp +++ b/core/jni/android_view_MotionEvent.cpp @@ -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) { |