diff options
author | 2024-10-23 19:29:49 +0000 | |
---|---|---|
committer | 2025-01-03 21:37:10 +0000 | |
commit | a3867c739a80d0c8a58dcb00bcae8f98afdc78ef (patch) | |
tree | 5bf41f147391b2bc923398563857c6a4d814c892 /libs/binder/BackendUnifiedServiceManager.cpp | |
parent | 3c93111ce80d2d7ea3375c39d75bf7dd54f3e15b (diff) |
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
Diffstat (limited to 'libs/binder/BackendUnifiedServiceManager.cpp')
-rw-r--r-- | libs/binder/BackendUnifiedServiceManager.cpp | 47 |
1 files changed, 38 insertions, 9 deletions
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 <android-base/strings.h> #include <android/os/IAccessor.h> #include <android/os/IServiceManager.h> #include <binder/RpcSession.h> @@ -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<os::IServiceCallback>& 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 + // <interface>/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) { |