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

Commit eb6d62cd authored by Hans Boehm's avatar Hans Boehm
Browse files

Naming fix and add comments

Also fix up imports to make repohooks happy and some whitespace issues.

A very small step towards making this code more understandable.

Bug: 65760710

Test: Builds.
Change-Id: I0396c06bb303e0b06ad0cbbbff4fdc1ac527ac6c
parent b4e17814
Loading
Loading
Loading
Loading
+32 −13
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.util.Log;
import android.util.Slog;

import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FunctionalUtils;
import com.android.internal.util.FunctionalUtils.ThrowingRunnable;
import com.android.internal.util.FunctionalUtils.ThrowingSupplier;

@@ -714,7 +713,15 @@ public class Binder implements IBinder {
    }
}

/**
 * Java proxy for a native IBinder object.
 * Allocated and constructed by the native javaObjectforIBinder function. Never allocated
 * directly from Java code.
 */
final class BinderProxy implements IBinder {
    // See android_util_Binder.cpp for the native half of this.
    // TODO: Consider using NativeAllocationRegistry instead of finalization.

    // Assume the process-wide default value when created
    volatile boolean mWarnOnBlocking = Binder.sWarnOnBlocking;

@@ -833,7 +840,19 @@ final class BinderProxy implements IBinder {
        }
    }

    // This WeakReference to "this" is used only by native code to "attach" to the
    // native IBinder object.
    // Using WeakGlobalRefs instead currently appears unsafe, in that they can yield a
    // non-null value after the BinderProxy is enqueued for finalization.
    // Used only once immediately after construction.
    // TODO: Consider making the extra native-to-java call to compute this on the fly.
    final private WeakReference mSelf;

    // Native pointer to the wrapped native IBinder object. Counted as strong reference.
    private long mObject;

    // Native pointer to native DeathRecipientList. Counted as strong reference.
    // Basically owned by the JavaProxy object. Reference counted only because DeathRecipients
    // hold a weak reference that can be temporarily promoted.
    private long mOrgue;
}
+5 −5
Original line number Diff line number Diff line
@@ -488,8 +488,8 @@ protected:

private:
    JavaVM* const mVM;
    jobject mObject;
    jweak mObjectWeak; // will be a weak ref to the same VM-side DeathRecipient after binderDied()
    jobject mObject;  // Initial strong ref to Java-side DeathRecipient. Cleared on binderDied().
    jweak mObjectWeak; // weak ref to the same Java-side DeathRecipient after binderDied().
    wp<DeathRecipientList> mList;
};

@@ -561,7 +561,7 @@ static void proxy_cleanup(const void* id, void* obj, void* cleanupCookie)
    env->DeleteGlobalRef((jobject)obj);
}

static Mutex mProxyLock;
static Mutex gProxyLock;

jobject javaObjectForIBinder(JNIEnv* env, const sp<IBinder>& val)
{
@@ -576,7 +576,7 @@ jobject javaObjectForIBinder(JNIEnv* env, const sp<IBinder>& val)

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

    // Someone else's...  do we know about it?
    jobject object = (jobject)val->findObject(&gBinderProxyOffsets);
@@ -1252,7 +1252,7 @@ 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);
    AutoMutex _l(gProxyLock);

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