From b82b8f84b48616c124e1d1421a985328c1df53dc Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Mon, 28 Oct 2019 10:52:34 -0700 Subject: ServiceManager: add isDeclared Most of the time, AIDL services exist in client/service pairs. In this context, `while(true) getService` or `waitForService` makes sense. However, for VINTF services, this client/server coupling isn't guaranteed. A device may or may not have specific hardware. So, now IServiceManager can tell a client when a server will exist so it will know if it needs to wait for this service during boot-up. The function waitForDeclaredService is provided for this. These functions are generic (not referring to VINTF specifically) because they may be expanded to include information about APEX services in the future OR the infrastructure may be made generic to work, if desired, on system services. Bug: 141828236 Test: binderStabilityTest, using waitForDeclaredService function Change-Id: Ia230625e44e1685cc3fa9230ece8f0a25c88585e --- cmds/servicemanager/ServiceManager.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'cmds/servicemanager/ServiceManager.cpp') diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp index 934646da41..91e89ae7e8 100644 --- a/cmds/servicemanager/ServiceManager.cpp +++ b/cmds/servicemanager/ServiceManager.cpp @@ -34,11 +34,7 @@ using ::android::internal::Stability; namespace android { #ifndef VENDORSERVICEMANAGER -static bool meetsDeclarationRequirements(const sp& binder, const std::string& name) { - if (!Stability::requiresVintfDeclaration(binder)) { - return true; - } - +static bool isVintfDeclared(const std::string& name) { size_t firstSlash = name.find('/'); size_t lastDot = name.rfind('.', firstSlash); if (firstSlash == std::string::npos || lastDot == std::string::npos) { @@ -62,6 +58,14 @@ static bool meetsDeclarationRequirements(const sp& binder, const std::s << " in the VINTF manifest."; return false; } + +static bool meetsDeclarationRequirements(const sp& binder, const std::string& name) { + if (!Stability::requiresVintfDeclaration(binder)) { + return true; + } + + return isVintfDeclared(name); +} #endif // !VENDORSERVICEMANAGER ServiceManager::ServiceManager(std::unique_ptr&& access) : mAccess(std::move(access)) {} @@ -270,6 +274,21 @@ Status ServiceManager::unregisterForNotifications( return Status::ok(); } +Status ServiceManager::isDeclared(const std::string& name, bool* outReturn) { + auto ctx = mAccess->getCallingContext(); + + if (!mAccess->canFind(ctx, name)) { + return Status::fromExceptionCode(Status::EX_SECURITY); + } + + *outReturn = false; + +#ifndef VENDORSERVICEMANAGER + *outReturn = isVintfDeclared(name); +#endif + return Status::ok(); +} + void ServiceManager::removeCallback(const wp& who, CallbackMap::iterator* it, bool* found) { -- cgit v1.2.3-59-g8ed1b