lazy AIDL services: multiple callbacks
This guarantees that client callbacks will get notified
that there are clients, if they are added to
servicemanager after a service notification has already
been sent. Typically, in Android, only one client
callback is used at a time, registered from the service
that is lazy itself. However, if a service quits and then
is restarted quickly, the old client callback wouldn't
be cleared, and so the notification was getting sent to
that callback instead of the new one.
Now, when the new callback is added, it gets the service
notification.
One possible other implementation of this would be to
unregister client callbacks implicitly when services
are unregistered. However, this may break other uses
of client callbacks in the future, so instead in this
case, we choose to keep all the client callbacks in a
consistent state (even though again, it should only
happen when there is a race).
aidl_lazy_test is updated above this CL
Bug: 278038751
Test: aidl_lazy_test
Change-Id: Ib9e69679a3c9c7e62c5c4fc4893cad2dd1c5e8fe
diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp
index 980682d..56c9d46 100644
--- a/cmds/servicemanager/ServiceManager.cpp
+++ b/cmds/servicemanager/ServiceManager.cpp
@@ -690,6 +690,11 @@
return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Couldn't linkToDeath.");
}
+ // make sure all callbacks have been told about a consistent state - b/278038751
+ if (serviceIt->second.hasClients) {
+ cb->onClients(service, true);
+ }
+
mNameToClientCallback[name].push_back(cb);
return Status::ok();