diff options
| author | 2019-09-09 20:13:10 -0700 | |
|---|---|---|
| committer | 2019-09-09 20:13:10 -0700 | |
| commit | 1390c726cd249ec24e270a2f3630ccdb90fc4ffb (patch) | |
| tree | 019387f4de96703f324e6d0d484d5fb1abb02623 /cmds/servicemanager/ServiceManager.cpp | |
| parent | 38ec9e4340b5835966470f93870d7c734bfe7b4f (diff) | |
| parent | 8c8b131b29aba3624a205e7aa17b9001a956e2d9 (diff) | |
Merge "ServiceManager signals init to start lazy services" am: 66050ee75e am: 94ddc1694a
am: 8c8b131b29
Change-Id: I083897a9b87a754ab805e0a7cf86df5b8bca8ad3
Diffstat (limited to 'cmds/servicemanager/ServiceManager.cpp')
| -rw-r--r-- | cmds/servicemanager/ServiceManager.cpp | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp index b3aa342a19..463d67f945 100644 --- a/cmds/servicemanager/ServiceManager.cpp +++ b/cmds/servicemanager/ServiceManager.cpp @@ -17,8 +17,10 @@ #include "ServiceManager.h" #include <android-base/logging.h> +#include <android-base/properties.h> #include <cutils/android_filesystem_config.h> #include <cutils/multiuser.h> +#include <thread> using ::android::binder::Status; @@ -41,39 +43,44 @@ ServiceManager::~ServiceManager() { } Status ServiceManager::getService(const std::string& name, sp<IBinder>* outBinder) { - // Servicemanager is single-threaded and cannot block. This method exists for legacy reasons. - return checkService(name, outBinder); + *outBinder = tryGetService(name, true); + // returns ok regardless of result for legacy reasons + return Status::ok(); } Status ServiceManager::checkService(const std::string& name, sp<IBinder>* outBinder) { - auto ctx = mAccess->getCallingContext(); + *outBinder = tryGetService(name, false); + // returns ok regardless of result for legacy reasons + return Status::ok(); +} - auto it = mNameToService.find(name); - if (it == mNameToService.end()) { - *outBinder = nullptr; - return Status::ok(); - } +sp<IBinder> ServiceManager::tryGetService(const std::string& name, bool startIfNotFound) { + auto ctx = mAccess->getCallingContext(); - const Service& service = it->second; + sp<IBinder> out; + if (auto it = mNameToService.find(name); it != mNameToService.end()) { + const Service& service = it->second; - if (!service.allowIsolated) { - uid_t appid = multiuser_get_app_id(ctx.uid); - bool isIsolated = appid >= AID_ISOLATED_START && appid <= AID_ISOLATED_END; + if (!service.allowIsolated) { + uid_t appid = multiuser_get_app_id(ctx.uid); + bool isIsolated = appid >= AID_ISOLATED_START && appid <= AID_ISOLATED_END; - if (isIsolated) { - *outBinder = nullptr; - return Status::ok(); + if (isIsolated) { + return nullptr; + } } + out = service.binder; } if (!mAccess->canFind(ctx, name)) { - // returns ok and null for legacy reasons - *outBinder = nullptr; - return Status::ok(); + return nullptr; } - *outBinder = service.binder; - return Status::ok(); + if (!out && startIfNotFound) { + tryStartService(name); + } + + return out; } bool isValidServiceName(const std::string& name) { @@ -253,4 +260,13 @@ void ServiceManager::binderDied(const wp<IBinder>& who) { } } +void ServiceManager::tryStartService(const std::string& name) { + ALOGI("Since '%s' could not be found, trying to start it as a lazy AIDL service", + name.c_str()); + + std::thread([=] { + (void)base::SetProperty("ctl.interface_start", "aidl/" + name); + }).detach(); +} + } // namespace android |