diff options
| author | 2019-12-17 23:14:45 +0000 | |
|---|---|---|
| committer | 2019-12-17 23:14:45 +0000 | |
| commit | a277a95497b6cf10da368311dfbc592fb28b8ce6 (patch) | |
| tree | 18866e7206db590b613d7659818c357c765e6d31 | |
| parent | 7b898192209db28796f3844db800ab984c36a9a8 (diff) | |
| parent | 1ea528acf1dafe0d20def59b18d27d969f4b6b0b (diff) | |
Merge "libbinder_ndk: add AStatus_getDescription" am: cb038369f8 am: 1ea528acf1
Change-Id: Ib1590ca5727e4596a81e4c8c186e784894e26b0c
| -rw-r--r-- | libs/binder/ndk/include_ndk/android/binder_auto_utils.h | 8 | ||||
| -rw-r--r-- | libs/binder/ndk/include_ndk/android/binder_status.h | 19 | ||||
| -rw-r--r-- | libs/binder/ndk/libbinder_ndk.map.txt | 2 | ||||
| -rw-r--r-- | libs/binder/ndk/status.cpp | 11 | ||||
| -rw-r--r-- | libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp | 3 |
5 files changed, 42 insertions, 1 deletions
diff --git a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h index 946ccb79a5..2b61cf18c2 100644 --- a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h +++ b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h @@ -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. */ diff --git a/libs/binder/ndk/include_ndk/android/binder_status.h b/libs/binder/ndk/include_ndk/android/binder_status.h index 78d70f87ba..ab9a144c53 100644 --- a/libs/binder/ndk/include_ndk/android/binder_status.h +++ b/libs/binder/ndk/include_ndk/android/binder_status.h @@ -247,6 +247,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. * * Available since API level 29. diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt index d59d6e42c6..71d8103161 100644 --- a/libs/binder/ndk/libbinder_ndk.map.txt +++ b/libs/binder/ndk/libbinder_ndk.map.txt @@ -103,6 +103,8 @@ LIBBINDER_NDK30 { # introduced=30 global: AIBinder_getExtension; AIBinder_setExtension; + AStatus_getDescription; + AStatus_deleteDescription; AIBinder_markSystemStability; # apex AIBinder_markVendorStability; # llndk diff --git a/libs/binder/ndk/status.cpp b/libs/binder/ndk/status.cpp index 1f75b0b05d..87e1341f36 100644 --- a/libs/binder/ndk/status.cpp +++ b/libs/binder/ndk/status.cpp @@ -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; } diff --git a/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp b/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp index d3ccdc2878..ad78e319a2 100644 --- a/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp +++ b/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp @@ -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; } } |