Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4739e7f authored by Jiyong Park's avatar Jiyong Park
Browse files

Guard the death recipient behavior behind a build flag

The death recipient behavior introduced with Ibb371f4de45530670d5f783f8ead8404c39381b4
is guarded with a build flag
RELEASE_BINDER_DEATH_RECIPIENT_WEAK_FROM_JNI.

Bug: 298374304
Test: build
Change-Id: Ie604ee723385676cf3c83f0d9b2a46ceb322903a
parent 646cc266
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -15,7 +15,19 @@ license {
    ],
}

cc_library_shared {
soong_config_module_type {
    name: "cc_library_shared_for_libandroid_runtime",
    module_type: "cc_library_shared",
    config_namespace: "ANDROID",
    bool_variables: [
        "release_binder_death_recipient_weak_from_jni",
    ],
    properties: [
        "cflags",
    ],
}

cc_library_shared_for_libandroid_runtime {
    name: "libandroid_runtime",
    host_supported: true,
    cflags: [
@@ -46,6 +58,12 @@ cc_library_shared {
        },
    },

    soong_config_variables: {
        release_binder_death_recipient_weak_from_jni: {
            cflags: ["-DBINDER_DEATH_RECIPIENT_WEAK_FROM_JNI"],
        },
    },

    cpp_std: "gnu++20",

    srcs: [
+6 −1
Original line number Diff line number Diff line
@@ -556,6 +556,7 @@ public:
};

// ----------------------------------------------------------------------------
#ifdef BINDER_DEATH_RECIPIENT_WEAK_FROM_JNI
#if __BIONIC__
#include <android/api-level.h>
static bool target_sdk_is_at_least_vic() {
@@ -568,6 +569,7 @@ static constexpr bool target_sdk_is_at_least_vic() {
    return true;
}
#endif // __BIONIC__
#endif // BINDER_DEATH_RECIPIENT_WEAK_FROM_JNI

class JavaDeathRecipient : public IBinder::DeathRecipient
{
@@ -588,9 +590,12 @@ public:
        // you normally are not interested in the death of a binder service which you don't have any
        // reference to. If however you want to get binderDied() regardless of the proxy object's
        // lifecycle, keep a strong reference to the death recipient object by yourself.
#ifdef BINDER_DEATH_RECIPIENT_WEAK_FROM_JNI
        if (target_sdk_is_at_least_vic()) {
            mObjectWeak = env->NewWeakGlobalRef(object);
        } else {
        } else
#endif
        {
            mObject = env->NewGlobalRef(object);
        }
        // These objects manage their own lifetimes so are responsible for final bookkeeping.