From 070f47dd7fd64c0c979a85a65c23fe559f65a6ed Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Thu, 6 Jan 2022 22:42:10 +0000 Subject: Make return values of IContextHub.aidl more consistent Follow the pattern of using well-defined AIDL error codes as return values for methods. Bug: 213474931 Test: Compile, run VTS Change-Id: If04d989cf504161638ec47b2302e60cbf32db502 --- contexthub/aidl/default/ContextHub.cpp | 73 ++++++++++++++-------------------- 1 file changed, 30 insertions(+), 43 deletions(-) (limited to 'contexthub/aidl/default/ContextHub.cpp') diff --git a/contexthub/aidl/default/ContextHub.cpp b/contexthub/aidl/default/ContextHub.cpp index 6da690da4f..4c23cbc8bf 100644 --- a/contexthub/aidl/default/ContextHub.cpp +++ b/contexthub/aidl/default/ContextHub.cpp @@ -21,7 +21,9 @@ namespace android { namespace hardware { namespace contexthub { -::ndk::ScopedAStatus ContextHub::getContextHubs(std::vector* out_contextHubInfos) { +using ::ndk::ScopedAStatus; + +ScopedAStatus ContextHub::getContextHubs(std::vector* out_contextHubInfos) { ContextHubInfo hub = {}; hub.name = "Mock Context Hub"; hub.vendor = "AOSP"; @@ -39,85 +41,70 @@ namespace contexthub { } // We don't expose any nanoapps for the default impl, therefore all nanoapp-related APIs fail. -::ndk::ScopedAStatus ContextHub::loadNanoapp(int32_t /* in_contextHubId */, - const NanoappBinary& /* in_appBinary */, - int32_t /* in_transactionId */, bool* _aidl_return) { - *_aidl_return = false; - return ndk::ScopedAStatus::ok(); +ScopedAStatus ContextHub::loadNanoapp(int32_t /* in_contextHubId */, + const NanoappBinary& /* in_appBinary */, + int32_t /* in_transactionId */) { + return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } -::ndk::ScopedAStatus ContextHub::unloadNanoapp(int32_t /* in_contextHubId */, - int64_t /* in_appId */, - int32_t /* in_transactionId */, bool* _aidl_return) { - *_aidl_return = false; - return ndk::ScopedAStatus::ok(); +ScopedAStatus ContextHub::unloadNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */, + int32_t /* in_transactionId */) { + return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } -::ndk::ScopedAStatus ContextHub::disableNanoapp(int32_t /* in_contextHubId */, - int64_t /* in_appId */, - int32_t /* in_transactionId */, - bool* _aidl_return) { - *_aidl_return = false; - return ndk::ScopedAStatus::ok(); +ScopedAStatus ContextHub::disableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */, + int32_t /* in_transactionId */) { + return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } -::ndk::ScopedAStatus ContextHub::enableNanoapp(int32_t /* in_contextHubId */, - int64_t /* in_appId */, - int32_t /* in_transactionId */, bool* _aidl_return) { - *_aidl_return = false; - return ndk::ScopedAStatus::ok(); +ScopedAStatus ContextHub::enableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */, + int32_t /* in_transactionId */) { + return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } -::ndk::ScopedAStatus ContextHub::onSettingChanged(Setting /* in_setting */, bool /*in_enabled */) { +ScopedAStatus ContextHub::onSettingChanged(Setting /* in_setting */, bool /*in_enabled */) { return ndk::ScopedAStatus::ok(); } -::ndk::ScopedAStatus ContextHub::queryNanoapps(int32_t in_contextHubId, bool* _aidl_return) { +ScopedAStatus ContextHub::queryNanoapps(int32_t in_contextHubId) { if (in_contextHubId == kMockHubId && mCallback != nullptr) { std::vector nanoapps; mCallback->handleNanoappInfo(nanoapps); - *_aidl_return = true; + return ndk::ScopedAStatus::ok(); } else { - *_aidl_return = false; + return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); } - - return ndk::ScopedAStatus::ok(); } -::ndk::ScopedAStatus ContextHub::registerCallback(int32_t in_contextHubId, - const std::shared_ptr& in_cb, - bool* _aidl_return) { +ScopedAStatus ContextHub::registerCallback(int32_t in_contextHubId, + const std::shared_ptr& in_cb) { if (in_contextHubId == kMockHubId) { mCallback = in_cb; - *_aidl_return = true; + return ndk::ScopedAStatus::ok(); } else { - *_aidl_return = false; + return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); } - return ndk::ScopedAStatus::ok(); } -::ndk::ScopedAStatus ContextHub::sendMessageToHub(int32_t in_contextHubId, - const ContextHubMessage& /* in_message */, - bool* _aidl_return) { +ScopedAStatus ContextHub::sendMessageToHub(int32_t in_contextHubId, + const ContextHubMessage& /* in_message */) { if (in_contextHubId == kMockHubId) { // Return true here to indicate that the HAL has accepted the message. // Successful delivery of the message to a nanoapp should be handled at // a higher level protocol. - *_aidl_return = true; + return ndk::ScopedAStatus::ok(); } else { - *_aidl_return = false; + return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); } - - return ndk::ScopedAStatus::ok(); } -::ndk::ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) { +ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) { mConnectedHostEndpoints.insert(in_info.hostEndpointId); return ndk::ScopedAStatus::ok(); } -::ndk::ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) { +ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) { if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) { mConnectedHostEndpoints.erase(in_hostEndpointId); return ndk::ScopedAStatus::ok(); -- cgit v1.2.3