LazyServiceRegistrar: Use defaultServiceManager
This is cleaner and more robust than partially reimplementing IServiceManager's code.
Bug: N/A
Test: aidl_lazy_test
Change-Id: I0fb696f5fb7c7d905ceb803d4cab898099aaaead
diff --git a/libs/binder/LazyServiceRegistrar.cpp b/libs/binder/LazyServiceRegistrar.cpp
index f064bd7..71d8130 100644
--- a/libs/binder/LazyServiceRegistrar.cpp
+++ b/libs/binder/LazyServiceRegistrar.cpp
@@ -64,8 +64,7 @@
bool ClientCounterCallback::registerService(const sp<IBinder>& service, const std::string& name,
bool allowIsolated, int dumpFlags) {
- auto manager = interface_cast<AidlServiceManager>(
- ProcessState::self()->getContextObject(nullptr));
+ auto manager = interface_cast<AidlServiceManager>(asBinder(defaultServiceManager()));
bool reRegister = mRegisteredServices.count(name) > 0;
std::string regStr = (reRegister) ? "Re-registering" : "Registering";
@@ -114,9 +113,7 @@
void ClientCounterCallback::tryShutdown() {
ALOGI("Trying to shut down the service. No clients in use for any service in process.");
- // This makes the same assumption as IServiceManager.cpp. Could dedupe if used in more places.
- auto manager = interface_cast<AidlServiceManager>(
- ProcessState::self()->getContextObject(nullptr));
+ auto manager = interface_cast<AidlServiceManager>(asBinder(defaultServiceManager()));
auto unRegisterIt = mRegisteredServices.begin();
for (; unRegisterIt != mRegisteredServices.end(); ++unRegisterIt) {