From 85c6441fbaede1985eeaf89442f79fe8a323e33d Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Mon, 22 Jan 2018 17:58:40 -0800 Subject: [PATCH] wifi(implementation): Invoke radio mode change callbacks Bug: 68349158 Test: Compiles Change-Id: I319ef33775069bf10abe449670e8f0d50de746e3 --- wifi/1.2/default/wifi_chip.cpp | 37 ++++++++++++++++++++++++++++++++++ wifi/1.2/default/wifi_chip.h | 1 + 2 files changed, 38 insertions(+) diff --git a/wifi/1.2/default/wifi_chip.cpp b/wifi/1.2/default/wifi_chip.cpp index a4b52b9b75..38301e96fa 100644 --- a/wifi/1.2/default/wifi_chip.cpp +++ b/wifi/1.2/default/wifi_chip.cpp @@ -1044,6 +1044,13 @@ WifiStatus WifiChip::handleChipConfiguration( << legacyErrorToString(legacy_status); return createWifiStatusFromLegacyError(legacy_status); } + // Every time the HAL is restarted, we need to register the + // radio mode change callback. + WifiStatus status = registerRadioModeChangeCallback(); + if (status.code != WifiStatusCode::SUCCESS) { + // This probably is not a critical failure? + LOG(ERROR) << "Failed to register radio mode change callback"; + } return createWifiStatus(WifiStatusCode::SUCCESS); } @@ -1087,6 +1094,36 @@ WifiStatus WifiChip::registerDebugRingBufferCallback() { return createWifiStatusFromLegacyError(legacy_status); } +WifiStatus WifiChip::registerRadioModeChangeCallback() { + android::wp weak_ptr_this(this); + const auto& on_radio_mode_change_callback = + [weak_ptr_this](const std::vector& mac_infos) { + const auto shared_ptr_this = weak_ptr_this.promote(); + if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { + LOG(ERROR) << "Callback invoked on an invalid object"; + return; + } + std::vector + hidl_radio_mode_infos; + if (!hidl_struct_util::convertLegacyWifiMacInfosToHidl( + mac_infos, &hidl_radio_mode_infos)) { + LOG(ERROR) << "Error converting wifi mac info"; + return; + } + for (const auto& callback : shared_ptr_this->getEventCallbacks()) { + if (!callback->onRadioModeChange(hidl_radio_mode_infos) + .isOk()) { + LOG(ERROR) << "Failed to invoke onRadioModeChange" + << " callback on: " << toString(callback); + } + } + }; + legacy_hal::wifi_error legacy_status = + legacy_hal_.lock()->registerRadioModeChangeCallbackHandler( + getWlan0IfaceName(), on_radio_mode_change_callback); + return createWifiStatusFromLegacyError(legacy_status); +} + void WifiChip::populateModes() { // The chip combination supported for current devices is fixed. // They can be one of the following based on device features: diff --git a/wifi/1.2/default/wifi_chip.h b/wifi/1.2/default/wifi_chip.h index c51f6b1e27..24a5486276 100644 --- a/wifi/1.2/default/wifi_chip.h +++ b/wifi/1.2/default/wifi_chip.h @@ -201,6 +201,7 @@ class WifiChip : public V1_2::IWifiChip { WifiStatus handleChipConfiguration( std::unique_lock* lock, ChipModeId mode_id); WifiStatus registerDebugRingBufferCallback(); + WifiStatus registerRadioModeChangeCallback(); void populateModes(); std::vector