summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2023-04-13 20:29:33 +0000
committer Steven Moreland <smoreland@google.com> 2023-04-14 01:26:26 +0000
commit7bb4ab864585475690b4ef73ee1cc691c85231e5 (patch)
tree4aad8bd75392fbc1e02fa4766bcad75f557d8381
parentba9df0b0dee1bbce3d29d99203c4e835f255408a (diff)
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
-rw-r--r--cmds/servicemanager/ServiceManager.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp
index 980682d425..56c9d4688b 100644
--- a/cmds/servicemanager/ServiceManager.cpp
+++ b/cmds/servicemanager/ServiceManager.cpp
@@ -690,6 +690,11 @@ Status ServiceManager::registerClientCallback(const std::string& name, const sp<
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();