Merge "Binder: add markVintfStability"

This commit is contained in:
Steven Moreland
2019-12-02 16:46:17 +00:00
committed by Gerrit Code Review
2 changed files with 37 additions and 4 deletions

View File

@@ -501,6 +501,19 @@ public class Binder implements IBinder {
@CriticalNative
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
* driver. This can be

View File

@@ -30,12 +30,13 @@
#include <unistd.h>
#include <android-base/stringprintf.h>
#include <binder/IInterface.h>
#include <binder/IServiceManager.h>
#include <binder/IPCThreadState.h>
#include <binder/Parcel.h>
#include <binder/BpBinder.h>
#include <binder/IInterface.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/Parcel.h>
#include <binder/ProcessState.h>
#include <binder/Stability.h>
#include <cutils/atomic.h>
#include <log/log.h>
#include <utils/KeyedVector.h>
@@ -459,6 +460,9 @@ public:
sp<JavaBBinder> b = mBinder.promote();
if (b == NULL) {
b = new JavaBBinder(env, obj);
if (mVintf) {
::android::internal::Stability::markVintf(b.get());
}
mBinder = b;
ALOGV("Creating JavaBinder %p (refs %p) for Object %p, weakCount=%" PRId32 "\n",
b.get(), b->getWeakRefs(), obj, b->getWeakRefs()->getWeakCount());
@@ -473,9 +477,18 @@ public:
return mBinder.promote();
}
void markVintf() {
mVintf = true;
}
private:
Mutex mLock;
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);
}
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)
{
IPCThreadState::self()->flushCommands();
@@ -1038,6 +1057,7 @@ static const JNINativeMethod gBinderMethods[] = {
// @CriticalNative
{ "clearCallingWorkSource", "()J", (void*)android_os_Binder_clearCallingWorkSource },
{ "restoreCallingWorkSource", "(J)V", (void*)android_os_Binder_restoreCallingWorkSource },
{ "markVintfStability", "()V", (void*)android_os_Binder_markVintfStability},
{ "flushPendingCommands", "()V", (void*)android_os_Binder_flushPendingCommands },
{ "getNativeBBinderHolder", "()J", (void*)android_os_Binder_getNativeBBinderHolder },
{ "getNativeFinalizer", "()J", (void*)android_os_Binder_getNativeFinalizer },