Commit 7ecc10cd authored by Jimmy Gong's avatar Jimmy Gong Committed by Chromium LUCI CQ

Phone Hub: Delay connected view until phone model is initialized

Previously, the connected Phone Hub UI would display before the phone
model is initialized. This resulted in the UI flashing the
uninitialized status model before the actual phone model status. This
fix delays the connected view from displaying until the model is
initialized.

Fixed: 1155636
Change-Id: Iadbbefbc3e5cee70316cfe02ef9d466888a2e6f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2581221
Commit-Queue: Jimmy Gong <jimmyxgong@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835826}
parent a6c977b1
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chromeos/components/phonehub/fake_connection_scheduler.h" #include "chromeos/components/phonehub/fake_connection_scheduler.h"
#include "chromeos/components/phonehub/fake_notification_access_manager.h" #include "chromeos/components/phonehub/fake_notification_access_manager.h"
#include "chromeos/components/phonehub/fake_phone_hub_manager.h" #include "chromeos/components/phonehub/fake_phone_hub_manager.h"
#include "chromeos/components/phonehub/phone_model_test_util.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "ui/events/event.h" #include "ui/events/event.h"
...@@ -52,6 +53,9 @@ class PhoneHubTrayTest : public AshTestBase { ...@@ -52,6 +53,9 @@ class PhoneHubTrayTest : public AshTestBase {
GetFeatureStatusProvider()->SetStatus( GetFeatureStatusProvider()->SetStatus(
chromeos::phonehub::FeatureStatus::kEnabledAndConnected); chromeos::phonehub::FeatureStatus::kEnabledAndConnected);
phone_hub_tray_->SetPhoneHubManager(&phone_hub_manager_); phone_hub_tray_->SetPhoneHubManager(&phone_hub_manager_);
phone_hub_manager_.mutable_phone_model()->SetPhoneStatusModel(
chromeos::phonehub::CreateFakePhoneStatusModel());
} }
chromeos::phonehub::FakeFeatureStatusProvider* GetFeatureStatusProvider() { chromeos::phonehub::FakeFeatureStatusProvider* GetFeatureStatusProvider() {
......
...@@ -37,6 +37,7 @@ void PhoneHubUiController::SetPhoneHubManager( ...@@ -37,6 +37,7 @@ void PhoneHubUiController::SetPhoneHubManager(
if (phone_hub_manager_) { if (phone_hub_manager_) {
phone_hub_manager_->GetFeatureStatusProvider()->AddObserver(this); phone_hub_manager_->GetFeatureStatusProvider()->AddObserver(this);
phone_hub_manager_->GetOnboardingUiTracker()->AddObserver(this); phone_hub_manager_->GetOnboardingUiTracker()->AddObserver(this);
phone_hub_manager_->GetPhoneModel()->AddObserver(this);
} }
UpdateUiState(GetUiStateFromPhoneHubManager()); UpdateUiState(GetUiStateFromPhoneHubManager());
...@@ -102,6 +103,10 @@ void PhoneHubUiController::OnShouldShowOnboardingUiChanged() { ...@@ -102,6 +103,10 @@ void PhoneHubUiController::OnShouldShowOnboardingUiChanged() {
UpdateUiState(GetUiStateFromPhoneHubManager()); UpdateUiState(GetUiStateFromPhoneHubManager());
} }
void PhoneHubUiController::OnModelChanged() {
UpdateUiState(GetUiStateFromPhoneHubManager());
}
void PhoneHubUiController::UpdateUiState( void PhoneHubUiController::UpdateUiState(
PhoneHubUiController::UiState new_state) { PhoneHubUiController::UiState new_state) {
if (new_state == ui_state_) if (new_state == ui_state_)
...@@ -121,6 +126,7 @@ PhoneHubUiController::GetUiStateFromPhoneHubManager() { ...@@ -121,6 +126,7 @@ PhoneHubUiController::GetUiStateFromPhoneHubManager() {
phone_hub_manager_->GetFeatureStatusProvider()->GetStatus(); phone_hub_manager_->GetFeatureStatusProvider()->GetStatus();
auto* tracker = phone_hub_manager_->GetOnboardingUiTracker(); auto* tracker = phone_hub_manager_->GetOnboardingUiTracker();
auto* phone_model = phone_hub_manager_->GetPhoneModel();
bool should_show_onboarding_ui = tracker->ShouldShowOnboardingUi(); bool should_show_onboarding_ui = tracker->ShouldShowOnboardingUi();
switch (feature_status) { switch (feature_status) {
...@@ -141,7 +147,11 @@ PhoneHubUiController::GetUiStateFromPhoneHubManager() { ...@@ -141,7 +147,11 @@ PhoneHubUiController::GetUiStateFromPhoneHubManager() {
case FeatureStatus::kEnabledAndConnecting: case FeatureStatus::kEnabledAndConnecting:
return UiState::kPhoneConnecting; return UiState::kPhoneConnecting;
case FeatureStatus::kEnabledAndConnected: case FeatureStatus::kEnabledAndConnected:
return UiState::kPhoneConnected; // Delay displaying the connected view until the phone model is ready.
if (phone_model->phone_status_model().has_value())
return UiState::kPhoneConnected;
else
return UiState::kPhoneConnecting;
case FeatureStatus::kLockOrSuspended: case FeatureStatus::kLockOrSuspended:
return UiState::kHidden; return UiState::kHidden;
} }
...@@ -153,6 +163,7 @@ void PhoneHubUiController::CleanUpPhoneHubManager() { ...@@ -153,6 +163,7 @@ void PhoneHubUiController::CleanUpPhoneHubManager() {
phone_hub_manager_->GetFeatureStatusProvider()->RemoveObserver(this); phone_hub_manager_->GetFeatureStatusProvider()->RemoveObserver(this);
phone_hub_manager_->GetOnboardingUiTracker()->RemoveObserver(this); phone_hub_manager_->GetOnboardingUiTracker()->RemoveObserver(this);
phone_hub_manager_->GetPhoneModel()->RemoveObserver(this);
} }
} // namespace ash } // namespace ash
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/observer_list_types.h" #include "base/observer_list_types.h"
#include "chromeos/components/phonehub/feature_status_provider.h" #include "chromeos/components/phonehub/feature_status_provider.h"
#include "chromeos/components/phonehub/onboarding_ui_tracker.h" #include "chromeos/components/phonehub/onboarding_ui_tracker.h"
#include "chromeos/components/phonehub/phone_model.h"
namespace chromeos { namespace chromeos {
namespace phonehub { namespace phonehub {
...@@ -30,7 +31,8 @@ namespace ash { ...@@ -30,7 +31,8 @@ namespace ash {
// corresponding main content view to be displayed in the tray bubble. // corresponding main content view to be displayed in the tray bubble.
class ASH_EXPORT PhoneHubUiController class ASH_EXPORT PhoneHubUiController
: public chromeos::phonehub::FeatureStatusProvider::Observer, : public chromeos::phonehub::FeatureStatusProvider::Observer,
public chromeos::phonehub::OnboardingUiTracker::Observer { public chromeos::phonehub::OnboardingUiTracker::Observer,
public chromeos::phonehub::PhoneModel::Observer {
public: public:
class Observer : public base::CheckedObserver { class Observer : public base::CheckedObserver {
public: public:
...@@ -86,6 +88,9 @@ class ASH_EXPORT PhoneHubUiController ...@@ -86,6 +88,9 @@ class ASH_EXPORT PhoneHubUiController
// chromeos::phonehub::OnboardingUiTracker::Observer: // chromeos::phonehub::OnboardingUiTracker::Observer:
void OnShouldShowOnboardingUiChanged() override; void OnShouldShowOnboardingUiChanged() override;
// chromeos::phonehub::PhoneModel::Observer:
void OnModelChanged() override;
// Updates the current UI state and notifies observers. // Updates the current UI state and notifies observers.
void UpdateUiState(PhoneHubUiController::UiState new_state); void UpdateUiState(PhoneHubUiController::UiState new_state);
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#include "ash/system/phonehub/phone_hub_view_ids.h" #include "ash/system/phonehub/phone_hub_view_ids.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "base/optional.h"
#include "chromeos/components/phonehub/fake_phone_hub_manager.h" #include "chromeos/components/phonehub/fake_phone_hub_manager.h"
#include "chromeos/components/phonehub/phone_model_test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -43,6 +45,13 @@ class PhoneHubUiControllerTest : public AshTestBase, ...@@ -43,6 +45,13 @@ class PhoneHubUiControllerTest : public AshTestBase,
return phone_hub_manager_.fake_onboarding_ui_tracker(); return phone_hub_manager_.fake_onboarding_ui_tracker();
} }
void SetPhoneStatusModel(
const base::Optional<chromeos::phonehub::PhoneStatusModel>&
phone_status_model) {
phone_hub_manager_.mutable_phone_model()->SetPhoneStatusModel(
phone_status_model);
}
protected: protected:
// PhoneHubUiController::Observer: // PhoneHubUiController::Observer:
void OnPhoneHubUiStateChanged() override { void OnPhoneHubUiStateChanged() override {
...@@ -136,6 +145,7 @@ TEST_F(PhoneHubUiControllerTest, PhoneConnecting) { ...@@ -136,6 +145,7 @@ TEST_F(PhoneHubUiControllerTest, PhoneConnecting) {
} }
TEST_F(PhoneHubUiControllerTest, PhoneConnected) { TEST_F(PhoneHubUiControllerTest, PhoneConnected) {
SetPhoneStatusModel(chromeos::phonehub::CreateFakePhoneStatusModel());
GetFeatureStatusProvider()->SetStatus(FeatureStatus::kEnabledAndConnected); GetFeatureStatusProvider()->SetStatus(FeatureStatus::kEnabledAndConnected);
EXPECT_EQ(PhoneHubUiController::UiState::kPhoneConnected, EXPECT_EQ(PhoneHubUiController::UiState::kPhoneConnected,
controller_.ui_state()); controller_.ui_state());
...@@ -150,4 +160,22 @@ TEST_F(PhoneHubUiControllerTest, UnavailableScreenLocked) { ...@@ -150,4 +160,22 @@ TEST_F(PhoneHubUiControllerTest, UnavailableScreenLocked) {
EXPECT_FALSE(controller_.CreateContentView(/*bubble_view=*/nullptr).get()); EXPECT_FALSE(controller_.CreateContentView(/*bubble_view=*/nullptr).get());
} }
TEST_F(PhoneHubUiControllerTest, ConnectedViewDelayed) {
// Since there is no phone model, expect that we stay at the connecting screen
// even though the feature status is kEnabledAndConnected.
SetPhoneStatusModel(base::nullopt);
GetFeatureStatusProvider()->SetStatus(FeatureStatus::kEnabledAndConnected);
EXPECT_EQ(PhoneHubUiController::UiState::kPhoneConnecting,
controller_.ui_state());
auto content_view = controller_.CreateContentView(/*delegate=*/nullptr);
EXPECT_EQ(kPhoneConnectingView, content_view->GetID());
// Update the phone status model and expect the connected view to show up.
SetPhoneStatusModel(chromeos::phonehub::CreateFakePhoneStatusModel());
EXPECT_EQ(PhoneHubUiController::UiState::kPhoneConnected,
controller_.ui_state());
auto content_view2 = controller_.CreateContentView(/*delegate=*/nullptr);
EXPECT_EQ(kPhoneConnectedView, content_view2->GetID());
}
} // namespace ash } // namespace ash
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