Commit b858821f authored by Karan Bhatia's avatar Karan Bhatia Committed by Commit Bot

Revert "[CrOS PhoneHub] Add enable hotspot and locate phone controller to quick"

This reverts commit 2e1031ec.

Reason for revert: Causes compile failure on linux-chromeos-dbg.

Original change's description:
> [CrOS PhoneHub] Add enable hotspot and locate phone controller to quick
> actions UI.
>
> - Add enable hotspot and locate phone quick actions controllers.
> - Connect the controllers to quick actions UI.
> - Minor changes in fake tether controller for testing.
>
> BUG=1106937,1126208
>
> Change-Id: I1d4ace03120a4c51fcb351b7c19f33252b3fb81c
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2428735
> Commit-Queue: Andre Le <leandre@chromium.org>
> Reviewed-by: Tim Song <tengs@chromium.org>
> Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#812915}

TBR=khorimoto@chromium.org,tengs@chromium.org,leandre@chromium.org

Change-Id: I431b965f354a2d63bd98e361b8ae3233ba5288e7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1106937
Bug: 1126208
Bug: 1134378
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444132Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: Karan Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812986}
parent 46e75950
......@@ -1128,12 +1128,8 @@ component("ash") {
"system/phonehub/connection_error_view.h",
"system/phonehub/continue_browsing_chip.cc",
"system/phonehub/continue_browsing_chip.h",
"system/phonehub/enable_hotspot_quick_action_controller.cc",
"system/phonehub/enable_hotspot_quick_action_controller.h",
"system/phonehub/initial_connecting_view.cc",
"system/phonehub/initial_connecting_view.h",
"system/phonehub/locate_phone_quick_action_controller.cc",
"system/phonehub/locate_phone_quick_action_controller.h",
"system/phonehub/notification_opt_in_view.cc",
"system/phonehub/notification_opt_in_view.h",
"system/phonehub/onboarding_view.cc",
......
// 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/enable_hotspot_quick_action_controller.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/phonehub/quick_action_item.h"
#include "ui/base/l10n/l10n_util.h"
namespace ash {
using Status = chromeos::phonehub::TetherController::Status;
EnableHotspotQuickActionController::EnableHotspotQuickActionController(
chromeos::phonehub::TetherController* tether_controller)
: tether_controller_(tether_controller) {
DCHECK(tether_controller_);
tether_controller_->AddObserver(this);
}
EnableHotspotQuickActionController::~EnableHotspotQuickActionController() {
tether_controller_->RemoveObserver(this);
}
QuickActionItem* EnableHotspotQuickActionController::CreateItem() {
DCHECK(!item_);
item_ = new QuickActionItem(this, IDS_ASH_PHONE_HUB_ENABLE_HOTSPOT_TITLE,
kSystemMenuPhoneIcon);
// 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_;
}
void EnableHotspotQuickActionController::OnButtonPressed(bool is_now_enabled) {
is_now_enabled ? tether_controller_->Disconnect()
: tether_controller_->AttemptConnection();
// TODO(leandre): Add a timer to switch back to off state after connecting
// failed.
}
void EnableHotspotQuickActionController::OnTetherStatusChanged() {
switch (tether_controller_->GetStatus()) {
case Status::kIneligibleForFeature:
item_->SetVisible(false);
return;
case Status::kConnectionUnavailable:
SetState(ActionState::kNotAvailable);
break;
case Status::kConnectionAvailable:
SetState(ActionState::kNotConnected);
break;
case Status::kConnecting:
SetState(ActionState::kConnecting);
break;
case Status::kConnected:
SetState(ActionState::kConnected);
break;
}
item_->SetVisible(true);
}
void EnableHotspotQuickActionController::SetState(ActionState state) {
item_->SetEnabled(true);
bool icon_enabled;
int state_text_id;
int sub_label_text;
switch (state) {
case ActionState::kNotAvailable:
icon_enabled = false;
state_text_id =
IDS_ASH_PHONE_HUB_QUICK_ACTIONS_NOT_AVAILABLE_STATE_TOOLTIP;
sub_label_text = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_NOT_AVAILABLE_STATE;
break;
case ActionState::kNotConnected:
icon_enabled = false;
state_text_id =
IDS_ASH_PHONE_HUB_QUICK_ACTIONS_NOT_CONNECTED_STATE_TOOLTIP;
sub_label_text = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_NOT_CONNECTED_STATE;
break;
case ActionState::kConnecting:
icon_enabled = true;
state_text_id = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_CONNECTING_STATE_TOOLTIP;
sub_label_text = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_CONNECTING_STATE;
break;
case ActionState::kConnected:
icon_enabled = true;
state_text_id = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_CONNECTED_STATE_TOOLTIP;
sub_label_text = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_CONNECTED_STATE;
break;
}
item_->SetToggled(icon_enabled);
item_->SetSubLabel(l10n_util::GetStringUTF16(sub_label_text));
base::string16 tooltip_state =
l10n_util::GetStringFUTF16(state_text_id, item_->GetItemLabel());
item_->SetIconTooltip(
l10n_util::GetStringFUTF16(IDS_ASH_PHONE_HUB_QUICK_ACTIONS_TOGGLE_TOOLTIP,
item_->GetItemLabel(), tooltip_state));
}
} // namespace ash
// 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.
#ifndef ASH_SYSTEM_PHONEHUB_ENABLE_HOTSPOT_QUICK_ACTION_CONTROLLER_H_
#define ASH_SYSTEM_PHONEHUB_ENABLE_HOTSPOT_QUICK_ACTION_CONTROLLER_H_
#include "ash/system/phonehub/quick_action_controller_base.h"
#include "chromeos/components/phonehub/tether_controller.h"
namespace ash {
// Controller of a quick action item that toggles Locate phone mode.
class EnableHotspotQuickActionController
: public QuickActionControllerBase,
public chromeos::phonehub::TetherController::Observer {
public:
explicit EnableHotspotQuickActionController(
chromeos::phonehub::TetherController* tether_controller);
~EnableHotspotQuickActionController() override;
EnableHotspotQuickActionController(EnableHotspotQuickActionController&) =
delete;
EnableHotspotQuickActionController operator=(
EnableHotspotQuickActionController&) = delete;
// QuickActionControllerBase:
QuickActionItem* CreateItem() override;
void OnButtonPressed(bool is_now_enabled) override;
// chromeos::phonehub::TetherController::Observer:
void OnTetherStatusChanged() override;
private:
// All the possible states that the enable hotspot button can be viewed. Each
// state has a corresponding icon, labels and tooltip view.
enum class ActionState {
kNotAvailable,
kNotConnected,
kConnecting,
kConnected
};
// Set the item (including icon, label and tooltips) to a certain state.
void SetState(ActionState state);
chromeos::phonehub::TetherController* tether_controller_ = nullptr;
QuickActionItem* item_ = nullptr;
};
} // namespace ash
#endif // ASH_SYSTEM_PHONEHUB_ENABLE_HOTSPOT_QUICK_ACTION_CONTROLLER_H_
// 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/locate_phone_quick_action_controller.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/phonehub/quick_action_item.h"
#include "ui/base/l10n/l10n_util.h"
namespace ash {
LocatePhoneQuickActionController::LocatePhoneQuickActionController(
chromeos::phonehub::FindMyDeviceController* find_my_device_controller)
: find_my_device_controller_(find_my_device_controller) {
DCHECK(find_my_device_controller_);
find_my_device_controller_->AddObserver(this);
}
LocatePhoneQuickActionController::~LocatePhoneQuickActionController() {
find_my_device_controller_->RemoveObserver(this);
}
QuickActionItem* LocatePhoneQuickActionController::CreateItem() {
DCHECK(!item_);
item_ = new QuickActionItem(this, IDS_ASH_PHONE_HUB_LOCATE_PHONE_TITLE,
kSystemMenuPhoneIcon);
OnPhoneRingingStateChanged();
return item_;
}
void LocatePhoneQuickActionController::OnButtonPressed(bool is_now_enabled) {
SetState(ActionState::kConnecting);
find_my_device_controller_->RequestNewPhoneRingingState(!is_now_enabled);
}
void LocatePhoneQuickActionController::OnPhoneRingingStateChanged() {
find_my_device_controller_->IsPhoneRinging() ? SetState(ActionState::kOn)
: SetState(ActionState::kOff);
}
void LocatePhoneQuickActionController::SetState(ActionState state) {
bool icon_enabled;
int state_text_id;
int sub_label_text;
switch (state) {
case ActionState::kOff:
icon_enabled = false;
state_text_id = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_DISABLED_STATE_TOOLTIP;
sub_label_text = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_OFF_STATE;
break;
case ActionState::kConnecting:
icon_enabled = true;
state_text_id = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_CONNECTING_STATE_TOOLTIP;
sub_label_text = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_CONNECTING_STATE;
break;
case ActionState::kOn:
icon_enabled = true;
state_text_id = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_ENABLED_STATE_TOOLTIP;
sub_label_text = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_ON_STATE;
break;
}
item_->SetToggled(icon_enabled);
item_->SetSubLabel(l10n_util::GetStringUTF16(sub_label_text));
base::string16 tooltip_state =
l10n_util::GetStringFUTF16(state_text_id, item_->GetItemLabel());
item_->SetIconTooltip(
l10n_util::GetStringFUTF16(IDS_ASH_PHONE_HUB_QUICK_ACTIONS_TOGGLE_TOOLTIP,
item_->GetItemLabel(), tooltip_state));
}
} // namespace ash
// 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.
#ifndef ASH_SYSTEM_PHONEHUB_LOCATE_PHONE_QUICK_ACTION_CONTROLLER_H_
#define ASH_SYSTEM_PHONEHUB_LOCATE_PHONE_QUICK_ACTION_CONTROLLER_H_
#include "ash/system/phonehub/quick_action_controller_base.h"
#include "chromeos/components/phonehub/find_my_device_controller.h"
namespace ash {
// Controller of a quick action item that toggles Locate phone mode.
class LocatePhoneQuickActionController
: public QuickActionControllerBase,
public chromeos::phonehub::FindMyDeviceController::Observer {
public:
explicit LocatePhoneQuickActionController(
chromeos::phonehub::FindMyDeviceController* find_my_device_controller);
~LocatePhoneQuickActionController() override;
LocatePhoneQuickActionController(LocatePhoneQuickActionController&) = delete;
LocatePhoneQuickActionController operator=(
LocatePhoneQuickActionController&) = delete;
// QuickActionControllerBase:
QuickActionItem* CreateItem() override;
void OnButtonPressed(bool is_now_enabled) override;
// chromeos::phonehub::FindMyDeviceController::Observer:
void OnPhoneRingingStateChanged() override;
private:
// All the possible states that the locate phone button can be viewed. Each
// state has a corresponding icon, labels and tooltip view.
enum class ActionState { kOff, kConnecting, kOn };
// Set the item (including icon, label and tooltips) to a certain state.
void SetState(ActionState state);
chromeos::phonehub::FindMyDeviceController* find_my_device_controller_ =
nullptr;
QuickActionItem* item_ = nullptr;
};
} // namespace ash
#endif // ASH_SYSTEM_PHONEHUB_LOCATE_PHONE_QUICK_ACTION_CONTROLLER_H_
......@@ -4,8 +4,6 @@
#include "ash/system/phonehub/quick_actions_view.h"
#include "ash/system/phonehub/enable_hotspot_quick_action_controller.h"
#include "ash/system/phonehub/locate_phone_quick_action_controller.h"
#include "ash/system/phonehub/phone_hub_view_ids.h"
#include "ash/system/phonehub/quick_action_item.h"
#include "ash/system/phonehub/silence_phone_quick_action_controller.h"
......@@ -38,13 +36,8 @@ QuickActionsView::QuickActionsView(
QuickActionsView::~QuickActionsView() = default;
void QuickActionsView::InitQuickActionItems() {
enable_hotspot_ =
AddItem(std::make_unique<EnableHotspotQuickActionController>(
phone_hub_manager_->GetTetherController()));
silence_phone_ = AddItem(std::make_unique<SilencePhoneQuickActionController>(
phone_hub_manager_->GetDoNotDisturbController()));
locate_phone_ = AddItem(std::make_unique<LocatePhoneQuickActionController>(
phone_hub_manager_->GetFindMyDeviceController()));
}
QuickActionItem* QuickActionsView::AddItem(
......
......@@ -24,11 +24,9 @@ class ASH_EXPORT QuickActionsView : public views::View {
QuickActionsView(QuickActionsView&) = delete;
QuickActionsView operator=(QuickActionsView&) = delete;
QuickActionItem* enable_hotspot_for_testing() { return enable_hotspot_; }
QuickActionItem* silence_phone_for_testing() { return silence_phone_; }
QuickActionItem* locate_phone_for_testing() { return locate_phone_; }
private:
FRIEND_TEST_ALL_PREFIXES(QuickActionsViewTest, QuickActionsToggle);
// Add all the quick actions items to the view.
void InitQuickActionItems();
......@@ -43,9 +41,7 @@ class ASH_EXPORT QuickActionsView : public views::View {
chromeos::phonehub::PhoneHubManager* phone_hub_manager_ = nullptr;
// QuickActionItem for unit testing. Owned by this view.
QuickActionItem* enable_hotspot_ = nullptr;
QuickActionItem* silence_phone_ = nullptr;
QuickActionItem* locate_phone_ = nullptr;
};
} // namespace ash
......
......@@ -60,60 +60,17 @@ class QuickActionsViewTest : public AshTestBase {
base::test::ScopedFeatureList feature_list_;
};
TEST_F(QuickActionsViewTest, EnableHotspotVisibility) {
tether_controller()->SetStatus(Status::kIneligibleForFeature);
// Enable Hotspot button should not be shown if the feature is ineligible.
EXPECT_FALSE(actions_view()->enable_hotspot_for_testing()->GetVisible());
tether_controller()->SetStatus(Status::kConnectionAvailable);
// Enable Hotspot button should be shown if the feature is available.
EXPECT_TRUE(actions_view()->enable_hotspot_for_testing()->GetVisible());
}
TEST_F(QuickActionsViewTest, EnableHotspotToggle) {
tether_controller()->SetStatus(Status::kConnectionAvailable);
// Simulate a toggle press. Status should be connecting.
actions_view()->enable_hotspot_for_testing()->ButtonPressed(nullptr,
DummyEvent());
EXPECT_EQ(Status::kConnecting, tether_controller()->GetStatus());
tether_controller()->SetStatus(Status::kConnected);
// Toggle again will change the state.
actions_view()->enable_hotspot_for_testing()->ButtonPressed(nullptr,
DummyEvent());
EXPECT_EQ(Status::kConnecting, tether_controller()->GetStatus());
}
TEST_F(QuickActionsViewTest, SilencePhoneToggle) {
TEST_F(QuickActionsViewTest, QuickActionsToggle) {
// Initially, silence phone is not enabled.
EXPECT_FALSE(dnd_controller()->IsDndEnabled());
// Toggle the button will enable the feature.
actions_view()->silence_phone_for_testing()->ButtonPressed(nullptr,
DummyEvent());
actions_view()->silence_phone_->ButtonPressed(nullptr, DummyEvent());
EXPECT_TRUE(dnd_controller()->IsDndEnabled());
// Togge again to disable.
actions_view()->silence_phone_for_testing()->ButtonPressed(nullptr,
DummyEvent());
actions_view()->silence_phone_->ButtonPressed(nullptr, DummyEvent());
EXPECT_FALSE(dnd_controller()->IsDndEnabled());
}
TEST_F(QuickActionsViewTest, LocatePhoneToggle) {
// Initially, locate phone is not enabled.
EXPECT_FALSE(find_my_device_controller()->IsPhoneRinging());
// Toggle the button will enable the feature.
actions_view()->locate_phone_for_testing()->ButtonPressed(nullptr,
DummyEvent());
EXPECT_TRUE(find_my_device_controller()->IsPhoneRinging());
// Togge again to disable.
actions_view()->locate_phone_for_testing()->ButtonPressed(nullptr,
DummyEvent());
EXPECT_FALSE(find_my_device_controller()->IsPhoneRinging());
}
} // namespace ash
......@@ -7,8 +7,7 @@
namespace chromeos {
namespace phonehub {
FakeTetherController::FakeTetherController()
: status_(Status::kConnectionAvailable) {}
FakeTetherController::FakeTetherController() = default;
FakeTetherController::~FakeTetherController() = default;
......
......@@ -21,7 +21,6 @@ class FakeTetherController : public TetherController {
Status GetStatus() const override;
private:
// TetherController:
void ScanForAvailableConnection() override;
void AttemptConnection() override;
void Disconnect() override;
......
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