wifi(implementation): Callback death handler
Add a new utility to handle callback death notifications. The new class
HidlCallbackHandler will be used by all the HIDL interface objects to
manage callbacks. Any dead clients will automatically removed from the
cb list by the utility class.
Bug: 34840719
Test: Compiles
Test: Verified that the cbs are deleted on crashing the framework
manually
Change-Id: I0f7ba8b3ed717c2e8e8fbf744a2501d0ad2d48c8
diff --git a/wifi/1.0/default/wifi.cpp b/wifi/1.0/default/wifi.cpp
index 8feb836..3d482b4 100644
--- a/wifi/1.0/default/wifi.cpp
+++ b/wifi/1.0/default/wifi.cpp
@@ -85,8 +85,9 @@
WifiStatus Wifi::registerEventCallbackInternal(
const sp<IWifiEventCallback>& event_callback) {
- // TODO(b/31632518): remove the callback when the client is destroyed
- event_callbacks_.emplace_back(event_callback);
+ if (!event_cb_handler_.addCallback(event_callback)) {
+ return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
+ }
return createWifiStatus(WifiStatusCode::SUCCESS);
}
@@ -102,13 +103,13 @@
// Create the chip instance once the HAL is started.
chip_ = new WifiChip(kChipId, legacy_hal_, mode_controller_);
run_state_ = RunState::STARTED;
- for (const auto& callback : event_callbacks_) {
+ for (const auto& callback : event_cb_handler_.getCallbacks()) {
if (!callback->onStart().isOk()) {
LOG(ERROR) << "Failed to invoke onStart callback";
};
}
} else {
- for (const auto& callback : event_callbacks_) {
+ for (const auto& callback : event_cb_handler_.getCallbacks()) {
if (!callback->onFailure(wifi_status).isOk()) {
LOG(ERROR) << "Failed to invoke onFailure callback";
}
@@ -126,13 +127,13 @@
}
WifiStatus wifi_status = stopLegacyHalAndDeinitializeModeController();
if (wifi_status.code == WifiStatusCode::SUCCESS) {
- for (const auto& callback : event_callbacks_) {
+ for (const auto& callback : event_cb_handler_.getCallbacks()) {
if (!callback->onStop().isOk()) {
LOG(ERROR) << "Failed to invoke onStop callback";
};
}
} else {
- for (const auto& callback : event_callbacks_) {
+ for (const auto& callback : event_cb_handler_.getCallbacks()) {
if (!callback->onFailure(wifi_status).isOk()) {
LOG(ERROR) << "Failed to invoke onFailure callback";
}