Fix DeathRecipient not work problem for UnsolicitedEventListener
linkToDeath of binder only use weak pointer ref for deathRecipient.
Hence local variable deathRecipient would destruct immediately after
registerUnsolEventListener function done.
Use a map to store all deathRecipient.
Bug: 129370555
Test: built, flashed, booted
system/netd/tests/runtests.sh pass
Change-Id: I1829222dc071e237974033559bfbcce72b05d3fb
diff --git a/server/NetlinkHandler.cpp b/server/NetlinkHandler.cpp
index 0354fca..7fb3437 100644
--- a/server/NetlinkHandler.cpp
+++ b/server/NetlinkHandler.cpp
@@ -51,15 +51,15 @@
res; \
})
-#define LOG_EVENT_FUNC(retry, func, ...) \
- do { \
- const auto listeners = gCtls->eventReporter.getNetdUnsolicitedEventListeners(); \
- for (auto& listener : listeners) { \
- auto entry = gUnsolicitedLog.newEntry().function(#func).args(__VA_ARGS__); \
- if (retry(listener->func(__VA_ARGS__))) { \
- gUnsolicitedLog.log(entry.withAutomaticDuration()); \
- } \
- } \
+#define LOG_EVENT_FUNC(retry, func, ...) \
+ do { \
+ const auto listenerMap = gCtls->eventReporter.getNetdUnsolicitedEventListenerMap(); \
+ for (auto& listener : listenerMap) { \
+ auto entry = gUnsolicitedLog.newEntry().function(#func).args(__VA_ARGS__); \
+ if (retry(listener.first->func(__VA_ARGS__))) { \
+ gUnsolicitedLog.log(entry.withAutomaticDuration()); \
+ } \
+ } \
} while (0)
namespace android {