From db07b07b2b198f0bdc7bfb817b35410970b65f3c Mon Sep 17 00:00:00 2001 From: chaviw Date: Mon, 18 Apr 2022 09:00:24 -0500 Subject: [PATCH] Construct Region object with nativeObject The default ctor for the Java Region object creates a native SkRegion object. Hoewver, in the JNI code we overwrite the native pointer so the native object created from the default ctor never gets cleaned up. Instead, use the ctor that accepts a native ptr so we create the Region object with native info populated. Test: Builds Fixes: 229537097 Change-Id: I89e4b8ec985c538e7337c0e80415d3b6474da78e --- core/jni/android_hardware_input_InputWindowHandle.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/core/jni/android_hardware_input_InputWindowHandle.cpp b/core/jni/android_hardware_input_InputWindowHandle.cpp index 973ed29d8e72d..241320f317486 100644 --- a/core/jni/android_hardware_input_InputWindowHandle.cpp +++ b/core/jni/android_hardware_input_InputWindowHandle.cpp @@ -79,7 +79,6 @@ static struct { static struct { jclass clazz; jmethodID ctor; - jfieldID nativeRegion; } gRegionClassInfo; static Mutex gHandleMutex; @@ -290,10 +289,8 @@ jobject android_view_InputWindowHandle_fromWindowInfo(JNIEnv* env, gui::WindowIn region->op({r.left, r.top, r.right, r.bottom}, SkRegion::kUnion_Op); } ScopedLocalRef regionObj(env, - env->NewObject(gRegionClassInfo.clazz, - gRegionClassInfo.ctor)); - env->SetLongField(regionObj.get(), gRegionClassInfo.nativeRegion, - reinterpret_cast(region)); + env->NewObject(gRegionClassInfo.clazz, gRegionClassInfo.ctor, + reinterpret_cast(region))); env->SetObjectField(inputWindowHandle, gInputWindowHandleClassInfo.touchableRegion, regionObj.get()); @@ -453,8 +450,7 @@ int register_android_view_InputWindowHandle(JNIEnv* env) { jclass regionClazz; FIND_CLASS(regionClazz, "android/graphics/Region"); gRegionClassInfo.clazz = MakeGlobalRefOrDie(env, regionClazz); - GET_METHOD_ID(gRegionClassInfo.ctor, gRegionClassInfo.clazz, "", "()V"); - GET_FIELD_ID(gRegionClassInfo.nativeRegion, gRegionClassInfo.clazz, "mNativeRegion", "J"); + GET_METHOD_ID(gRegionClassInfo.ctor, gRegionClassInfo.clazz, "", "(J)V"); return 0; }