From a3867c739a80d0c8a58dcb00bcae8f98afdc78ef Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Wed, 23 Oct 2024 19:29:49 +0000 Subject: Add listServices/isDeclared/getDeclaredInstances for Accessors We associate specific accessors with instance names, so we can get more information about what is available through the existing service manager APIs. Test: atest binderRpcTest Bug: 358427181 Change-Id: I337430a222b537643351bfc70178ccd1dc06d73b --- libs/binder/BackendUnifiedServiceManager.cpp | 47 ++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 9 deletions(-) (limited to 'libs/binder/BackendUnifiedServiceManager.cpp') diff --git a/libs/binder/BackendUnifiedServiceManager.cpp b/libs/binder/BackendUnifiedServiceManager.cpp index 9d0a557f4e..ee3d6af742 100644 --- a/libs/binder/BackendUnifiedServiceManager.cpp +++ b/libs/binder/BackendUnifiedServiceManager.cpp @@ -15,6 +15,7 @@ */ #include "BackendUnifiedServiceManager.h" +#include #include #include #include @@ -339,11 +340,15 @@ Status BackendUnifiedServiceManager::addService(const ::std::string& name, } Status BackendUnifiedServiceManager::listServices(int32_t dumpPriority, ::std::vector<::std::string>* _aidl_return) { + Status status = Status::ok(); if (mTheRealServiceManager) { - return mTheRealServiceManager->listServices(dumpPriority, _aidl_return); + status = mTheRealServiceManager->listServices(dumpPriority, _aidl_return); } - return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION, - kUnsupportedOpNoServiceManager); + if (!status.isOk()) return status; + + appendInjectedAccessorServices(_aidl_return); + + return status; } Status BackendUnifiedServiceManager::registerForNotifications( const ::std::string& name, const sp& callback) { @@ -362,19 +367,43 @@ Status BackendUnifiedServiceManager::unregisterForNotifications( kUnsupportedOpNoServiceManager); } Status BackendUnifiedServiceManager::isDeclared(const ::std::string& name, bool* _aidl_return) { + Status status = Status::ok(); if (mTheRealServiceManager) { - return mTheRealServiceManager->isDeclared(name, _aidl_return); + status = mTheRealServiceManager->isDeclared(name, _aidl_return); } - return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION, - kUnsupportedOpNoServiceManager); + if (!status.isOk()) return status; + + if (!*_aidl_return) { + forEachInjectedAccessorService([&](const std::string& instance) { + if (name == instance) { + *_aidl_return = true; + } + }); + } + + return status; } Status BackendUnifiedServiceManager::getDeclaredInstances( const ::std::string& iface, ::std::vector<::std::string>* _aidl_return) { + Status status = Status::ok(); if (mTheRealServiceManager) { - return mTheRealServiceManager->getDeclaredInstances(iface, _aidl_return); + status = mTheRealServiceManager->getDeclaredInstances(iface, _aidl_return); } - return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION, - kUnsupportedOpNoServiceManager); + if (!status.isOk()) return status; + + forEachInjectedAccessorService([&](const std::string& instance) { + // Declared instances have the format + // /instance like foo.bar.ISomething/instance + // If it does not have that format, consider the instance to be "" + std::string_view name(instance); + if (base::ConsumePrefix(&name, iface + "/")) { + _aidl_return->emplace_back(name); + } else if (iface == instance) { + _aidl_return->push_back(""); + } + }); + + return status; } Status BackendUnifiedServiceManager::updatableViaApex( const ::std::string& name, ::std::optional<::std::string>* _aidl_return) { -- cgit v1.2.3-59-g8ed1b