Merge "Fix Legacy to AIDL conversion for link state" into udc-qpr-dev

This commit is contained in:
Mahesh KKV 2023-08-23 23:43:02 +00:00 committed by Android (Google) Code Review
commit d7175ec8e7
2 changed files with 26 additions and 0 deletions

View file

@ -887,6 +887,15 @@ bool convertLegacyLinkLayerRadioStatsToAidl(
return true;
}
StaLinkLayerLinkStats::StaLinkState convertLegacyMlLinkStateToAidl(wifi_link_state state) {
if (state == wifi_link_state::WIFI_LINK_STATE_NOT_IN_USE) {
return StaLinkLayerLinkStats::StaLinkState::NOT_IN_USE;
} else if (state == wifi_link_state::WIFI_LINK_STATE_IN_USE) {
return StaLinkLayerLinkStats::StaLinkState::IN_USE;
}
return StaLinkLayerLinkStats::StaLinkState::UNKNOWN;
}
bool convertLegacyLinkLayerMlStatsToAidl(const legacy_hal::LinkLayerMlStats& legacy_ml_stats,
StaLinkLayerStats* aidl_stats) {
if (!aidl_stats) {
@ -898,6 +907,7 @@ bool convertLegacyLinkLayerMlStatsToAidl(const legacy_hal::LinkLayerMlStats& leg
for (const auto& link : legacy_ml_stats.links) {
StaLinkLayerLinkStats linkStats = {};
linkStats.linkId = link.stat.link_id;
linkStats.state = convertLegacyMlLinkStateToAidl(link.stat.state);
linkStats.radioId = link.stat.radio;
linkStats.frequencyMhz = link.stat.frequency;
linkStats.beaconRx = link.stat.beacon_rx;

View file

@ -123,6 +123,9 @@ TEST_F(AidlStructUtilTest, canConvertLegacyLinkLayerMlStatsToAidl) {
// Add two radio stats
legacy_ml_stats.radios.push_back(legacy_hal::LinkLayerRadioStats{});
legacy_ml_stats.radios.push_back(legacy_hal::LinkLayerRadioStats{});
wifi_link_state states[sizeof(wifi_link_state)] = {wifi_link_state::WIFI_LINK_STATE_UNKNOWN,
wifi_link_state::WIFI_LINK_STATE_NOT_IN_USE,
wifi_link_state::WIFI_LINK_STATE_IN_USE};
// Add two links.
legacy_ml_stats.links.push_back(legacy_hal::LinkStats{});
legacy_ml_stats.links.push_back(legacy_hal::LinkStats{});
@ -133,6 +136,7 @@ TEST_F(AidlStructUtilTest, canConvertLegacyLinkLayerMlStatsToAidl) {
link.stat.beacon_rx = rand();
// MLO link id: 0 - 15
link.stat.link_id = rand() % 16;
link.stat.state = states[rand() % sizeof(states)];
// Maximum number of radios is limited to 3 for testing.
link.stat.radio = rand() % 4;
link.stat.frequency = rand();
@ -241,6 +245,18 @@ TEST_F(AidlStructUtilTest, canConvertLegacyLinkLayerMlStatsToAidl) {
int l = 0;
for (legacy_hal::LinkStats& link : legacy_ml_stats.links) {
EXPECT_EQ(link.stat.link_id, (uint8_t)converted.iface.links[l].linkId);
StaLinkLayerLinkStats::StaLinkState expectedState;
switch (link.stat.state) {
case wifi_link_state::WIFI_LINK_STATE_NOT_IN_USE:
expectedState = StaLinkLayerLinkStats::StaLinkState::NOT_IN_USE;
break;
case wifi_link_state::WIFI_LINK_STATE_IN_USE:
expectedState = StaLinkLayerLinkStats::StaLinkState::IN_USE;
break;
default:
expectedState = StaLinkLayerLinkStats::StaLinkState::UNKNOWN;
}
EXPECT_EQ(expectedState, converted.iface.links[l].state);
EXPECT_EQ(link.stat.radio, converted.iface.links[l].radioId);
EXPECT_EQ(link.stat.frequency, (uint32_t)converted.iface.links[l].frequencyMhz);
EXPECT_EQ(link.stat.beacon_rx, (uint32_t)converted.iface.links[l].beaconRx);