Commit b32e781a authored by Tim Song's avatar Tim Song Committed by Commit Bot

[CrOS PhoneHub] Hook up PhoneHubManager with tray UI.

BUG=1106937,1126208

Change-Id: I58ef9ad83bb18ee8193563820c3c0a223295e6a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2400765
Commit-Queue: Tim Song <tengs@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806376}
parent c3c444c0
...@@ -1646,6 +1646,7 @@ component("ash") { ...@@ -1646,6 +1646,7 @@ component("ash") {
"//cc/paint:paint", "//cc/paint:paint",
"//chromeos/assistant:buildflags", "//chromeos/assistant:buildflags",
"//chromeos/components/bloom/public/cpp", "//chromeos/components/bloom/public/cpp",
"//chromeos/components/phonehub",
"//chromeos/components/quick_answers", "//chromeos/components/quick_answers",
"//chromeos/components/quick_answers/public/cpp:prefs", "//chromeos/components/quick_answers/public/cpp:prefs",
"//services/viz/public/mojom", "//services/viz/public/mojom",
...@@ -2072,6 +2073,7 @@ test("ash_unittests") { ...@@ -2072,6 +2073,7 @@ test("ash_unittests") {
"system/palette/tools/create_note_unittest.cc", "system/palette/tools/create_note_unittest.cc",
"system/palette/tools/metalayer_unittest.cc", "system/palette/tools/metalayer_unittest.cc",
"system/palette/tools/screenshot_unittest.cc", "system/palette/tools/screenshot_unittest.cc",
"system/phonehub/phone_hub_tray_unittest.cc",
"system/power/backlights_forced_off_setter_unittest.cc", "system/power/backlights_forced_off_setter_unittest.cc",
"system/power/peripheral_battery_notifier_unittest.cc", "system/power/peripheral_battery_notifier_unittest.cc",
"system/power/power_button_controller_unittest.cc", "system/power/power_button_controller_unittest.cc",
...@@ -2238,6 +2240,7 @@ test("ash_unittests") { ...@@ -2238,6 +2240,7 @@ test("ash_unittests") {
# TODO(https://crbug.com/644336): Make CrasAudioHandler Chrome or Ash only. # TODO(https://crbug.com/644336): Make CrasAudioHandler Chrome or Ash only.
"//chromeos/audio", "//chromeos/audio",
"//chromeos/components/bloom/public/cpp", "//chromeos/components/bloom/public/cpp",
"//chromeos/components/phonehub:test_support",
"//chromeos/components/quick_answers:quick_answers", "//chromeos/components/quick_answers:quick_answers",
"//chromeos/constants", "//chromeos/constants",
"//chromeos/dbus:test_support", "//chromeos/dbus:test_support",
......
...@@ -59,6 +59,7 @@ include_rules = [ ...@@ -59,6 +59,7 @@ include_rules = [
"+chromeos/audio", "+chromeos/audio",
"+chromeos/components/multidevice/logging/logging.h", "+chromeos/components/multidevice/logging/logging.h",
"+chromeos/components/bloom/public/cpp", "+chromeos/components/bloom/public/cpp",
"+chromeos/components/phonehub",
"+chromeos/components/proximity_auth/public/mojom", "+chromeos/components/proximity_auth/public/mojom",
"+chromeos/components/quick_answers", "+chromeos/components/quick_answers",
"+chromeos/components/security_token_pin", "+chromeos/components/security_token_pin",
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
#include "ash/system/model/virtual_keyboard_model.h" #include "ash/system/model/virtual_keyboard_model.h"
#include "ash/system/network/active_network_icon.h" #include "ash/system/network/active_network_icon.h"
#include "ash/system/network/tray_network_state_model.h" #include "ash/system/network/tray_network_state_model.h"
#include "ash/system/phonehub/phone_hub_tray.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/system/unified/unified_system_tray.h" #include "ash/system/unified/unified_system_tray.h"
#include "chromeos/components/phonehub/phone_hub_manager.h"
namespace ash { namespace ash {
...@@ -117,7 +119,10 @@ void SystemTrayModel::ShowNetworkDetailedViewBubble(bool show_by_click) { ...@@ -117,7 +119,10 @@ void SystemTrayModel::ShowNetworkDetailedViewBubble(bool show_by_click) {
void SystemTrayModel::SetPhoneHubManager( void SystemTrayModel::SetPhoneHubManager(
chromeos::phonehub::PhoneHubManager* phone_hub_manager) { chromeos::phonehub::PhoneHubManager* phone_hub_manager) {
// TODO(tengs): Use |phone_hub_manager|. auto* phone_hub_tray = Shell::GetPrimaryRootWindowController()
->GetStatusAreaWidget()
->phone_hub_tray();
phone_hub_tray->SetPhoneHubManager(phone_hub_manager);
} }
} // namespace ash } // namespace ash
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "ash/system/tray/tray_popup_utils.h" #include "ash/system/tray/tray_popup_utils.h"
#include "ash/system/tray/tray_utils.h" #include "ash/system/tray/tray_utils.h"
#include "base/bind.h" #include "base/bind.h"
#include "chromeos/components/phonehub/phone_hub_manager.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -106,6 +107,21 @@ PhoneHubTray::PhoneHubTray(Shelf* shelf) : TrayBackgroundView(shelf) { ...@@ -106,6 +107,21 @@ PhoneHubTray::PhoneHubTray(Shelf* shelf) : TrayBackgroundView(shelf) {
PhoneHubTray::~PhoneHubTray() { PhoneHubTray::~PhoneHubTray() {
if (bubble_) if (bubble_)
bubble_->bubble_view()->ResetDelegate(); bubble_->bubble_view()->ResetDelegate();
CleanUpPhoneHubManager();
}
void PhoneHubTray::SetPhoneHubManager(
chromeos::phonehub::PhoneHubManager* phone_hub_manager) {
if (phone_hub_manager == phone_hub_manager_)
return;
CleanUpPhoneHubManager();
phone_hub_manager_ = phone_hub_manager;
if (phone_hub_manager_)
phone_hub_manager_->GetFeatureStatusProvider()->AddObserver(this);
OnFeatureStatusChanged();
} }
void PhoneHubTray::ClickedOutsideBubble() { void PhoneHubTray::ClickedOutsideBubble() {
...@@ -200,9 +216,38 @@ void PhoneHubTray::CloseBubble() { ...@@ -200,9 +216,38 @@ void PhoneHubTray::CloseBubble() {
shelf()->UpdateAutoHideState(); shelf()->UpdateAutoHideState();
} }
void PhoneHubTray::OnFeatureStatusChanged() {
UpdateVisibility();
}
void PhoneHubTray::UpdateVisibility() { void PhoneHubTray::UpdateVisibility() {
// TODO(tengs): Hook up visibility with phonehub::FeatureStatusProvider. if (!phone_hub_manager_) {
SetVisiblePreferred(chromeos::features::IsPhoneHubEnabled()); SetVisiblePreferred(false);
return;
}
auto feature_status =
phone_hub_manager_->GetFeatureStatusProvider()->GetStatus();
bool is_visible;
switch (feature_status) {
case chromeos::phonehub::FeatureStatus::kNotEligibleForFeature:
FALLTHROUGH;
case chromeos::phonehub::FeatureStatus::kDisabled:
is_visible = false;
break;
default:
is_visible = true;
break;
}
SetVisiblePreferred(is_visible);
}
void PhoneHubTray::CleanUpPhoneHubManager() {
if (!phone_hub_manager_)
return;
phone_hub_manager_->GetFeatureStatusProvider()->RemoveObserver(this);
} }
} // namespace ash } // namespace ash
...@@ -7,6 +7,13 @@ ...@@ -7,6 +7,13 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/system/tray/tray_background_view.h" #include "ash/system/tray/tray_background_view.h"
#include "chromeos/components/phonehub/feature_status_provider.h"
namespace chromeos {
namespace phonehub {
class PhoneHubManager;
} // namespace phonehub
} // namespace chromeos
namespace views { namespace views {
class ImageView; class ImageView;
...@@ -18,13 +25,19 @@ class TrayBubbleWrapper; ...@@ -18,13 +25,19 @@ class TrayBubbleWrapper;
// This class represents the Phone Hub tray button in the status area and // This class represents the Phone Hub tray button in the status area and
// controls the bubble that is shown when the tray button is clicked. // controls the bubble that is shown when the tray button is clicked.
class ASH_EXPORT PhoneHubTray : public TrayBackgroundView { class ASH_EXPORT PhoneHubTray
: public TrayBackgroundView,
public chromeos::phonehub::FeatureStatusProvider::Observer {
public: public:
explicit PhoneHubTray(Shelf* shelf); explicit PhoneHubTray(Shelf* shelf);
PhoneHubTray(const PhoneHubTray&) = delete; PhoneHubTray(const PhoneHubTray&) = delete;
~PhoneHubTray() override; ~PhoneHubTray() override;
PhoneHubTray& operator=(const PhoneHubTray&) = delete; PhoneHubTray& operator=(const PhoneHubTray&) = delete;
// Sets the PhoneHubManager that provides the data to drive the UI.
void SetPhoneHubManager(
chromeos::phonehub::PhoneHubManager* phone_hub_manager);
// TrayBackgroundView: // TrayBackgroundView:
void ClickedOutsideBubble() override; void ClickedOutsideBubble() override;
base::string16 GetAccessibleNameForTray() override; base::string16 GetAccessibleNameForTray() override;
...@@ -44,13 +57,22 @@ class ASH_EXPORT PhoneHubTray : public TrayBackgroundView { ...@@ -44,13 +57,22 @@ class ASH_EXPORT PhoneHubTray : public TrayBackgroundView {
bool ShouldEnableExtraKeyboardAccessibility() override; bool ShouldEnableExtraKeyboardAccessibility() override;
void HideBubble(const TrayBubbleView* bubble_view) override; void HideBubble(const TrayBubbleView* bubble_view) override;
// chromeos::phonehub::FeatureStatusProvider::Observer:
void OnFeatureStatusChanged() override;
// Updates the visibility of the tray in the shelf based on the feature is // Updates the visibility of the tray in the shelf based on the feature is
// enabled. // enabled.
void UpdateVisibility(); void UpdateVisibility();
// Cleans up |phone_hub_manager_| by removing all observers.
void CleanUpPhoneHubManager();
// Icon of the tray. Unowned. // Icon of the tray. Unowned.
views::ImageView* icon_; views::ImageView* icon_;
// The PhoneHubManager that provides data for the UI.
chromeos::phonehub::PhoneHubManager* phone_hub_manager_ = nullptr;
std::unique_ptr<TrayBubbleWrapper> bubble_; std::unique_ptr<TrayBubbleWrapper> bubble_;
}; };
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/phonehub/phone_hub_tray.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/test/ash_test_base.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/components/phonehub/fake_phone_hub_manager.h"
#include "chromeos/constants/chromeos_features.h"
#include "ui/events/event.h"
namespace ash {
class PhoneHubTrayTest : public AshTestBase {
public:
PhoneHubTrayTest() = default;
~PhoneHubTrayTest() override = default;
// AshTestBase:
void SetUp() override {
feature_list_.InitAndEnableFeature(chromeos::features::kPhoneHub);
AshTestBase::SetUp();
phone_hub_tray_ =
StatusAreaWidgetTestHelper::GetStatusAreaWidget()->phone_hub_tray();
GetFeatureStatusProvider()->SetStatus(
chromeos::phonehub::FeatureStatus::kEnabledAndConnected);
phone_hub_tray_->SetPhoneHubManager(&phone_hub_manager_);
}
chromeos::phonehub::FakeFeatureStatusProvider* GetFeatureStatusProvider() {
return phone_hub_manager_.fake_feature_status_provider();
}
void ClickTrayButton() {
ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
phone_hub_tray_->PerformAction(tap);
}
protected:
PhoneHubTray* phone_hub_tray_ = nullptr;
chromeos::phonehub::FakePhoneHubManager phone_hub_manager_;
base::test::ScopedFeatureList feature_list_;
};
TEST_F(PhoneHubTrayTest, SetPhoneHubManager) {
// Set a new manager.
chromeos::phonehub::FakePhoneHubManager new_manager;
new_manager.fake_feature_status_provider()->SetStatus(
chromeos::phonehub::FeatureStatus::kEligiblePhoneButNotSetUp);
phone_hub_tray_->SetPhoneHubManager(&new_manager);
EXPECT_TRUE(phone_hub_tray_->GetVisible());
// Changing the old manager should have no effect.
GetFeatureStatusProvider()->SetStatus(
chromeos::phonehub::FeatureStatus::kDisabled);
EXPECT_TRUE(phone_hub_tray_->GetVisible());
// Only the new manager should work.
new_manager.fake_feature_status_provider()->SetStatus(
chromeos::phonehub::FeatureStatus::kDisabled);
EXPECT_FALSE(phone_hub_tray_->GetVisible());
// Set no manager.
phone_hub_tray_->SetPhoneHubManager(nullptr);
EXPECT_FALSE(phone_hub_tray_->GetVisible());
}
TEST_F(PhoneHubTrayTest, ClickTrayButton) {
EXPECT_TRUE(phone_hub_tray_->GetVisible());
EXPECT_FALSE(phone_hub_tray_->is_active());
ClickTrayButton();
EXPECT_TRUE(phone_hub_tray_->is_active());
ClickTrayButton();
EXPECT_FALSE(phone_hub_tray_->is_active());
}
} // namespace ash
...@@ -125,6 +125,7 @@ class ASH_EXPORT StatusAreaWidget : public SessionObserver, ...@@ -125,6 +125,7 @@ class ASH_EXPORT StatusAreaWidget : public SessionObserver,
} }
ImeMenuTray* ime_menu_tray() { return ime_menu_tray_.get(); } ImeMenuTray* ime_menu_tray() { return ime_menu_tray_.get(); }
HoldingSpaceTray* holding_space_tray() { return holding_space_tray_.get(); } HoldingSpaceTray* holding_space_tray() { return holding_space_tray_.get(); }
PhoneHubTray* phone_hub_tray() { return phone_hub_tray_.get(); }
SelectToSpeakTray* select_to_speak_tray() { SelectToSpeakTray* select_to_speak_tray() {
return select_to_speak_tray_.get(); return select_to_speak_tray_.get();
......
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