diff options
author | Jooyung Han <jooyung@google.com> | 2023-12-29 16:49:43 +0900 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-01-04 00:54:14 +0000 |
commit | 4009a41cdc770b63cd65f42aa820fbd821beab76 (patch) | |
tree | e7f31917f28b7f0bf617e555de1c3ca4e751e8da | |
parent | 1528f5da3f475dda69073e871d0b36f4a6ee1f3a (diff) | |
download | native-4009a41cdc770b63cd65f42aa820fbd821beab76.tar.gz |
Reapply "Guard new APIs with __builtin_available"
This reverts commit 027650fb9f4a54a1848f062e9944cd845651208d.
Ignore-AOSP-First: this is for 24q1-release
Bug: 317676192
Test: manual check (wifi hal service should work with U GSI)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e40a10779c74290c504a38799f81eb6e0a06610d)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:fde6b58b4f9efb8998364f2bcfa51cc1c1e48834)
Merged-In: I0211eb1f7f8c74a43143cbed7c32c065eabf39ed
Change-Id: I0211eb1f7f8c74a43143cbed7c32c065eabf39ed
-rw-r--r-- | libs/binder/ndk/include_cpp/android/persistable_bundle_aidl.h | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/libs/binder/ndk/include_cpp/android/persistable_bundle_aidl.h b/libs/binder/ndk/include_cpp/android/persistable_bundle_aidl.h index f178027b35..a0e4f7b63b 100644 --- a/libs/binder/ndk/include_cpp/android/persistable_bundle_aidl.h +++ b/libs/binder/ndk/include_cpp/android/persistable_bundle_aidl.h @@ -31,7 +31,11 @@ namespace aidl::android::os { */ class PersistableBundle { public: - PersistableBundle() noexcept : mPBundle(APersistableBundle_new()) {} + PersistableBundle() noexcept { + if (__builtin_available(android __ANDROID_API_V__, *)) { + mPBundle = APersistableBundle_new(); + } + } // takes ownership of the APersistableBundle* PersistableBundle(APersistableBundle* _Nonnull bundle) noexcept : mPBundle(bundle) {} // takes ownership of the APersistableBundle* @@ -327,20 +331,32 @@ class PersistableBundle { } bool getBooleanVector(const std::string& key, std::vector<bool>* _Nonnull vec) { - return getVecInternal<bool>(&APersistableBundle_getBooleanVector, mPBundle, key.c_str(), - vec); + if (__builtin_available(android __ANDROID_API_V__, *)) { + return getVecInternal<bool>(&APersistableBundle_getBooleanVector, mPBundle, key.c_str(), + vec); + } + return false; } bool getIntVector(const std::string& key, std::vector<int32_t>* _Nonnull vec) { - return getVecInternal<int32_t>(&APersistableBundle_getIntVector, mPBundle, key.c_str(), - vec); + if (__builtin_available(android __ANDROID_API_V__, *)) { + 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) { - return getVecInternal<int64_t>(&APersistableBundle_getLongVector, mPBundle, key.c_str(), - vec); + if (__builtin_available(android __ANDROID_API_V__, *)) { + return getVecInternal<int64_t>(&APersistableBundle_getLongVector, mPBundle, key.c_str(), + vec); + } + return false; } bool getDoubleVector(const std::string& key, std::vector<double>* _Nonnull vec) { - return getVecInternal<double>(&APersistableBundle_getDoubleVector, mPBundle, key.c_str(), - vec); + if (__builtin_available(android __ANDROID_API_V__, *)) { + return getVecInternal<double>(&APersistableBundle_getDoubleVector, mPBundle, + key.c_str(), vec); + } + return false; } // Takes ownership of and frees the char** and its elements. @@ -361,15 +377,17 @@ class PersistableBundle { } bool getStringVector(const std::string& key, std::vector<std::string>* _Nonnull vec) { - int32_t bytes = APersistableBundle_getStringVector(mPBundle, key.c_str(), nullptr, 0, - &stringAllocator, nullptr); - if (bytes > 0) { - char** strings = (char**)malloc(bytes); - if (strings) { - bytes = APersistableBundle_getStringVector(mPBundle, key.c_str(), strings, bytes, - &stringAllocator, nullptr); - *vec = moveStringsInternal<std::vector<std::string>>(strings, bytes); - return true; + if (__builtin_available(android __ANDROID_API_V__, *)) { + int32_t bytes = APersistableBundle_getStringVector(mPBundle, key.c_str(), nullptr, 0, + &stringAllocator, nullptr); + if (bytes > 0) { + char** strings = (char**)malloc(bytes); + if (strings) { + bytes = APersistableBundle_getStringVector(mPBundle, key.c_str(), strings, + bytes, &stringAllocator, nullptr); + *vec = moveStringsInternal<std::vector<std::string>>(strings, bytes); + return true; + } } } return false; |