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

Commit a277a954 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "libbinder_ndk: add AStatus_getDescription" am: cb038369 am: 1ea528ac

Change-Id: Ib1590ca5727e4596a81e4c8c186e784894e26b0c
parents 7b898192 1ea528ac
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@

#include <unistd.h>
#include <cstddef>
#include <string>

namespace ndk {

@@ -228,6 +229,13 @@ class ScopedAStatus : public impl::ScopedAResource<AStatus*, void, AStatus_delet
     */
    const char* getMessage() const { return AStatus_getMessage(get()); }

    std::string getDescription() const {
        const char* cStr = AStatus_getDescription(get());
        std::string ret = cStr;
        AStatus_deleteDescription(cStr);
        return ret;
    }

    /**
     * Convenience methods for creating scoped statuses.
     */
+19 −0
Original line number Diff line number Diff line
@@ -246,6 +246,25 @@ binder_status_t AStatus_getStatus(const AStatus* status) __INTRODUCED_IN(29);
 */
const char* AStatus_getMessage(const AStatus* status) __INTRODUCED_IN(29);

/**
 * Get human-readable description for debugging.
 *
 * Available since API level 30.
 *
 * \param status the status being queried.
 *
 * \return a description, must be deleted with AStatus_deleteDescription.
 */
__attribute__((warn_unused_result)) const char* AStatus_getDescription(const AStatus* status)
        __INTRODUCED_IN(30);

/**
 * Delete description.
 *
 * \param description value from AStatus_getDescription
 */
void AStatus_deleteDescription(const char* description) __INTRODUCED_IN(30);

/**
 * Deletes memory associated with the status instance.
 *
+2 −0
Original line number Diff line number Diff line
@@ -103,6 +103,8 @@ LIBBINDER_NDK30 { # introduced=30
  global:
    AIBinder_getExtension;
    AIBinder_setExtension;
    AStatus_getDescription;
    AStatus_deleteDescription;

    AIBinder_markSystemStability; # apex
    AIBinder_markVendorStability; # llndk
+11 −0
Original line number Diff line number Diff line
@@ -66,6 +66,17 @@ const char* AStatus_getMessage(const AStatus* status) {
    return status->get()->exceptionMessage().c_str();
}

const char* AStatus_getDescription(const AStatus* status) {
    android::String8 description = status->get()->toString8();
    char* cStr = new char[description.size() + 1];
    memcpy(cStr, description.c_str(), description.size() + 1);
    return cStr;
}

void AStatus_deleteDescription(const char* description) {
    delete[] const_cast<char*>(description);
}

void AStatus_delete(AStatus* status) {
    delete status;
}
+2 −1
Original line number Diff line number Diff line
@@ -105,7 +105,8 @@ TEST(DoubleBinder, CallIntoNdk) {

        std::string outString;
        ScopedAStatus status = server->RepeatString("foo", &outString);
        EXPECT_EQ(STATUS_OK, AStatus_getExceptionCode(status.get())) << serviceName;
        EXPECT_EQ(STATUS_OK, AStatus_getExceptionCode(status.get()))
                << serviceName << " " << status.getDescription();
        EXPECT_EQ("foo", outString) << serviceName;
    }
}