wifi: Add support for multiple chips in IWifi am: cd566bddd7
am: f7702fcfba
Change-Id: If6ca4867325da53ffe88f95d7046539cb903cd1c
This commit is contained in:
commit
e8ff1680f0
4 changed files with 37 additions and 10 deletions
|
@ -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 @@ Wifi::Wifi()
|
|||
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 @@ Return<void> Wifi::start() {
|
|||
}
|
||||
|
||||
// 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> Wifi::stop() {
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#define WIFI_H_
|
||||
|
||||
#include <functional>
|
||||
#include <set>
|
||||
|
||||
#include <android-base/macros.h>
|
||||
#include <android/hardware/wifi/1.0/IWifi.h>
|
||||
|
@ -46,7 +45,8 @@ class Wifi : public IWifi {
|
|||
Return<bool> isStarted() override;
|
||||
Return<void> start() override;
|
||||
Return<void> stop() override;
|
||||
Return<void> getChip(getChip_cb cb) override;
|
||||
Return<void> getChipIds(getChipIds_cb cb) override;
|
||||
Return<void> getChip(ChipId chip_id, getChip_cb cb) override;
|
||||
|
||||
private:
|
||||
enum class RunState { STOPPED, STARTED, STOPPING };
|
||||
|
@ -55,7 +55,7 @@ class Wifi : public IWifi {
|
|||
// and shared with all the child HIDL interface objects.
|
||||
std::shared_ptr<WifiLegacyHal> legacy_hal_;
|
||||
RunState run_state_;
|
||||
std::set<sp<IWifiEventCallback>> callbacks_;
|
||||
std::vector<sp<IWifiEventCallback>> callbacks_;
|
||||
sp<WifiChip> chip_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Wifi);
|
||||
|
|
|
@ -26,14 +26,19 @@ namespace wifi {
|
|||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
WifiChip::WifiChip(std::weak_ptr<WifiLegacyHal> legacy_hal)
|
||||
: legacy_hal_(legacy_hal) {}
|
||||
WifiChip::WifiChip(ChipId chip_id,
|
||||
const std::weak_ptr<WifiLegacyHal> legacy_hal)
|
||||
: chip_id_(chip_id), legacy_hal_(legacy_hal) {}
|
||||
|
||||
void WifiChip::invalidate() {
|
||||
legacy_hal_.reset();
|
||||
callbacks_.clear();
|
||||
}
|
||||
|
||||
Return<ChipId> WifiChip::getId() {
|
||||
return chip_id_;
|
||||
}
|
||||
|
||||
Return<void> WifiChip::registerEventCallback(
|
||||
const sp<IWifiChipEventCallback>& callback) {
|
||||
if (!legacy_hal_.lock())
|
||||
|
|
|
@ -37,11 +37,12 @@ namespace implementation {
|
|||
*/
|
||||
class WifiChip : public IWifiChip {
|
||||
public:
|
||||
WifiChip(std::weak_ptr<WifiLegacyHal> legacy_hal);
|
||||
WifiChip(ChipId chip_id, const std::weak_ptr<WifiLegacyHal> legacy_hal);
|
||||
// Invalidate this instance once the HAL is stopped.
|
||||
void invalidate();
|
||||
|
||||
// HIDL methods exposed.
|
||||
Return<ChipId> getId() override;
|
||||
Return<void> registerEventCallback(
|
||||
const sp<IWifiChipEventCallback>& callback) override;
|
||||
Return<void> getAvailableModes(getAvailableModes_cb cb) override;
|
||||
|
@ -52,6 +53,7 @@ class WifiChip : public IWifiChip {
|
|||
Return<void> requestFirmwareDebugDump() override;
|
||||
|
||||
private:
|
||||
ChipId chip_id_;
|
||||
std::weak_ptr<WifiLegacyHal> legacy_hal_;
|
||||
std::set<sp<IWifiChipEventCallback>> callbacks_;
|
||||
|
||||
|
|
Loading…
Reference in a new issue