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

Commit d587a555 authored by Steven Moreland's avatar Steven Moreland
Browse files

Binder: add markVintfStability

For the AIDL compiler to call. Without this, the Java framework can't
pass callbacks to HALs.

Bug: 139325468
Test: use vibrator callback from Java
Change-Id: I147d3e3da699ce740f6589264b37f43f8557719b
parent 10f4d427
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -501,6 +501,19 @@ public class Binder implements IBinder {
    @CriticalNative
    @CriticalNative
    public static final native void restoreCallingWorkSource(long token);
    public static final native void restoreCallingWorkSource(long token);


    /**
     * Mark as being built with VINTF-level stability promise. This API should
     * only ever be invoked by the build system. It means that the interface
     * represented by this binder is guaranteed to be kept stable for several
     * years, and the build system also keeps snapshots of these APIs and
     * invokes the AIDL compiler to make sure that these snapshots are
     * backwards compatible. Instead of using this API, use an @VintfStability
     * interface.
     *
     * @hide
     */
    public final native void markVintfStability();

    /**
    /**
     * Flush any Binder commands pending in the current thread to the kernel
     * Flush any Binder commands pending in the current thread to the kernel
     * driver.  This can be
     * driver.  This can be
+22 −2
Original line number Original line Diff line number Diff line
@@ -30,12 +30,13 @@
#include <unistd.h>
#include <unistd.h>


#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <binder/BpBinder.h>
#include <binder/IInterface.h>
#include <binder/IInterface.h>
#include <binder/IServiceManager.h>
#include <binder/IPCThreadState.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/Parcel.h>
#include <binder/Parcel.h>
#include <binder/BpBinder.h>
#include <binder/ProcessState.h>
#include <binder/ProcessState.h>
#include <binder/Stability.h>
#include <cutils/atomic.h>
#include <cutils/atomic.h>
#include <log/log.h>
#include <log/log.h>
#include <utils/KeyedVector.h>
#include <utils/KeyedVector.h>
@@ -459,6 +460,9 @@ public:
        sp<JavaBBinder> b = mBinder.promote();
        sp<JavaBBinder> b = mBinder.promote();
        if (b == NULL) {
        if (b == NULL) {
            b = new JavaBBinder(env, obj);
            b = new JavaBBinder(env, obj);
            if (mVintf) {
                ::android::internal::Stability::markVintf(b.get());
            }
            mBinder = b;
            mBinder = b;
            ALOGV("Creating JavaBinder %p (refs %p) for Object %p, weakCount=%" PRId32 "\n",
            ALOGV("Creating JavaBinder %p (refs %p) for Object %p, weakCount=%" PRId32 "\n",
                 b.get(), b->getWeakRefs(), obj, b->getWeakRefs()->getWeakCount());
                 b.get(), b->getWeakRefs(), obj, b->getWeakRefs()->getWeakCount());
@@ -473,9 +477,18 @@ public:
        return mBinder.promote();
        return mBinder.promote();
    }
    }


    void markVintf() {
        mVintf = true;
    }

private:
private:
    Mutex           mLock;
    Mutex           mLock;
    wp<JavaBBinder> mBinder;
    wp<JavaBBinder> mBinder;

    // in the future, we might condense this into int32_t stability, or if there
    // is too much binder state here, we can think about making JavaBBinder an
    // sp here (avoid recreating it)
    bool            mVintf = false;
};
};


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -962,6 +975,12 @@ static void android_os_Binder_restoreCallingWorkSource(jlong token)
    IPCThreadState::self()->restoreCallingWorkSource(token);
    IPCThreadState::self()->restoreCallingWorkSource(token);
}
}


static void android_os_Binder_markVintfStability(JNIEnv* env, jobject clazz) {
    JavaBBinderHolder* jbh =
        (JavaBBinderHolder*) env->GetLongField(clazz, gBinderOffsets.mObject);
    jbh->markVintf();
}

static void android_os_Binder_flushPendingCommands(JNIEnv* env, jobject clazz)
static void android_os_Binder_flushPendingCommands(JNIEnv* env, jobject clazz)
{
{
    IPCThreadState::self()->flushCommands();
    IPCThreadState::self()->flushCommands();
@@ -1038,6 +1057,7 @@ static const JNINativeMethod gBinderMethods[] = {
    // @CriticalNative
    // @CriticalNative
    { "clearCallingWorkSource", "()J", (void*)android_os_Binder_clearCallingWorkSource },
    { "clearCallingWorkSource", "()J", (void*)android_os_Binder_clearCallingWorkSource },
    { "restoreCallingWorkSource", "(J)V", (void*)android_os_Binder_restoreCallingWorkSource },
    { "restoreCallingWorkSource", "(J)V", (void*)android_os_Binder_restoreCallingWorkSource },
    { "markVintfStability", "()V", (void*)android_os_Binder_markVintfStability},
    { "flushPendingCommands", "()V", (void*)android_os_Binder_flushPendingCommands },
    { "flushPendingCommands", "()V", (void*)android_os_Binder_flushPendingCommands },
    { "getNativeBBinderHolder", "()J", (void*)android_os_Binder_getNativeBBinderHolder },
    { "getNativeBBinderHolder", "()J", (void*)android_os_Binder_getNativeBBinderHolder },
    { "getNativeFinalizer", "()J", (void*)android_os_Binder_getNativeFinalizer },
    { "getNativeFinalizer", "()J", (void*)android_os_Binder_getNativeFinalizer },