Commit 17e14fc0 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS PhoneHub] Create FindMyDeviceController

This class provides an interface for the Phone Hub UI to ring the
connected phone as part of the FindMyDevice feature; additionally, it
provides an API for checking whether the phone is currently ringing.

The implementation of setting/retrieving the phone ringing state will be
part of a future CL.

Bug: 1106937
Change-Id: Ia100f320bd782e307fdae85581ef45b43bcc1c2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2378728
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarRegan Hsu <hsuregan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802315}
parent edb6e5ef
...@@ -20,6 +20,10 @@ static_library("phonehub") { ...@@ -20,6 +20,10 @@ static_library("phonehub") {
"feature_status_provider.h", "feature_status_provider.h",
"feature_status_provider_impl.cc", "feature_status_provider_impl.cc",
"feature_status_provider_impl.h", "feature_status_provider_impl.h",
"find_my_device_controller.cc",
"find_my_device_controller.h",
"find_my_device_controller_impl.cc",
"find_my_device_controller_impl.h",
"mutable_phone_model.cc", "mutable_phone_model.cc",
"mutable_phone_model.h", "mutable_phone_model.h",
"notification.cc", "notification.cc",
...@@ -71,6 +75,8 @@ static_library("test_support") { ...@@ -71,6 +75,8 @@ static_library("test_support") {
"fake_do_not_disturb_controller.h", "fake_do_not_disturb_controller.h",
"fake_feature_status_provider.cc", "fake_feature_status_provider.cc",
"fake_feature_status_provider.h", "fake_feature_status_provider.h",
"fake_find_my_device_controller.cc",
"fake_find_my_device_controller.h",
"fake_notification_access_manager.cc", "fake_notification_access_manager.cc",
"fake_notification_access_manager.h", "fake_notification_access_manager.h",
"fake_notification_manager.cc", "fake_notification_manager.cc",
...@@ -95,6 +101,7 @@ source_set("unit_tests") { ...@@ -95,6 +101,7 @@ source_set("unit_tests") {
"browser_tabs_model_unittest.cc", "browser_tabs_model_unittest.cc",
"do_not_disturb_controller_impl_unittest.cc", "do_not_disturb_controller_impl_unittest.cc",
"feature_status_provider_impl_unittest.cc", "feature_status_provider_impl_unittest.cc",
"find_my_device_controller_impl_unittest.cc",
"mutable_phone_model_unittest.cc", "mutable_phone_model_unittest.cc",
"notification_access_manager_impl_unittest.cc", "notification_access_manager_impl_unittest.cc",
"notification_manager_impl_unittest.cc", "notification_manager_impl_unittest.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 "chromeos/components/phonehub/fake_find_my_device_controller.h"
namespace chromeos {
namespace phonehub {
FakeFindMyDeviceController::FakeFindMyDeviceController() = default;
FakeFindMyDeviceController::~FakeFindMyDeviceController() = default;
bool FakeFindMyDeviceController::IsPhoneRinging() const {
return is_phone_ringing_;
}
void FakeFindMyDeviceController::SetPhoneRingingState(bool ringing) {
if (is_phone_ringing_ == ringing)
return;
is_phone_ringing_ = ringing;
NotifyPhoneRingingStateChanged();
}
} // namespace phonehub
} // namespace chromeos
// 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 CHROMEOS_COMPONENTS_PHONEHUB_FAKE_FIND_MY_DEVICE_CONTROLLER_H_
#define CHROMEOS_COMPONENTS_PHONEHUB_FAKE_FIND_MY_DEVICE_CONTROLLER_H_
#include "chromeos/components/phonehub/find_my_device_controller.h"
namespace chromeos {
namespace phonehub {
class FakeFindMyDeviceController : public FindMyDeviceController {
public:
FakeFindMyDeviceController();
~FakeFindMyDeviceController() override;
// FindMyDeviceController:
bool IsPhoneRinging() const override;
void SetPhoneRingingState(bool ringing) override;
private:
bool is_phone_ringing_ = false;
};
} // namespace phonehub
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_PHONEHUB_FAKE_FIND_MY_DEVICE_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 "chromeos/components/phonehub/find_my_device_controller.h"
namespace chromeos {
namespace phonehub {
FindMyDeviceController::FindMyDeviceController() = default;
FindMyDeviceController::~FindMyDeviceController() = default;
void FindMyDeviceController::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer);
}
void FindMyDeviceController::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
void FindMyDeviceController::NotifyPhoneRingingStateChanged() {
for (auto& observer : observer_list_)
observer.OnPhoneRingingStateChanged();
}
} // namespace phonehub
} // namespace chromeos
// 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 CHROMEOS_COMPONENTS_PHONEHUB_FIND_MY_DEVICE_CONTROLLER_H_
#define CHROMEOS_COMPONENTS_PHONEHUB_FIND_MY_DEVICE_CONTROLLER_H_
#include "base/observer_list.h"
#include "base/observer_list_types.h"
namespace chromeos {
namespace phonehub {
// Provides functionality for ringing the connected phone via the Find My Device
// feature.
class FindMyDeviceController {
public:
class Observer : public base::CheckedObserver {
public:
~Observer() override = default;
virtual void OnPhoneRingingStateChanged() = 0;
};
FindMyDeviceController(const FindMyDeviceController&) = delete;
FindMyDeviceController& operator=(const FindMyDeviceController&) = delete;
virtual ~FindMyDeviceController();
// Returns whether the phone is ringing as a result of Find My Device
// functionality. Note that this function does not return true if the phone is
// ringing for another reason (e.g., a normal phone call).
virtual bool IsPhoneRinging() const = 0;
// Note: Ringing the phone via Find My Device is not a synchronous operation,
// since it requires sending a message to the connected phone. Use the
// observer interface to be notified of when the state changes.
virtual void SetPhoneRingingState(bool ringing) = 0;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
protected:
FindMyDeviceController();
void NotifyPhoneRingingStateChanged();
private:
base::ObserverList<Observer> observer_list_;
};
} // namespace phonehub
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_PHONEHUB_FIND_MY_DEVICE_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 "chromeos/components/phonehub/find_my_device_controller_impl.h"
#include "chromeos/components/multidevice/logging/logging.h"
namespace chromeos {
namespace phonehub {
FindMyDeviceControllerImpl::FindMyDeviceControllerImpl() = default;
FindMyDeviceControllerImpl::~FindMyDeviceControllerImpl() = default;
bool FindMyDeviceControllerImpl::IsPhoneRinging() const {
return is_phone_ringing_;
}
void FindMyDeviceControllerImpl::SetPhoneRingingState(bool ringing) {
PA_LOG(INFO) << "Attempting to set Find My Device phone ring state; new "
<< "value: " << ringing;
}
} // namespace phonehub
} // namespace chromeos
// 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 CHROMEOS_COMPONENTS_PHONEHUB_FIND_MY_DEVICE_CONTROLLER_IMPL_H_
#define CHROMEOS_COMPONENTS_PHONEHUB_FIND_MY_DEVICE_CONTROLLER_IMPL_H_
#include "chromeos/components/phonehub/find_my_device_controller.h"
namespace chromeos {
namespace phonehub {
// TODO(https://crbug.com/1106937): Add real implementation.
class FindMyDeviceControllerImpl : public FindMyDeviceController {
public:
FindMyDeviceControllerImpl();
~FindMyDeviceControllerImpl() override;
private:
// FindMyDeviceController:
bool IsPhoneRinging() const override;
void SetPhoneRingingState(bool ringing) override;
bool is_phone_ringing_ = false;
};
} // namespace phonehub
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_PHONEHUB_FIND_MY_DEVICE_CONTROLLER_IMPL_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 "chromeos/components/phonehub/find_my_device_controller_impl.h"
#include <memory>
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace phonehub {
namespace {
class FakeObserver : public FindMyDeviceController::Observer {
public:
FakeObserver() = default;
~FakeObserver() override = default;
size_t num_calls() const { return num_calls_; }
// FindMyDeviceController::Observer:
void OnPhoneRingingStateChanged() override { ++num_calls_; }
private:
size_t num_calls_ = 0;
};
} // namespace
class FindMyDeviceControllerImplTest : public testing::Test {
protected:
FindMyDeviceControllerImplTest() = default;
FindMyDeviceControllerImplTest(const FindMyDeviceControllerImplTest&) =
delete;
FindMyDeviceControllerImplTest& operator=(
const FindMyDeviceControllerImplTest&) = delete;
~FindMyDeviceControllerImplTest() override = default;
// testing::Test:
void SetUp() override {
controller_ = std::make_unique<FindMyDeviceControllerImpl>();
controller_->AddObserver(&fake_observer_);
}
void TearDown() override { controller_->RemoveObserver(&fake_observer_); }
bool IsPhoneRinging() const { return controller_->IsPhoneRinging(); }
size_t GetNumObserverCalls() const { return fake_observer_.num_calls(); }
private:
FakeObserver fake_observer_;
std::unique_ptr<FindMyDeviceController> controller_;
};
// TODO(https://crbug.com/1106937): Remove this test once we have real
// functionality to test.
TEST_F(FindMyDeviceControllerImplTest, Initialize) {
EXPECT_FALSE(IsPhoneRinging());
}
} // namespace phonehub
} // namespace chromeos
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