From dd511058abd4c8014aba989c78584639cc65fb8d Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Thu, 29 Dec 2022 00:34:24 +0000 Subject: libbinder*: IBinder/IInterface toString impl Bug: 259162245 Test: N/A Change-Id: If612cbd323e5d35b87bec5144b7e35358d718be1 --- .../ndk/include_cpp/android/binder_to_string.h | 46 +++++++++------------- 1 file changed, 19 insertions(+), 27 deletions(-) (limited to 'libs') diff --git a/libs/binder/ndk/include_cpp/android/binder_to_string.h b/libs/binder/ndk/include_cpp/android/binder_to_string.h index 9b0d222147..b0c7f6d4a9 100644 --- a/libs/binder/ndk/include_cpp/android/binder_to_string.h +++ b/libs/binder/ndk/include_cpp/android/binder_to_string.h @@ -138,30 +138,6 @@ class IsIterable { enum { value = decltype(_test<_T>(0))::value }; }; -template -class ToEmptyString { - template - static std::enable_if_t -#if __ANDROID_API__ >= 31 - || std::is_same_v<::ndk::AParcelableHolder, _U> -#endif -#endif // HAS_NDK_INTERFACE -#ifdef HAS_CPP_INTERFACE - || std::is_base_of_v || - std::is_same_v -#endif - , - std::true_type> - _test(int); - template - static std::false_type _test(...); - - public: - enum { value = decltype(_test<_T>(0))::value }; -}; - template struct TypeDependentFalse { enum { value = false }; @@ -171,9 +147,7 @@ struct TypeDependentFalse { template std::string ToString(const _T& t) { - if constexpr (details::ToEmptyString<_T>::value) { - return ""; - } else if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { return t ? "true" : "false"; } else if constexpr (std::is_same_v) { // TODO(b/244494451): codecvt is deprecated in C++17 -- suppress the @@ -193,6 +167,24 @@ std::string ToString(const _T& t) { return ss.str(); } else if constexpr (std::is_same_v<::ndk::ScopedFileDescriptor, _T>) { return "fd:" + std::to_string(t.get()); + } else if constexpr (std::is_base_of_v<::ndk::ICInterface, _T>) { + // TODO(b/266248339): this format is to make it easy to handle resolv_integration_test + // freezing the output format. We would like to print more info. + return ""; +#if __ANDROID_API__ >= 31 + } else if constexpr (std::is_same_v<::ndk::AParcelableHolder, _T>) { + return "AParcelableHolder"; +#endif +#endif // HAS_NDK_INTERFACE +#ifdef HAS_CPP_INTERFACE + } else if constexpr (std::is_base_of_v) { + std::stringstream ss; + ss << "interface:" << std::hex << &t; + return ss.str(); + } else if constexpr (std::is_same_v) { + std::stringstream ss; + ss << "binder:" << std::hex << &t; + return ss.str(); #endif #ifdef HAS_STRING16 } else if constexpr (std::is_same_v) { -- cgit v1.2.3-59-g8ed1b