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

Commit a517844c authored by Chris Tate's avatar Chris Tate Committed by Android (Google) Code Review
Browse files

Merge "BinderProxy native destruction resilience" into nyc-dev

parents 341de33e 10c3a283
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -556,7 +556,7 @@ jobject javaObjectForIBinder(JNIEnv* env, const sp<IBinder>& val)
    }

    // For the rest of the function we will hold this lock, to serialize
    // looking/creation of Java proxies for native Binder proxies.
    // looking/creation/destruction of Java proxies for native Binder proxies.
    AutoMutex _l(mProxyLock);

    // Someone else's...  do we know about it?
@@ -1225,16 +1225,21 @@ static jboolean android_os_BinderProxy_unlinkToDeath(JNIEnv* env, jobject obj,

static void android_os_BinderProxy_destroy(JNIEnv* env, jobject obj)
{
    // Don't race with construction/initialization
    AutoMutex _l(mProxyLock);

    IBinder* b = (IBinder*)
            env->GetLongField(obj, gBinderProxyOffsets.mObject);
    DeathRecipientList* drl = (DeathRecipientList*)
            env->GetLongField(obj, gBinderProxyOffsets.mOrgue);

    LOGDEATH("Destroying BinderProxy %p: binder=%p drl=%p\n", obj, b, drl);
    if (b != nullptr) {
        env->SetLongField(obj, gBinderProxyOffsets.mObject, 0);
        env->SetLongField(obj, gBinderProxyOffsets.mOrgue, 0);
        drl->decStrong((void*)javaObjectForIBinder);
        b->decStrong((void*)javaObjectForIBinder);
    }

    IPCThreadState::self()->flushCommands();
}