Commit 91ad38b7 authored by Regan Hsu's avatar Regan Hsu Committed by Chromium LUCI CQ

[CrOS PhoneHub] Scan for tether network only when UI first opens

Prior to this CL, a scan for instant tethering networks is performed
every time the PHoneHub UI bubble opens. Now, a scan for tether
networks only occurs the first time the user opens PhoneHub when its
enabled during their session.

Fixed: 1164517
Bug: 1106937
Change-Id: I281fb88bafdc375391e0596052b327657ee71c47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2621982
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843092}
parent cb0091b9
......@@ -33,10 +33,6 @@ QuickActionItem* EnableHotspotQuickActionController::CreateItem() {
item_ = new QuickActionItem(this, IDS_ASH_PHONE_HUB_ENABLE_HOTSPOT_TITLE,
kPhoneHubEnableHotspotOnIcon,
kPhoneHubEnableHotspotOffIcon);
// When the UI has just opened, scan to see if there is a connection
// available.
if (tether_controller_->GetStatus() == Status::kConnectionUnavailable)
tether_controller_->ScanForAvailableConnection();
OnTetherStatusChanged();
return item_;
}
......
......@@ -103,6 +103,21 @@ void PhoneHubUiController::HandleBubbleOpened() {
phone_hub_manager_->GetBrowserTabsModelProvider()->TriggerRefresh();
phone_hub_manager_->GetUserActionRecorder()->RecordUiOpened();
bool is_feature_enabled =
feature_status == FeatureStatus::kEnabledAndConnected ||
feature_status == FeatureStatus::kEnabledButDisconnected ||
feature_status == FeatureStatus::kEnabledAndConnected;
if (!is_feature_enabled)
return;
if (!has_requested_tether_scan_during_session_ &&
phone_hub_manager_->GetTetherController()->GetStatus() ==
TetherStatus::kConnectionUnavailable) {
phone_hub_manager_->GetTetherController()->ScanForAvailableConnection();
has_requested_tether_scan_during_session_ = true;
}
}
void PhoneHubUiController::AddObserver(Observer* observer) {
......
......@@ -112,6 +112,11 @@ class ASH_EXPORT PhoneHubUiController
// The current UI state.
UiState ui_state_ = UiState::kHidden;
// This value becomes true the first time the user opens the PhoneHub UI
// when the feature is in the enabled state, and a tether scan request is
// made.
bool has_requested_tether_scan_during_session_ = false;
// Registered observers.
base::ObserverList<Observer> observer_list_;
};
......
......@@ -14,6 +14,7 @@
#include "ui/views/view.h"
using FeatureStatus = chromeos::phonehub::FeatureStatus;
using TetherStatus = chromeos::phonehub::TetherController::Status;
namespace ash {
......@@ -72,6 +73,8 @@ class PhoneHubUiControllerTest : public NoSessionAshTestBase,
phone_status_model);
}
void CallHandleBubbleOpened() { controller_->HandleBubbleOpened(); }
protected:
// PhoneHubUiController::Observer:
void OnPhoneHubUiStateChanged() override {
......@@ -241,4 +244,25 @@ TEST_F(PhoneHubUiControllerTest, ConnectedViewDelayed) {
EXPECT_EQ(kPhoneConnectedView, content_view2->GetID());
}
TEST_F(PhoneHubUiControllerTest, NumScanForAvailableConnectionCalls) {
size_t num_scan_for_connection_calls =
GetTetherController()->num_scan_for_available_connection_calls();
GetFeatureStatusProvider()->SetStatus(FeatureStatus::kEnabledAndConnected);
GetTetherController()->SetStatus(TetherStatus::kConnectionUnavailable);
// A scan for available connection calls should occur the first time
// the PhoneHub UI is opened while the feature status is enabled
// and the tether status is kConnectionUnavailable.
CallHandleBubbleOpened();
EXPECT_EQ(GetTetherController()->num_scan_for_available_connection_calls(),
num_scan_for_connection_calls + 1);
// No scan for available connection calls should occur after a tether scan
// has been requested.
CallHandleBubbleOpened();
EXPECT_EQ(GetTetherController()->num_scan_for_available_connection_calls(),
num_scan_for_connection_calls + 1);
}
} // namespace ash
......@@ -25,6 +25,7 @@ TetherController::Status FakeTetherController::GetStatus() const {
}
void FakeTetherController::ScanForAvailableConnection() {
num_scan_for_available_connection_calls_++;
if (status_ == Status::kConnectionUnavailable)
SetStatus(Status::kConnectionAvailable);
}
......
......@@ -19,16 +19,21 @@ class FakeTetherController : public TetherController {
void SetStatus(Status status);
size_t num_scan_for_available_connection_calls() {
return num_scan_for_available_connection_calls_;
}
// TetherController:
Status GetStatus() const override;
void ScanForAvailableConnection() override;
private:
// TetherController:
void ScanForAvailableConnection() override;
void AttemptConnection() override;
void Disconnect() override;
Status status_;
size_t num_scan_for_available_connection_calls_ = 0;
};
} // namespace phonehub
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment