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

Commit acb53f92 authored by Devin Moore's avatar Devin Moore Committed by Automerger Merge Worker
Browse files

Merge "Add APersistableBundle to lldnk" into main am: 81fed5f3 am: b53bce4a

parents d8b0cc3f b53bce4a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ cc_library {

    llndk: {
        symbol_file: "libbinder_ndk.map.txt",
        export_llndk_headers: ["libvendorsupport_llndk_headers"],
    },

    export_include_dirs: [
@@ -79,9 +80,11 @@ cc_library {
    ],

    header_libs: [
        "libvendorsupport_llndk_headers",
        "jni_headers",
    ],
    export_header_lib_headers: [
        "libvendorsupport_llndk_headers",
        "jni_headers",
    ],

+51 −44
Original line number Diff line number Diff line
@@ -24,6 +24,13 @@

namespace aidl::android::os {

#if defined(__ANDROID_VENDOR__)
#define AT_LEAST_V_OR_202404 constexpr(__ANDROID_VENDOR_API__ >= 202404)
#else
// TODO(b/322384429) switch this to __ANDROID_API_V__ when V is finalized
#define AT_LEAST_V_OR_202404 (__builtin_available(android __ANDROID_API_FUTURE__, *))
#endif

/**
 * Wrapper class that enables interop with AIDL NDK generation
 * Takes ownership of the APersistableBundle* given to it in reset() and will automatically
@@ -32,7 +39,7 @@ namespace aidl::android::os {
class PersistableBundle {
   public:
    PersistableBundle() noexcept {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            mPBundle = APersistableBundle_new();
        }
    }
@@ -42,13 +49,13 @@ class PersistableBundle {
    PersistableBundle(PersistableBundle&& other) noexcept : mPBundle(other.release()) {}
    // duplicates, does not take ownership of the APersistableBundle*
    PersistableBundle(const PersistableBundle& other) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            mPBundle = APersistableBundle_dup(other.mPBundle);
        }
    }
    // duplicates, does not take ownership of the APersistableBundle*
    PersistableBundle& operator=(const PersistableBundle& other) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            mPBundle = APersistableBundle_dup(other.mPBundle);
        }
        return *this;
@@ -58,7 +65,7 @@ class PersistableBundle {

    binder_status_t readFromParcel(const AParcel* _Nonnull parcel) {
        reset();
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return APersistableBundle_readFromParcel(parcel, &mPBundle);
        } else {
            return STATUS_INVALID_OPERATION;
@@ -69,7 +76,7 @@ class PersistableBundle {
        if (!mPBundle) {
            return STATUS_BAD_VALUE;
        }
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return APersistableBundle_writeToParcel(mPBundle, parcel);
        } else {
            return STATUS_INVALID_OPERATION;
@@ -84,7 +91,7 @@ class PersistableBundle {
     */
    void reset(APersistableBundle* _Nullable pBundle = nullptr) noexcept {
        if (mPBundle) {
            if (__builtin_available(android __ANDROID_API_V__, *)) {
            if AT_LEAST_V_OR_202404 {
                APersistableBundle_delete(mPBundle);
            }
            mPBundle = nullptr;
@@ -97,7 +104,7 @@ class PersistableBundle {
     * what should be used to check for equality.
     */
    bool deepEquals(const PersistableBundle& rhs) const {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return APersistableBundle_isEqual(get(), rhs.get());
        } else {
            return false;
@@ -136,7 +143,7 @@ class PersistableBundle {
    inline std::string toString() const {
        if (!mPBundle) {
            return "<PersistableBundle: null>";
        } else if (__builtin_available(android __ANDROID_API_V__, *)) {
        } else if AT_LEAST_V_OR_202404 {
            std::ostringstream os;
            os << "<PersistableBundle: ";
            os << "size: " << std::to_string(APersistableBundle_size(mPBundle));
@@ -147,7 +154,7 @@ class PersistableBundle {
    }

    int32_t size() const {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return APersistableBundle_size(mPBundle);
        } else {
            return 0;
@@ -155,7 +162,7 @@ class PersistableBundle {
    }

    int32_t erase(const std::string& key) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return APersistableBundle_erase(mPBundle, key.c_str());
        } else {
            return 0;
@@ -163,37 +170,37 @@ class PersistableBundle {
    }

    void putBoolean(const std::string& key, bool val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            APersistableBundle_putBoolean(mPBundle, key.c_str(), val);
        }
    }

    void putInt(const std::string& key, int32_t val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            APersistableBundle_putInt(mPBundle, key.c_str(), val);
        }
    }

    void putLong(const std::string& key, int64_t val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            APersistableBundle_putLong(mPBundle, key.c_str(), val);
        }
    }

    void putDouble(const std::string& key, double val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            APersistableBundle_putDouble(mPBundle, key.c_str(), val);
        }
    }

    void putString(const std::string& key, const std::string& val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            APersistableBundle_putString(mPBundle, key.c_str(), val.c_str());
        }
    }

    void putBooleanVector(const std::string& key, const std::vector<bool>& vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            // std::vector<bool> has no ::data().
            int32_t num = vec.size();
            if (num > 0) {
@@ -210,7 +217,7 @@ class PersistableBundle {
    }

    void putIntVector(const std::string& key, const std::vector<int32_t>& vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            int32_t num = vec.size();
            if (num > 0) {
                APersistableBundle_putIntVector(mPBundle, key.c_str(), vec.data(), num);
@@ -218,7 +225,7 @@ class PersistableBundle {
        }
    }
    void putLongVector(const std::string& key, const std::vector<int64_t>& vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            int32_t num = vec.size();
            if (num > 0) {
                APersistableBundle_putLongVector(mPBundle, key.c_str(), vec.data(), num);
@@ -226,7 +233,7 @@ class PersistableBundle {
        }
    }
    void putDoubleVector(const std::string& key, const std::vector<double>& vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            int32_t num = vec.size();
            if (num > 0) {
                APersistableBundle_putDoubleVector(mPBundle, key.c_str(), vec.data(), num);
@@ -234,7 +241,7 @@ class PersistableBundle {
        }
    }
    void putStringVector(const std::string& key, const std::vector<std::string>& vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            int32_t num = vec.size();
            if (num > 0) {
                char** inVec = (char**)malloc(num * sizeof(char*));
@@ -249,13 +256,13 @@ class PersistableBundle {
        }
    }
    void putPersistableBundle(const std::string& key, const PersistableBundle& pBundle) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            APersistableBundle_putPersistableBundle(mPBundle, key.c_str(), pBundle.mPBundle);
        }
    }

    bool getBoolean(const std::string& key, bool* _Nonnull val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return APersistableBundle_getBoolean(mPBundle, key.c_str(), val);
        } else {
            return false;
@@ -263,7 +270,7 @@ class PersistableBundle {
    }

    bool getInt(const std::string& key, int32_t* _Nonnull val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return APersistableBundle_getInt(mPBundle, key.c_str(), val);
        } else {
            return false;
@@ -271,7 +278,7 @@ class PersistableBundle {
    }

    bool getLong(const std::string& key, int64_t* _Nonnull val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return APersistableBundle_getLong(mPBundle, key.c_str(), val);
        } else {
            return false;
@@ -279,7 +286,7 @@ class PersistableBundle {
    }

    bool getDouble(const std::string& key, double* _Nonnull val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return APersistableBundle_getDouble(mPBundle, key.c_str(), val);
        } else {
            return false;
@@ -291,7 +298,7 @@ class PersistableBundle {
    }

    bool getString(const std::string& key, std::string* _Nonnull val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            char* outString = nullptr;
            bool ret = APersistableBundle_getString(mPBundle, key.c_str(), &outString,
                                                    &stringAllocator, nullptr);
@@ -309,7 +316,7 @@ class PersistableBundle {
                                                   const char* _Nonnull, T* _Nullable, int32_t),
                        const APersistableBundle* _Nonnull pBundle, const char* _Nonnull key,
                        std::vector<T>* _Nonnull vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            int32_t bytes = 0;
            // call first with nullptr to get required size in bytes
            bytes = getVec(pBundle, key, nullptr, 0);
@@ -331,28 +338,28 @@ class PersistableBundle {
    }

    bool getBooleanVector(const std::string& key, std::vector<bool>* _Nonnull vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getVecInternal<bool>(&APersistableBundle_getBooleanVector, mPBundle, key.c_str(),
                                        vec);
        }
        return false;
    }
    bool getIntVector(const std::string& key, std::vector<int32_t>* _Nonnull vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getVecInternal<int32_t>(&APersistableBundle_getIntVector, mPBundle, key.c_str(),
                                           vec);
        }
        return false;
    }
    bool getLongVector(const std::string& key, std::vector<int64_t>* _Nonnull vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getVecInternal<int64_t>(&APersistableBundle_getLongVector, mPBundle, key.c_str(),
                                           vec);
        }
        return false;
    }
    bool getDoubleVector(const std::string& key, std::vector<double>* _Nonnull vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getVecInternal<double>(&APersistableBundle_getDoubleVector, mPBundle,
                                          key.c_str(), vec);
        }
@@ -377,7 +384,7 @@ class PersistableBundle {
    }

    bool getStringVector(const std::string& key, std::vector<std::string>* _Nonnull vec) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            int32_t bytes = APersistableBundle_getStringVector(mPBundle, key.c_str(), nullptr, 0,
                                                               &stringAllocator, nullptr);
            if (bytes > 0) {
@@ -394,7 +401,7 @@ class PersistableBundle {
    }

    bool getPersistableBundle(const std::string& key, PersistableBundle* _Nonnull val) {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            APersistableBundle* bundle = nullptr;
            bool ret = APersistableBundle_getPersistableBundle(mPBundle, key.c_str(), &bundle);
            if (ret) {
@@ -426,77 +433,77 @@ class PersistableBundle {
    }

    std::set<std::string> getBooleanKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getBooleanKeys, mPBundle);
        } else {
            return {};
        }
    }
    std::set<std::string> getIntKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getIntKeys, mPBundle);
        } else {
            return {};
        }
    }
    std::set<std::string> getLongKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getLongKeys, mPBundle);
        } else {
            return {};
        }
    }
    std::set<std::string> getDoubleKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getDoubleKeys, mPBundle);
        } else {
            return {};
        }
    }
    std::set<std::string> getStringKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getStringKeys, mPBundle);
        } else {
            return {};
        }
    }
    std::set<std::string> getBooleanVectorKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getBooleanVectorKeys, mPBundle);
        } else {
            return {};
        }
    }
    std::set<std::string> getIntVectorKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getIntVectorKeys, mPBundle);
        } else {
            return {};
        }
    }
    std::set<std::string> getLongVectorKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getLongVectorKeys, mPBundle);
        } else {
            return {};
        }
    }
    std::set<std::string> getDoubleVectorKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getDoubleVectorKeys, mPBundle);
        } else {
            return {};
        }
    }
    std::set<std::string> getStringVectorKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getStringVectorKeys, mPBundle);
        } else {
            return {};
        }
    }
    std::set<std::string> getPersistableBundleKeys() {
        if (__builtin_available(android __ANDROID_API_V__, *)) {
        if AT_LEAST_V_OR_202404 {
            return getKeys(&APersistableBundle_getPersistableBundleKeys, mPBundle);
        } else {
            return {};
+88 −69

File changed.

Preview size limit exceeded, changes collapsed.