From a944ece068ba4c7ac99079adbc04d132763fb9e2 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Tue, 19 Apr 2022 23:39:08 +0000 Subject: [PATCH] javaObjectForIBinder: warn rets global and local Trying to manually delete the result of this function as a local ref is problematic. Bug: 227719836 Test: N/A Change-Id: Iea4509e08f935f268ee502825dab47caef8508a5 --- core/jni/android_util_Binder.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/jni/android_util_Binder.h b/core/jni/android_util_Binder.h index 9098d46ee29c4..d73db6245672a 100644 --- a/core/jni/android_util_Binder.h +++ b/core/jni/android_util_Binder.h @@ -24,8 +24,18 @@ namespace android { -// Converstion to/from Java IBinder Object and C++ IBinder instance. +/** + * Conversion to Java IBinder Object from C++ IBinder instance. + * + * WARNING: this function returns global and local references. This can be + * figured out using GetObjectRefType. Though, when this function is called + * from within a Java context, the local ref will automatically be cleaned + * up. If this is called outside of a Java frame, + * PushObjectFrame/PopObjectFrame can simulate this automatic cleanup. The + * platform provides ScopedLocalFrame as an RAII object for this. + */ extern jobject javaObjectForIBinder(JNIEnv* env, const sp& val); +/** Conversion from Java IBinder Object to C++ IBinder instance. */ extern sp ibinderForJavaObject(JNIEnv* env, jobject obj); extern jobject newParcelFileDescriptor(JNIEnv* env, jobject fileDesc);