mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
BWU Hotspot Responder(client) need to disconnect Hotspot when the session is done
PiperOrigin-RevId: 460577462
This commit is contained in:
@@ -75,6 +75,10 @@ void BaseBwuHandler::RevertInitiatorState(const std::string& upgrade_service_id,
|
||||
}
|
||||
}
|
||||
|
||||
void BaseBwuHandler::RevertResponderState(const std::string& service_id) {
|
||||
HandleRevertInitiatorStateForService(service_id);
|
||||
}
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
@@ -40,6 +40,10 @@ class BaseBwuHandler : public BwuHandler {
|
||||
void RevertInitiatorState() final;
|
||||
void RevertInitiatorState(const std::string& upgrade_service_id,
|
||||
const std::string& endpoint_id) final;
|
||||
// If BWU Medium is Hotspot. The client needs to disconnect from Hotspot, then
|
||||
// it can restore the previous AP connection right away. The following method
|
||||
// is only for Hotspot Client
|
||||
void RevertResponderState(const std::string& service_id) final;
|
||||
|
||||
protected:
|
||||
// Invoked by InitializeUpgradedMediumForEndpoint and RevertInitiatorState,
|
||||
|
||||
@@ -77,6 +77,8 @@ class BwuHandler {
|
||||
virtual void RevertInitiatorState(const std::string& service_id,
|
||||
const std::string& endpoint_id) = 0;
|
||||
|
||||
virtual void RevertResponderState(const std::string& service_id) = 0;
|
||||
|
||||
// Called by the Responder to set up the upgraded medium for this endpoint (if
|
||||
// that hasn't already been done) using the UpgradePathInfo sent by the
|
||||
// Initiator, and returns a new EndpointChannel for the upgraded medium.
|
||||
|
||||
@@ -374,12 +374,23 @@ void BwuManager::RevertBwuMediumForEndpoint(const std::string& service_id,
|
||||
<< endpoint_id;
|
||||
endpoint_id_to_bwu_medium_.erase(endpoint_id);
|
||||
|
||||
// If |service_id| isn't of the INITIATOR-upgrade format--for example, if this
|
||||
// is called by the RESPONDER--there is no need to call RevertInitiatorState.
|
||||
if (!IsInitiatorUpgradeServiceId(service_id)) return;
|
||||
|
||||
BwuHandler* handler = GetHandlerForMedium(medium);
|
||||
if (!handler) return;
|
||||
if (!handler) {
|
||||
NEARBY_LOGS(INFO) << "No BWU handler can be found for "
|
||||
<< proto::connections::Medium_Name(medium);
|
||||
return;
|
||||
}
|
||||
// If |service_id| isn't of the INITIATOR-upgrade format--for example, if this
|
||||
// is called by the RESPONDER--there is no need to call RevertInitiatorState
|
||||
// unless the BWU Medium is Hotspot. The client needs to disconnect from
|
||||
// Hotspot, then it can restore the previous AP connection right away.
|
||||
if (!IsInitiatorUpgradeServiceId(service_id)) {
|
||||
if (medium == Medium::WIFI_HOTSPOT) {
|
||||
handler->RevertResponderState(service_id);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
handler->RevertInitiatorState(service_id, endpoint_id);
|
||||
}
|
||||
|
||||
@@ -669,6 +669,59 @@ TEST_F(BwuManagerTest, InitiateBwu_Revert_OnUpgradeFailure_FlagDisabled) {
|
||||
EXPECT_TRUE(fake_web_rtc_bwu_handler_->handle_revert_calls().empty());
|
||||
}
|
||||
|
||||
TEST_F(BwuManagerTest, InitiateBwu_Revert_OnDisconnect_Hotspot) {
|
||||
FeatureFlags::GetMutableFlagsForTesting().support_multiple_bwu_mediums = true;
|
||||
|
||||
CreateInitialEndpoint(kServiceIdA, kEndpointId1, Medium::BLUETOOTH);
|
||||
|
||||
ExceptionOr<OfflineFrame> hotspot_path_available_frame =
|
||||
parser::FromBytes(parser::ForBwuWifiHotspotPathAvailable(
|
||||
/*ssid=*/"Direct-357a2d8c", /*password=*/"b592f7d3",
|
||||
/*port=*/1234, /*gateway=*/"123.234.23.1", false));
|
||||
OfflineFrame frame = hotspot_path_available_frame.result();
|
||||
frame.set_version(OfflineFrame::V1);
|
||||
auto* v1_frame = frame.mutable_v1();
|
||||
auto* sub_frame = v1_frame->mutable_bandwidth_upgrade_negotiation();
|
||||
sub_frame->set_event_type(
|
||||
BandwidthUpgradeNegotiationFrame::UPGRADE_PATH_AVAILABLE);
|
||||
auto* upgrade_path_info = sub_frame->mutable_upgrade_path_info();
|
||||
upgrade_path_info->set_supports_client_introduction_ack(false);
|
||||
|
||||
bwu_manager_->OnIncomingFrame(frame, std::string(kEndpointId1), &client_,
|
||||
Medium::BLUETOOTH);
|
||||
CountDownLatch latch(1);
|
||||
bwu_manager_->OnEndpointDisconnect(&client_, (std::string)kServiceIdA,
|
||||
std::string(kEndpointId1), latch);
|
||||
|
||||
ASSERT_EQ(fake_wifi_hotspot_bwu_handler_->handle_revert_calls().size(), 1u);
|
||||
}
|
||||
|
||||
TEST_F(BwuManagerTest, InitiateBwu_Revert_OnDisconnect_Wlan) {
|
||||
FeatureFlags::GetMutableFlagsForTesting().support_multiple_bwu_mediums = true;
|
||||
|
||||
CreateInitialEndpoint(kServiceIdA, kEndpointId1, Medium::BLUETOOTH);
|
||||
|
||||
ExceptionOr<OfflineFrame> wlan_path_available_frame = parser::FromBytes(
|
||||
parser::ForBwuWifiLanPathAvailable(/*ip_address=*/"ABCD",
|
||||
/*port=*/1234));
|
||||
OfflineFrame frame = wlan_path_available_frame.result();
|
||||
frame.set_version(OfflineFrame::V1);
|
||||
auto* v1_frame = frame.mutable_v1();
|
||||
auto* sub_frame = v1_frame->mutable_bandwidth_upgrade_negotiation();
|
||||
sub_frame->set_event_type(
|
||||
BandwidthUpgradeNegotiationFrame::UPGRADE_PATH_AVAILABLE);
|
||||
auto* upgrade_path_info = sub_frame->mutable_upgrade_path_info();
|
||||
upgrade_path_info->set_supports_client_introduction_ack(false);
|
||||
|
||||
bwu_manager_->OnIncomingFrame(frame, std::string(kEndpointId1), &client_,
|
||||
Medium::BLUETOOTH);
|
||||
CountDownLatch latch(1);
|
||||
bwu_manager_->OnEndpointDisconnect(&client_, (std::string)kServiceIdA,
|
||||
std::string(kEndpointId1), latch);
|
||||
|
||||
ASSERT_EQ(fake_wifi_lan_bwu_handler_->handle_revert_calls().size(), 0u);
|
||||
}
|
||||
|
||||
TEST_F(BwuManagerTest, OnReceiveBwuEvent) {
|
||||
// TODO(b/235109434): Add more unit tests coverage for BWU module
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user