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

Commit 437a5e70 authored by Steven Moreland's avatar Steven Moreland Committed by Automerger Merge Worker
Browse files

Merge "libbinder_ndk: allow disabling interface token" am: 3aeebcf7 am: 0c83a941

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1811940

Change-Id: Ifaf4a1b2a7ce389617ab5473e8dcb5e8373b91c1
parents 90eb3d2f 0c83a941
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ status_t ABBinder::dump(int fd, const ::android::Vector<String16>& args) {
status_t ABBinder::onTransact(transaction_code_t code, const Parcel& data, Parcel* reply,
                              binder_flags_t flags) {
    if (isUserCommand(code)) {
        if (!data.checkInterface(this)) {
        if (getClass()->writeHeader && !data.checkInterface(this)) {
            return STATUS_BAD_TYPE;
        }

@@ -354,6 +354,12 @@ void AIBinder_Class_setOnDump(AIBinder_Class* clazz, AIBinder_onDump onDump) {
    clazz->onDump = onDump;
}

void AIBinder_Class_disableInterfaceTokenHeader(AIBinder_Class* clazz) {
    CHECK(clazz != nullptr) << "disableInterfaceTokenHeader requires non-null clazz";

    clazz->writeHeader = false;
}

void AIBinder_Class_setHandleShellCommand(AIBinder_Class* clazz,
                                          AIBinder_handleShellCommand handleShellCommand) {
    CHECK(clazz != nullptr) << "setHandleShellCommand requires non-null clazz";
@@ -606,7 +612,10 @@ binder_status_t AIBinder_prepareTransaction(AIBinder* binder, AParcel** in) {
    *in = new AParcel(binder);
    (*in)->get()->markForBinder(binder->getBinder());

    status_t status = (*in)->get()->writeInterfaceToken(clazz->getInterfaceDescriptor());
    status_t status = android::OK;
    if (clazz->writeHeader) {
        status = (*in)->get()->writeInterfaceToken(clazz->getInterfaceDescriptor());
    }
    binder_status_t ret = PruneStatusT(status);

    if (ret != STATUS_OK) {
+3 −0
Original line number Diff line number Diff line
@@ -116,6 +116,9 @@ struct AIBinder_Class {
    const ::android::String16& getInterfaceDescriptor() const { return mWideInterfaceDescriptor; }
    const char* getInterfaceDescriptorUtf8() const { return mInterfaceDescriptor.c_str(); }

    // whether a transaction header should be written
    bool writeHeader = true;

    // required to be non-null, implemented for every class
    const AIBinder_Class_onCreate onCreate = nullptr;
    const AIBinder_Class_onDestroy onDestroy = nullptr;
+15 −0
Original line number Diff line number Diff line
@@ -218,6 +218,21 @@ typedef binder_status_t (*AIBinder_onDump)(AIBinder* binder, int fd, const char*
 */
void AIBinder_Class_setOnDump(AIBinder_Class* clazz, AIBinder_onDump onDump) __INTRODUCED_IN(29);

/**
 * This tells users of this class not to use a transaction header. By default, libbinder_ndk users
 * read/write transaction headers implicitly (in the SDK, this must be manually written by
 * android.os.Parcel#writeInterfaceToken, and it is read/checked with
 * android.os.Parcel#enforceInterface). This method is provided in order to talk to legacy code
 * which does not write an interface token. When this is disabled, type safety is reduced, so you
 * must have a separate way of determining the binder you are talking to is the right type. Must
 * be called before any instance of the class is created.
 *
 * Available since API level 32.
 *
 * \param clazz class to disable interface header on.
 */
void AIBinder_Class_disableInterfaceTokenHeader(AIBinder_Class* clazz) __INTRODUCED_IN(32);

/**
 * Creates a new binder object of the appropriate class.
 *
+5 −0
Original line number Diff line number Diff line
@@ -141,6 +141,11 @@ LIBBINDER_NDK31 { # introduced=31
    AParcel_reset;
};

LIBBINDER_NDK32 { # introduced=32
  global:
    AIBinder_Class_disableInterfaceTokenHeader;
};

LIBBINDER_NDK_PLATFORM {
  global:
    AParcel_getAllowFds;