From 29f2c0dc8347dea98447e77e7d48b64401424fe4 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Tue, 18 Aug 2020 13:38:52 -0700 Subject: [PATCH] Removes unnecessary weak reference on the java object associated with JHwRemoteBinder. Bug: 161964661 Test: system/tools/hidl/test/run_all_device_tests.sh Change-Id: Ia08e64bd4df87f1604f26ffa64d799131cc31f53 --- core/jni/android_os_HwRemoteBinder.cpp | 19 +++---------------- core/jni/android_os_HwRemoteBinder.h | 13 ++++++------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/core/jni/android_os_HwRemoteBinder.cpp b/core/jni/android_os_HwRemoteBinder.cpp index f8f841c6fd26d..3af55fe810fc6 100644 --- a/core/jni/android_os_HwRemoteBinder.cpp +++ b/core/jni/android_os_HwRemoteBinder.cpp @@ -269,22 +269,9 @@ jobject JHwRemoteBinder::NewObject( return obj; } -JHwRemoteBinder::JHwRemoteBinder( - JNIEnv *env, jobject thiz, const sp &binder) - : mBinder(binder) { - mDeathRecipientList = new HwBinderDeathRecipientList(); - jclass clazz = env->GetObjectClass(thiz); - CHECK(clazz != NULL); - - mObject = env->NewWeakGlobalRef(thiz); -} - -JHwRemoteBinder::~JHwRemoteBinder() { - JNIEnv *env = AndroidRuntime::getJNIEnv(); - - env->DeleteWeakGlobalRef(mObject); - mObject = NULL; -} +JHwRemoteBinder::JHwRemoteBinder(JNIEnv* env, jobject /* thiz */, + const sp& binder) + : mBinder(binder), mDeathRecipientList(new HwBinderDeathRecipientList()) {} sp JHwRemoteBinder::getBinder() const { return mBinder; diff --git a/core/jni/android_os_HwRemoteBinder.h b/core/jni/android_os_HwRemoteBinder.h index 4b5a4c8c837c7..7eb81f3c54e1b 100644 --- a/core/jni/android_os_HwRemoteBinder.h +++ b/core/jni/android_os_HwRemoteBinder.h @@ -36,9 +36,13 @@ class HwBinderDeathRecipientList : public RefBase { std::vector> mList; Mutex mLock; +protected: + ~HwBinderDeathRecipientList() override; + public: - HwBinderDeathRecipientList(); - ~HwBinderDeathRecipientList(); + explicit HwBinderDeathRecipientList(); + + DISALLOW_COPY_AND_ASSIGN(HwBinderDeathRecipientList); void add(const sp& recipient); void remove(const sp& recipient); @@ -66,12 +70,7 @@ struct JHwRemoteBinder : public RefBase { void setBinder(const sp &binder); sp getDeathRecipientList() const; -protected: - virtual ~JHwRemoteBinder(); - private: - jobject mObject; - sp mBinder; sp mDeathRecipientList; DISALLOW_COPY_AND_ASSIGN(JHwRemoteBinder);