wifi: Add support for multiple chips in IWifi
The modified HIDL interface supports multiple chip instances on the
device. Modify the |IWifi| interface implementation to support the new
methods.
NOTE: The legacy HAL implementation will continue to only expose 1 chip.
While there,
Change the |callbacks_| member to std::vector instead of std::set. We
don't really need a set to store the list of callbacks.
Bug: 32003988
Test: Compiles
Change-Id: I31e704100f716e223095890279bdf93d2a04377e
diff --git a/wifi/1.0/default/wifi.cpp b/wifi/1.0/default/wifi.cpp
index d5b69b8..ff2eb4c 100644
--- a/wifi/1.0/default/wifi.cpp
+++ b/wifi/1.0/default/wifi.cpp
@@ -21,6 +21,11 @@
#include "failure_reason_util.h"
#include "wifi_chip.h"
+namespace {
+// Chip ID to use for the only supported chip.
+static constexpr android::hardware::wifi::V1_0::ChipId kChipId = 0;
+} // namespace
+
namespace android {
namespace hardware {
namespace wifi {
@@ -33,7 +38,7 @@
Return<void> Wifi::registerEventCallback(
const sp<IWifiEventCallback>& callback) {
// TODO(b/31632518): remove the callback when the client is destroyed
- callbacks_.insert(callback);
+ callbacks_.emplace_back(callback);
return Void();
}
@@ -67,7 +72,7 @@
}
// Create the chip instance once the HAL is started.
- chip_ = new WifiChip(legacy_hal_);
+ chip_ = new WifiChip(kChipId, legacy_hal_);
run_state_ = RunState::STARTED;
for (const auto& callback : callbacks_) {
callback->onStart();
@@ -108,8 +113,23 @@
return Void();
}
-Return<void> Wifi::getChip(getChip_cb cb) {
- cb(chip_);
+Return<void> Wifi::getChipIds(getChipIds_cb cb) {
+ std::vector<ChipId> chip_ids;
+ if (chip_.get()) {
+ chip_ids.emplace_back(kChipId);
+ }
+ hidl_vec<ChipId> hidl_data;
+ hidl_data.setToExternal(chip_ids.data(), chip_ids.size());
+ cb(hidl_data);
+ return Void();
+}
+
+Return<void> Wifi::getChip(ChipId chip_id, getChip_cb cb) {
+ if (chip_.get() && chip_id == kChipId) {
+ cb(chip_);
+ } else {
+ cb(nullptr);
+ }
return Void();
}