Unregister service notification callbacks that are gone.
Bug: 33818175
Test: hidl_test
Change-Id: Icc2bc70c8d423aaa99ba8df41e0cefdc19217b9d
diff --git a/HidlService.cpp b/HidlService.cpp
index 7688dc3..2898411 100644
--- a/HidlService.cpp
+++ b/HidlService.cpp
@@ -48,7 +48,7 @@
return ss.str();
}
-void HidlService::sendRegistrationNotifications() const {
+void HidlService::sendRegistrationNotifications() {
if (mListeners.size() == 0 || mService == nullptr) {
return;
}
@@ -56,9 +56,13 @@
hidl_string iface = mInterfaceName;
hidl_string name = mInstanceName;
- for (const auto &listener : mListeners) {
- auto ret = listener->onRegistration(iface, name, false /* preexisting */);
- ret.isOk(); // ignore result
+ for (auto it = mListeners.begin(); it != mListeners.end();) {
+ auto ret = (*it)->onRegistration(iface, name, false /* preexisting */);
+ if (ret.isOk()) {
+ ++it;
+ } else {
+ it = mListeners.erase(it);
+ }
}
}