diff options
author | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-18 04:41:42 +0000 |
---|---|---|
committer | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-18 04:41:42 +0000 |
commit | 896619e714a5510c34a8d2b3d80741786d96e30b (patch) | |
tree | 9ef02ddc4df476097001c764e8172d18df804071 /chromeos | |
parent | b520cfffb5be192d59638f5a8530ba88933f8973 (diff) | |
download | chromium_src-896619e714a5510c34a8d2b3d80741786d96e30b.zip chromium_src-896619e714a5510c34a8d2b3d80741786d96e30b.tar.gz chromium_src-896619e714a5510c34a8d2b3d80741786d96e30b.tar.bz2 |
Bluetooth: implement BlueZ 5 backend for Chrome OS
Provides an implementation for adapter control, device discovery,
pairing, connection, disconnection and unpairing using the BlueZ 5.x
backend on Chrome OS.
Uses Fake* classes for testing instead of Mocks.
TBR=youngki@chromium.org
BUG=220951
TEST=device_unittests
Review URL: https://chromiumcodereview.appspot.com/13927010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
21 files changed, 1906 insertions, 375 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 651cdc9..9a1b58c 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -82,6 +82,18 @@ 'dbus/experimental_bluetooth_profile_manager_client.h', 'dbus/experimental_bluetooth_profile_service_provider.cc', 'dbus/experimental_bluetooth_profile_service_provider.h', + 'dbus/fake_bluetooth_adapter_client.cc', + 'dbus/fake_bluetooth_adapter_client.h', + 'dbus/fake_bluetooth_agent_manager_client.cc', + 'dbus/fake_bluetooth_agent_manager_client.h', + 'dbus/fake_bluetooth_agent_service_provider.cc', + 'dbus/fake_bluetooth_agent_service_provider.h', + 'dbus/fake_bluetooth_device_client.cc', + 'dbus/fake_bluetooth_device_client.h', + 'dbus/fake_bluetooth_profile_manager_client.cc', + 'dbus/fake_bluetooth_profile_manager_client.h', + 'dbus/fake_bluetooth_profile_service_provider.cc', + 'dbus/fake_bluetooth_profile_service_provider.h', 'dbus/gsm_sms_client.cc', 'dbus/gsm_sms_client.h', 'dbus/shill_client_helper.cc', diff --git a/chromeos/dbus/experimental_bluetooth_adapter_client.cc b/chromeos/dbus/experimental_bluetooth_adapter_client.cc index 53ac357..34b8ae1 100644 --- a/chromeos/dbus/experimental_bluetooth_adapter_client.cc +++ b/chromeos/dbus/experimental_bluetooth_adapter_client.cc @@ -4,11 +4,9 @@ #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" -#include <map> - #include "base/bind.h" #include "base/logging.h" -#include "chromeos/dbus/bluetooth_property.h" +#include "chromeos/dbus/fake_bluetooth_adapter_client.h" #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_manager.h" @@ -252,122 +250,6 @@ class ExperimentalBluetoothAdapterClientImpl DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothAdapterClientImpl); }; -// The ExperimentalBluetoothAdapterClient implementation used on Linux desktop, -// which does nothing. -class ExperimentalBluetoothAdapterClientStubImpl - : public ExperimentalBluetoothAdapterClient { - public: - struct Properties : public ExperimentalBluetoothAdapterClient::Properties { - explicit Properties(const PropertyChangedCallback& callback) - : ExperimentalBluetoothAdapterClient::Properties( - NULL, - bluetooth_adapter::kExperimentalBluetoothAdapterInterface, - callback) { - } - - virtual ~Properties() { - } - - virtual void Get(dbus::PropertyBase* property, - dbus::PropertySet::GetCallback callback) OVERRIDE { - VLOG(1) << "Get " << property->name(); - callback.Run(false); - } - - virtual void GetAll() OVERRIDE { - VLOG(1) << "GetAll"; - } - - virtual void Set(dbus::PropertyBase *property, - dbus::PropertySet::SetCallback callback) OVERRIDE { - VLOG(1) << "Set " << property->name(); - if (property->name() == "Powered") { - property->ReplaceValueWithSetValue(); - NotifyPropertyChanged(property->name()); - callback.Run(true); - } else { - callback.Run(false); - } - } - }; - - ExperimentalBluetoothAdapterClientStubImpl() { - properties_.reset(new Properties(base::Bind( - &ExperimentalBluetoothAdapterClientStubImpl::OnPropertyChanged, - base::Unretained(this)))); - - properties_->address.ReplaceValue("hci0"); - properties_->name.ReplaceValue("Fake Adapter"); - properties_->pairable.ReplaceValue(true); - } - - // ExperimentalBluetoothAdapterClient override. - virtual void AddObserver(Observer* observer) OVERRIDE { - observers_.AddObserver(observer); - } - - // ExperimentalBluetoothAdapterClient override. - virtual void RemoveObserver(Observer* observer) OVERRIDE { - observers_.RemoveObserver(observer); - } - - // ExperimentalBluetoothAdapterClient override. - virtual std::vector<dbus::ObjectPath> GetAdapters() OVERRIDE { - std::vector<dbus::ObjectPath> object_paths; - object_paths.push_back(dbus::ObjectPath("/fake/hci0")); - return object_paths; - } - - // ExperimentalBluetoothAdapterClient override. - virtual Properties* GetProperties(const dbus::ObjectPath& object_path) - OVERRIDE { - VLOG(1) << "GetProperties: " << object_path.value(); - if (object_path.value() == "/fake/hci0") - return properties_.get(); - else - return NULL; - } - - // ExperimentalBluetoothAdapterClient override. - virtual void StartDiscovery(const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE { - VLOG(1) << "StartDiscovery: " << object_path.value(); - error_callback.Run(kNoResponseError, ""); - } - - // ExperimentalBluetoothAdapterClient override. - virtual void StopDiscovery(const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE { - VLOG(1) << "StopDiscovery: " << object_path.value(); - error_callback.Run(kNoResponseError, ""); - } - - // ExperimentalBluetoothAdapterClient override. - virtual void RemoveDevice(const dbus::ObjectPath& object_path, - const dbus::ObjectPath& device_path, - const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE { - VLOG(1) << "RemoveDevice: " << object_path.value() - << " " << device_path.value(); - error_callback.Run(kNoResponseError, ""); - } - - private: - void OnPropertyChanged(const std::string& property_name) { - FOR_EACH_OBSERVER(ExperimentalBluetoothAdapterClient::Observer, observers_, - AdapterPropertyChanged(dbus::ObjectPath("/fake/hci0"), - property_name)); - } - - // List of observers interested in event notifications from us. - ObserverList<Observer> observers_; - - // Static properties we return. - scoped_ptr<Properties> properties_; -}; - ExperimentalBluetoothAdapterClient::ExperimentalBluetoothAdapterClient() { } @@ -380,7 +262,7 @@ ExperimentalBluetoothAdapterClient* ExperimentalBluetoothAdapterClient::Create( if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) return new ExperimentalBluetoothAdapterClientImpl(bus); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); - return new ExperimentalBluetoothAdapterClientStubImpl(); + return new FakeBluetoothAdapterClient(); } } // namespace chromeos diff --git a/chromeos/dbus/experimental_bluetooth_agent_manager_client.cc b/chromeos/dbus/experimental_bluetooth_agent_manager_client.cc index d20e874..9055b41 100644 --- a/chromeos/dbus/experimental_bluetooth_agent_manager_client.cc +++ b/chromeos/dbus/experimental_bluetooth_agent_manager_client.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/logging.h" +#include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_path.h" @@ -137,41 +138,6 @@ class ExperimentalBluetoothAgentManagerClientImpl DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothAgentManagerClientImpl); }; -// The ExperimentalBluetoothAgentManagerClient implementation used on Linux -// desktop, which does nothing. -class ExperimentalBluetoothAgentManagerClientStubImpl - : public ExperimentalBluetoothAgentManagerClient { - public: - ExperimentalBluetoothAgentManagerClientStubImpl() { - } - - // ExperimentalBluetoothAgentManagerClient override. - virtual void RegisterAgent(const dbus::ObjectPath& agent_path, - const std::string& capability, - const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE { - VLOG(1) << "RegisterAgent: " << agent_path.value(); - error_callback.Run(kNoResponseError, ""); - } - - // ExperimentalBluetoothAgentManagerClient override. - virtual void UnregisterAgent(const dbus::ObjectPath& agent_path, - const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE { - VLOG(1) << "UnregisterAgent: " << agent_path.value(); - error_callback.Run(kNoResponseError, ""); - } - - // ExperimentalBluetoothAgentManagerClient override. - virtual void RequestDefaultAgent(const dbus::ObjectPath& agent_path, - const base::Closure& callback, - const ErrorCallback& error_callback) - OVERRIDE { - VLOG(1) << "RequestDefaultAgent: " << agent_path.value(); - error_callback.Run(kNoResponseError, ""); - } -}; - ExperimentalBluetoothAgentManagerClient:: ExperimentalBluetoothAgentManagerClient() { } @@ -187,7 +153,7 @@ ExperimentalBluetoothAgentManagerClient* if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) return new ExperimentalBluetoothAgentManagerClientImpl(bus); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); - return new ExperimentalBluetoothAgentManagerClientStubImpl(); + return new FakeBluetoothAgentManagerClient(); } } // namespace chromeos diff --git a/chromeos/dbus/experimental_bluetooth_agent_service_provider.cc b/chromeos/dbus/experimental_bluetooth_agent_service_provider.cc index 0e77d77..6501cef 100644 --- a/chromeos/dbus/experimental_bluetooth_agent_service_provider.cc +++ b/chromeos/dbus/experimental_bluetooth_agent_service_provider.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/memory/ref_counted.h" #include "base/threading/platform_thread.h" +#include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" #include "dbus/bus.h" #include "dbus/exported_object.h" #include "dbus/message.h" @@ -481,19 +482,6 @@ class ExperimentalBluetoothAgentServiceProviderImpl DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothAgentServiceProviderImpl); }; -// The ExperimentalBluetoothAgentServiceProvider implementation used on Linux -// desktop, which does nothing. -class ExperimentalBluetoothAgentServiceProviderStubImpl - : public ExperimentalBluetoothAgentServiceProvider { - public: - explicit ExperimentalBluetoothAgentServiceProviderStubImpl( - Delegate* delegate) { - } - - virtual ~ExperimentalBluetoothAgentServiceProviderStubImpl() { - } -}; - ExperimentalBluetoothAgentServiceProvider:: ExperimentalBluetoothAgentServiceProvider() { } @@ -512,7 +500,7 @@ ExperimentalBluetoothAgentServiceProvider* return new ExperimentalBluetoothAgentServiceProviderImpl( bus, object_path, delegate); } else { - return new ExperimentalBluetoothAgentServiceProviderStubImpl(delegate); + return new FakeBluetoothAgentServiceProvider(object_path, delegate); } } diff --git a/chromeos/dbus/experimental_bluetooth_device_client.cc b/chromeos/dbus/experimental_bluetooth_device_client.cc index 7015e5f..9de3c94 100644 --- a/chromeos/dbus/experimental_bluetooth_device_client.cc +++ b/chromeos/dbus/experimental_bluetooth_device_client.cc @@ -4,13 +4,10 @@ #include "chromeos/dbus/experimental_bluetooth_device_client.h" -#include <map> -#include <utility> - #include "base/bind.h" #include "base/logging.h" #include "base/stl_util.h" -#include "chromeos/dbus/bluetooth_property.h" +#include "chromeos/dbus/fake_bluetooth_device_client.h" #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_manager.h" @@ -343,155 +340,6 @@ class ExperimentalBluetoothDeviceClientImpl DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothDeviceClientImpl); }; -// The ExperimentalBluetoothDeviceClient implementation used on Linux desktop, -// which does nothing. -class ExperimentalBluetoothDeviceClientStubImpl - : public ExperimentalBluetoothDeviceClient { - public: - struct Properties : public ExperimentalBluetoothDeviceClient::Properties { - explicit Properties(const PropertyChangedCallback& callback) - : ExperimentalBluetoothDeviceClient::Properties( - NULL, - bluetooth_device::kExperimentalBluetoothDeviceInterface, - callback) { - } - - virtual ~Properties() { - } - - virtual void Get(dbus::PropertyBase* property, - dbus::PropertySet::GetCallback callback) OVERRIDE { - VLOG(1) << "Get " << property->name(); - callback.Run(false); - } - - virtual void GetAll() OVERRIDE { - VLOG(1) << "GetAll"; - } - - virtual void Set(dbus::PropertyBase *property, - dbus::PropertySet::SetCallback callback) OVERRIDE { - VLOG(1) << "Set " << property->name(); - callback.Run(false); - } - }; - - ExperimentalBluetoothDeviceClientStubImpl() { - dbus::ObjectPath dev0("/fake/hci0/dev0"); - - Properties* properties = new Properties(base::Bind( - &ExperimentalBluetoothDeviceClientStubImpl::OnPropertyChanged, - base::Unretained(this), - dev0)); - properties->address.ReplaceValue("00:11:22:33:44:55"); - properties->name.ReplaceValue("Fake Device"); - properties->paired.ReplaceValue(true); - properties->trusted.ReplaceValue(true); - - properties_map_[dev0] = properties; - } - - virtual ~ExperimentalBluetoothDeviceClientStubImpl() { - // Clean up Properties structures - STLDeleteValues(&properties_map_); - } - - // ExperimentalBluetoothDeviceClient override. - virtual void AddObserver(Observer* observer) OVERRIDE { - observers_.AddObserver(observer); - } - - // ExperimentalBluetoothDeviceClient override. - virtual void RemoveObserver(Observer* observer) OVERRIDE { - observers_.RemoveObserver(observer); - } - - virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( - const dbus::ObjectPath& adapter_path) OVERRIDE { - std::vector<dbus::ObjectPath> object_paths; - if (adapter_path.value() == "/fake/hci0") - object_paths.push_back(dbus::ObjectPath("/fake/hci0/dev0")); - return object_paths; - } - - // ExperimentalBluetoothDeviceClient override. - virtual Properties* GetProperties(const dbus::ObjectPath& object_path) - OVERRIDE { - VLOG(1) << "GetProperties: " << object_path.value(); - PropertiesMap::iterator iter = properties_map_.find(object_path); - if (iter != properties_map_.end()) - return iter->second; - return NULL; - } - - // ExperimentalBluetoothDeviceClient override. - virtual void Connect(const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE { - VLOG(1) << "Connect: " << object_path.value(); - error_callback.Run(kNoResponseError, ""); - } - - // ExperimentalBluetoothDeviceClient override. - virtual void Disconnect(const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE { - VLOG(1) << "Disconnect: " << object_path.value(); - error_callback.Run(kNoResponseError, ""); - } - - // ExperimentalBluetoothDeviceClient override. - virtual void ConnectProfile(const dbus::ObjectPath& object_path, - const std::string& uuid, - const base::Closure& callback, - const ErrorCallback& error_callback) - OVERRIDE { - VLOG(1) << "ConnectProfile: " << object_path.value() << " " << uuid; - error_callback.Run(kNoResponseError, ""); - } - - // ExperimentalBluetoothDeviceClient override. - virtual void DisconnectProfile(const dbus::ObjectPath& object_path, - const std::string& uuid, - const base::Closure& callback, - const ErrorCallback& error_callback) - OVERRIDE { - VLOG(1) << "DisconnectProfile: " << object_path.value() << " " << uuid; - error_callback.Run(kNoResponseError, ""); - } - - // ExperimentalBluetoothDeviceClient override. - virtual void Pair(const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE { - VLOG(1) << "Pair: " << object_path.value(); - error_callback.Run(kNoResponseError, ""); - } - - // ExperimentalBluetoothDeviceClient override. - virtual void CancelPairing(const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) - OVERRIDE { - VLOG(1) << "CancelPairing: " << object_path.value(); - error_callback.Run(kNoResponseError, ""); - } - - private: - void OnPropertyChanged(dbus::ObjectPath object_path, - const std::string& property_name) { - FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, - DevicePropertyChanged(object_path, property_name)); - } - - // List of observers interested in event notifications from us. - ObserverList<Observer> observers_; - - // Static properties we typedef. - typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap; - PropertiesMap properties_map_; -}; - ExperimentalBluetoothDeviceClient::ExperimentalBluetoothDeviceClient() { } @@ -504,7 +352,7 @@ ExperimentalBluetoothDeviceClient* ExperimentalBluetoothDeviceClient::Create( if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) return new ExperimentalBluetoothDeviceClientImpl(bus); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); - return new ExperimentalBluetoothDeviceClientStubImpl(); + return new FakeBluetoothDeviceClient(); } } // namespace chromeos diff --git a/chromeos/dbus/experimental_bluetooth_profile_manager_client.cc b/chromeos/dbus/experimental_bluetooth_profile_manager_client.cc index c398827..dab9d93 100644 --- a/chromeos/dbus/experimental_bluetooth_profile_manager_client.cc +++ b/chromeos/dbus/experimental_bluetooth_profile_manager_client.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/logging.h" +#include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_path.h" @@ -229,33 +230,6 @@ class ExperimentalBluetoothProfileManagerClientImpl DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothProfileManagerClientImpl); }; -// The ExperimentalBluetoothProfileManagerClient implementation used on Linux -// desktop, which does nothing. -class ExperimentalBluetoothProfileManagerClientStubImpl - : public ExperimentalBluetoothProfileManagerClient { - public: - ExperimentalBluetoothProfileManagerClientStubImpl() { - } - - // ExperimentalBluetoothProfileManagerClient override. - virtual void RegisterProfile(const dbus::ObjectPath& profile_path, - const std::string& uuid, - const Options& options, - const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE { - VLOG(1) << "RegisterProfile: " << profile_path.value() << ": " << uuid; - error_callback.Run(kNoResponseError, ""); - } - - // ExperimentalBluetoothProfileManagerClient override. - virtual void UnregisterProfile(const dbus::ObjectPath& profile_path, - const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE { - VLOG(1) << "UnregisterAgent: " << profile_path.value(); - error_callback.Run(kNoResponseError, ""); - } -}; - ExperimentalBluetoothProfileManagerClient:: ExperimentalBluetoothProfileManagerClient() { } @@ -271,7 +245,7 @@ ExperimentalBluetoothProfileManagerClient* if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) return new ExperimentalBluetoothProfileManagerClientImpl(bus); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); - return new ExperimentalBluetoothProfileManagerClientStubImpl(); + return new FakeBluetoothProfileManagerClient(); } } // namespace chromeos diff --git a/chromeos/dbus/experimental_bluetooth_profile_service_provider.cc b/chromeos/dbus/experimental_bluetooth_profile_service_provider.cc index 30fa5e9..a58c8bc 100644 --- a/chromeos/dbus/experimental_bluetooth_profile_service_provider.cc +++ b/chromeos/dbus/experimental_bluetooth_profile_service_provider.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/memory/ref_counted.h" #include "base/threading/platform_thread.h" +#include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" #include "dbus/bus.h" #include "dbus/exported_object.h" #include "dbus/message.h" @@ -253,19 +254,6 @@ class ExperimentalBluetoothProfileServiceProviderImpl DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothProfileServiceProviderImpl); }; -// The ExperimentalBluetoothProfileServiceProvider implementation used on Linux -// desktop, which does nothing. -class ExperimentalBluetoothProfileServiceProviderStubImpl - : public ExperimentalBluetoothProfileServiceProvider { - public: - explicit ExperimentalBluetoothProfileServiceProviderStubImpl( - Delegate* delegate) { - } - - virtual ~ExperimentalBluetoothProfileServiceProviderStubImpl() { - } -}; - ExperimentalBluetoothProfileServiceProvider:: ExperimentalBluetoothProfileServiceProvider() { } @@ -284,7 +272,7 @@ ExperimentalBluetoothProfileServiceProvider* return new ExperimentalBluetoothProfileServiceProviderImpl( bus, object_path, delegate); } else { - return new ExperimentalBluetoothProfileServiceProviderStubImpl(delegate); + return new FakeBluetoothProfileServiceProvider(object_path, delegate); } } diff --git a/chromeos/dbus/fake_bluetooth_adapter_client.cc b/chromeos/dbus/fake_bluetooth_adapter_client.cc new file mode 100644 index 0000000..4d248c2 --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_adapter_client.cc @@ -0,0 +1,258 @@ +// Copyright (c) 2013 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/dbus/fake_bluetooth_adapter_client.h" + +#include "base/bind.h" +#include "base/logging.h" +#include "base/message_loop.h" +#include "base/time.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/fake_bluetooth_device_client.h" +#include "dbus/object_path.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace { + +// Amount of time to wait after a command before performing it. +const int kCommandEffectsTimeMs = 500; + +} + +namespace chromeos { + +const char FakeBluetoothAdapterClient::kAdapterPath[] = + "/fake/hci0"; +const char FakeBluetoothAdapterClient::kAdapterName[] = + "Fake Adapter"; +const char FakeBluetoothAdapterClient::kAdapterAddress[] = + "01:1a:2b:1a:2b:03"; + +const char FakeBluetoothAdapterClient::kSecondAdapterPath[] = + "/fake/hci1"; +const char FakeBluetoothAdapterClient::kSecondAdapterName[] = + "Second Fake Adapter"; +const char FakeBluetoothAdapterClient::kSecondAdapterAddress[] = + "00:de:51:10:01:00"; + +FakeBluetoothAdapterClient::Properties::Properties( + const PropertyChangedCallback& callback) + : ExperimentalBluetoothAdapterClient::Properties( + NULL, + bluetooth_adapter::kExperimentalBluetoothAdapterInterface, + callback) { +} + +FakeBluetoothAdapterClient::Properties::~Properties() { +} + +void FakeBluetoothAdapterClient::Properties::Get( + dbus::PropertyBase* property, + dbus::PropertySet::GetCallback callback) { + VLOG(1) << "Get " << property->name(); + callback.Run(false); +} + +void FakeBluetoothAdapterClient::Properties::GetAll() { + VLOG(1) << "GetAll"; +} + +void FakeBluetoothAdapterClient::Properties::Set( + dbus::PropertyBase *property, + dbus::PropertySet::SetCallback callback) { + VLOG(1) << "Set " << property->name(); + if (property->name() == powered.name() || property->name() == alias.name()) { + callback.Run(true); + property->ReplaceValueWithSetValue(); + NotifyPropertyChanged(property->name()); + } else { + callback.Run(false); + } +} + + +FakeBluetoothAdapterClient::FakeBluetoothAdapterClient() + : visible_(true), + second_visible_(false), + discovering_count_(0) { + properties_.reset(new Properties(base::Bind( + &FakeBluetoothAdapterClient::OnPropertyChanged, + base::Unretained(this)))); + + properties_->address.ReplaceValue(kAdapterAddress); + properties_->name.ReplaceValue("Fake Adapter (Name)"); + properties_->alias.ReplaceValue(kAdapterName); + properties_->pairable.ReplaceValue(true); + + second_properties_.reset(new Properties(base::Bind( + &FakeBluetoothAdapterClient::OnPropertyChanged, + base::Unretained(this)))); + + second_properties_->address.ReplaceValue(kSecondAdapterAddress); + second_properties_->name.ReplaceValue("Second Fake Adapter (Name)"); + second_properties_->alias.ReplaceValue(kSecondAdapterName); + second_properties_->pairable.ReplaceValue(true); +} + +FakeBluetoothAdapterClient::~FakeBluetoothAdapterClient() { +} + +void FakeBluetoothAdapterClient::AddObserver(Observer* observer) { + observers_.AddObserver(observer); +} + +void FakeBluetoothAdapterClient::RemoveObserver(Observer* observer) { + observers_.RemoveObserver(observer); +} + +std::vector<dbus::ObjectPath> FakeBluetoothAdapterClient::GetAdapters() { + std::vector<dbus::ObjectPath> object_paths; + if (visible_) + object_paths.push_back(dbus::ObjectPath(kAdapterPath)); + if (second_visible_) + object_paths.push_back(dbus::ObjectPath(kSecondAdapterPath)); + return object_paths; +} + +FakeBluetoothAdapterClient::Properties* +FakeBluetoothAdapterClient::GetProperties(const dbus::ObjectPath& object_path) { + if (object_path == dbus::ObjectPath(kAdapterPath)) + return properties_.get(); + else if (object_path == dbus::ObjectPath(kSecondAdapterPath)) + return second_properties_.get(); + else + return NULL; +} + +void FakeBluetoothAdapterClient::StartDiscovery( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + if (object_path != dbus::ObjectPath(kAdapterPath)) { + error_callback.Run(kNoResponseError, ""); + return; + } + + ++discovering_count_; + VLOG(1) << "StartDiscovery: " << object_path.value() << ", " + << "count is now " << discovering_count_; + callback.Run(); + + if (discovering_count_ == 1) { + properties_->discovering.ReplaceValue(true); + properties_->NotifyPropertyChanged(properties_->discovering.name()); + + FakeBluetoothDeviceClient* device_client = + static_cast<FakeBluetoothDeviceClient*>( + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()); + device_client->BeginDiscoverySimulation(dbus::ObjectPath(kAdapterPath)); + } +} + +void FakeBluetoothAdapterClient::StopDiscovery( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + if (object_path != dbus::ObjectPath(kAdapterPath)) { + error_callback.Run(kNoResponseError, ""); + return; + } + + if (!discovering_count_) { + LOG(WARNING) << "StopDiscovery called when not discovering"; + error_callback.Run(kNoResponseError, ""); + return; + } + + --discovering_count_; + VLOG(1) << "StopDiscovery: " << object_path.value() << ", " + << "count is now " << discovering_count_; + callback.Run(); + + if (discovering_count_ == 0) { + FakeBluetoothDeviceClient* device_client = + static_cast<FakeBluetoothDeviceClient*>( + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()); + device_client->EndDiscoverySimulation(dbus::ObjectPath(kAdapterPath)); + + properties_->discovering.ReplaceValue(false); + properties_->NotifyPropertyChanged(properties_->discovering.name()); + } +} + +void FakeBluetoothAdapterClient::RemoveDevice( + const dbus::ObjectPath& object_path, + const dbus::ObjectPath& device_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + if (object_path != dbus::ObjectPath(kAdapterPath)) { + error_callback.Run(kNoResponseError, ""); + return; + } + + VLOG(1) << "RemoveDevice: " << object_path.value() + << " " << device_path.value(); + callback.Run(); + + FakeBluetoothDeviceClient* device_client = + static_cast<FakeBluetoothDeviceClient*>( + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()); + device_client->RemoveDevice(dbus::ObjectPath(kAdapterPath), device_path); +} + +void FakeBluetoothAdapterClient::SetVisible( + bool visible) { + if (visible && !visible_) { + // Adapter becoming visible + visible_ = visible; + + FOR_EACH_OBSERVER(ExperimentalBluetoothAdapterClient::Observer, observers_, + AdapterAdded(dbus::ObjectPath(kAdapterPath))); + + } else if (visible_ && !visible) { + // Adapter becoming invisible + visible_ = visible; + + FOR_EACH_OBSERVER(ExperimentalBluetoothAdapterClient::Observer, observers_, + AdapterRemoved(dbus::ObjectPath(kAdapterPath))); + } +} + +void FakeBluetoothAdapterClient::SetSecondVisible( + bool visible) { + if (visible && !second_visible_) { + // Second adapter becoming visible + second_visible_ = visible; + + FOR_EACH_OBSERVER(ExperimentalBluetoothAdapterClient::Observer, observers_, + AdapterAdded(dbus::ObjectPath(kSecondAdapterPath))); + + } else if (second_visible_ && !visible) { + // Second adapter becoming invisible + second_visible_ = visible; + + FOR_EACH_OBSERVER(ExperimentalBluetoothAdapterClient::Observer, observers_, + AdapterRemoved(dbus::ObjectPath(kSecondAdapterPath))); + } +} + +void FakeBluetoothAdapterClient::OnPropertyChanged( + const std::string& property_name) { + if (property_name == properties_->powered.name() && + !properties_->powered.value()) { + VLOG(1) << "Adapter powered off"; + + if (discovering_count_) { + discovering_count_ = 0; + properties_->discovering.ReplaceValue(false); + properties_->NotifyPropertyChanged(properties_->discovering.name()); + } + } + + FOR_EACH_OBSERVER(ExperimentalBluetoothAdapterClient::Observer, observers_, + AdapterPropertyChanged(dbus::ObjectPath(kAdapterPath), + property_name)); +} + +} // namespace chromeos diff --git a/chromeos/dbus/fake_bluetooth_adapter_client.h b/chromeos/dbus/fake_bluetooth_adapter_client.h new file mode 100644 index 0000000..72ce9d1 --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_adapter_client.h @@ -0,0 +1,93 @@ +// Copyright (c) 2013 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_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_ +#define CHROMEOS_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_ + +#include <vector> + +#include "base/bind.h" +#include "base/callback.h" +#include "base/observer_list.h" +#include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client_implementation_type.h" +#include "chromeos/dbus/experimental_bluetooth_adapter_client.h" +#include "dbus/object_path.h" +#include "dbus/property.h" + +namespace chromeos { + +// FakeBluetoothAdapterClient simulates the behavior of the Bluetooth Daemon +// adapter objects and is used both in test cases in place of a mock and on +// the Linux desktop. +class CHROMEOS_EXPORT FakeBluetoothAdapterClient + : public ExperimentalBluetoothAdapterClient { + public: + struct Properties : public ExperimentalBluetoothAdapterClient::Properties { + explicit Properties(const PropertyChangedCallback & callback); + virtual ~Properties(); + + // dbus::PropertySet override + virtual void Get(dbus::PropertyBase* property, + dbus::PropertySet::GetCallback callback) OVERRIDE; + virtual void GetAll() OVERRIDE; + virtual void Set(dbus::PropertyBase* property, + dbus::PropertySet::SetCallback callback) OVERRIDE; + }; + + FakeBluetoothAdapterClient(); + virtual ~FakeBluetoothAdapterClient(); + + // ExperimentalBluetoothAdapterClient override + virtual void AddObserver(Observer* observer) OVERRIDE; + virtual void RemoveObserver(Observer* observer) OVERRIDE; + virtual std::vector<dbus::ObjectPath> GetAdapters() OVERRIDE; + virtual Properties* GetProperties(const dbus::ObjectPath& object_path) + OVERRIDE; + virtual void StartDiscovery(const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void StopDiscovery(const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void RemoveDevice(const dbus::ObjectPath& object_path, + const dbus::ObjectPath& device_path, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + + // Mark the adapter and second adapter as visible or invisible. + void SetVisible(bool visible); + void SetSecondVisible(bool visible); + + // Object path, name and addresses of the adapters we emulate. + static const char kAdapterPath[]; + static const char kAdapterName[]; + static const char kAdapterAddress[]; + + static const char kSecondAdapterPath[]; + static const char kSecondAdapterName[]; + static const char kSecondAdapterAddress[]; + + private: + // Property callback passed when we create Properties* structures. + void OnPropertyChanged(const std::string& property_name); + + // List of observers interested in event notifications from us. + ObserverList<Observer> observers_; + + // Static properties we return. + scoped_ptr<Properties> properties_; + scoped_ptr<Properties> second_properties_; + + // Whether the adapter and second adapter should be visible or not. + bool visible_; + bool second_visible_; + + // Number of times we've been asked to discover. + int discovering_count_; +}; + +} // namespace chromeos + +#endif /* CHROMEOS_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_ */ diff --git a/chromeos/dbus/fake_bluetooth_agent_manager_client.cc b/chromeos/dbus/fake_bluetooth_agent_manager_client.cc new file mode 100644 index 0000000..f7fc81e --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_agent_manager_client.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2013 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/dbus/fake_bluetooth_agent_manager_client.h" + +#include "base/bind.h" +#include "base/logging.h" +#include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" +#include "dbus/object_path.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace chromeos { + +FakeBluetoothAgentManagerClient::FakeBluetoothAgentManagerClient() + : service_provider_(NULL) { +} + +FakeBluetoothAgentManagerClient::~FakeBluetoothAgentManagerClient() { +} + +void FakeBluetoothAgentManagerClient::RegisterAgent( + const dbus::ObjectPath& agent_path, + const std::string& capability, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "RegisterAgent: " << agent_path.value(); + + if (service_provider_ == NULL) { + error_callback.Run(bluetooth_adapter::kErrorFailed, + "No agent created"); + } else if (service_provider_->object_path_ != agent_path) { + error_callback.Run(bluetooth_adapter::kErrorAlreadyExists, + "Agent already registered"); + } else { + callback.Run(); + } +} + +void FakeBluetoothAgentManagerClient::UnregisterAgent( + const dbus::ObjectPath& agent_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "UnregisterAgent: " << agent_path.value(); + if (service_provider_ != NULL) { + error_callback.Run(bluetooth_adapter::kErrorFailed, + "Agent still registered"); + } else { + callback.Run(); + } +} + +void FakeBluetoothAgentManagerClient::RequestDefaultAgent( + const dbus::ObjectPath& agent_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "RequestDefaultAgent: " << agent_path.value(); + callback.Run(); +} + +void FakeBluetoothAgentManagerClient::RegisterAgentServiceProvider( + FakeBluetoothAgentServiceProvider* service_provider) { + service_provider_ = service_provider; +} + +void FakeBluetoothAgentManagerClient::UnregisterAgentServiceProvider( + FakeBluetoothAgentServiceProvider* service_provider) { + if (service_provider_ == service_provider) + service_provider_ = NULL; +} + +FakeBluetoothAgentServiceProvider* +FakeBluetoothAgentManagerClient::GetAgentServiceProvider() { + return service_provider_; +} + +} // namespace chromeos diff --git a/chromeos/dbus/fake_bluetooth_agent_manager_client.h b/chromeos/dbus/fake_bluetooth_agent_manager_client.h new file mode 100644 index 0000000..9874f6b --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_agent_manager_client.h @@ -0,0 +1,58 @@ +// Copyright (c) 2013 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_DBUS_FAKE_BLUETOOTH_AGENT_MANAGER_CLIENT_H_ +#define CHROMEOS_DBUS_FAKE_BLUETOOTH_AGENT_MANAGER_CLIENT_H_ + +#include "base/bind.h" +#include "base/callback.h" +#include "base/observer_list.h" +#include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client_implementation_type.h" +#include "chromeos/dbus/experimental_bluetooth_agent_manager_client.h" +#include "dbus/object_path.h" +#include "dbus/property.h" + +namespace chromeos { + +class FakeBluetoothAgentServiceProvider; + +// FakeBluetoothAgentManagerClient simulates the behavior of the Bluetooth +// Daemon's agent manager object and is used both in test cases in place of a +// mock and on the Linux desktop. +class CHROMEOS_EXPORT FakeBluetoothAgentManagerClient + : public ExperimentalBluetoothAgentManagerClient { + public: + FakeBluetoothAgentManagerClient(); + virtual ~FakeBluetoothAgentManagerClient(); + + // ExperimentalBluetoothAgentManagerClient override + virtual void RegisterAgent(const dbus::ObjectPath& agent_path, + const std::string& capability, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void UnregisterAgent(const dbus::ObjectPath& agent_path, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void RequestDefaultAgent(const dbus::ObjectPath& agent_path, + const base::Closure& callback, + const ErrorCallback& error_callback) + OVERRIDE; + + // Register, unregister and retrieve pointers to agent service providers. + void RegisterAgentServiceProvider( + FakeBluetoothAgentServiceProvider* service_provider); + void UnregisterAgentServiceProvider( + FakeBluetoothAgentServiceProvider* service_provider); + FakeBluetoothAgentServiceProvider* GetAgentServiceProvider(); + + private: + // The single agent service provider we permit, owned by the application + // using it. + FakeBluetoothAgentServiceProvider* service_provider_; +}; + +} // namespace chromeos + +#endif /* CHROMEOS_DBUS_FAKE_BLUETOOTH_AGENT_MANAGER_CLIENT_H_ */ diff --git a/chromeos/dbus/fake_bluetooth_agent_service_provider.cc b/chromeos/dbus/fake_bluetooth_agent_service_provider.cc new file mode 100644 index 0000000..16ba3c0 --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_agent_service_provider.cc @@ -0,0 +1,105 @@ +// Copyright (c) 2013 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/dbus/fake_bluetooth_agent_service_provider.h" + +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" +#include "dbus/object_path.h" + +namespace chromeos { + +FakeBluetoothAgentServiceProvider::FakeBluetoothAgentServiceProvider( + const dbus::ObjectPath& object_path, + Delegate* delegate) + : object_path_(object_path), + delegate_(delegate) { + VLOG(1) << "Creating Bluetooth Agent: " << object_path_.value(); + + FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = + static_cast<FakeBluetoothAgentManagerClient*>( + DBusThreadManager::Get()-> + GetExperimentalBluetoothAgentManagerClient()); + fake_bluetooth_agent_manager_client->RegisterAgentServiceProvider(this); +} + +FakeBluetoothAgentServiceProvider::~FakeBluetoothAgentServiceProvider() { + VLOG(1) << "Cleaning up Bluetooth Agent: " << object_path_.value(); + + FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = + static_cast<FakeBluetoothAgentManagerClient*>( + DBusThreadManager::Get()-> + GetExperimentalBluetoothAgentManagerClient()); + fake_bluetooth_agent_manager_client->UnregisterAgentServiceProvider(this); +} + +void FakeBluetoothAgentServiceProvider::Release() { + VLOG(1) << object_path_.value() << ": Release"; + delegate_->Release(); +} + +void FakeBluetoothAgentServiceProvider::RequestPinCode( + const dbus::ObjectPath& device_path, + const Delegate::PinCodeCallback& callback) { + VLOG(1) << object_path_.value() << ": RequestPinCode for " + << device_path.value(); + delegate_->RequestPinCode(device_path, callback); +} + +void FakeBluetoothAgentServiceProvider::DisplayPinCode( + const dbus::ObjectPath& device_path, + const std::string& pincode) { + VLOG(1) << object_path_.value() << ": DisplayPincode " << pincode << " for " + << device_path.value(); + delegate_->DisplayPinCode(device_path, pincode); +} + +void FakeBluetoothAgentServiceProvider::RequestPasskey( + const dbus::ObjectPath& device_path, + const Delegate::PasskeyCallback& callback) { + VLOG(1) << object_path_.value() << ": RequestPasskey for " + << device_path.value(); + delegate_->RequestPasskey(device_path, callback); +} + +void FakeBluetoothAgentServiceProvider::DisplayPasskey( + const dbus::ObjectPath& device_path, + uint32 passkey, int16 entered) { + VLOG(1) << object_path_.value() << ": DisplayPasskey " << passkey + << " (" << entered << " entered) for "<< device_path.value(); + delegate_->DisplayPasskey(device_path, passkey, entered); +} + +void FakeBluetoothAgentServiceProvider::RequestConfirmation( + const dbus::ObjectPath& device_path, + uint32 passkey, + const Delegate::ConfirmationCallback& callback) { + VLOG(1) << object_path_.value() << ": RequestConfirmation " << passkey + << " for "<< device_path.value(); + delegate_->RequestConfirmation(device_path, passkey, callback); +} + +void FakeBluetoothAgentServiceProvider::RequestAuthorization( + const dbus::ObjectPath& device_path, + const Delegate::ConfirmationCallback& callback) { + VLOG(1) << object_path_.value() << ": RequestAuthorization for " + << device_path.value(); + delegate_->RequestAuthorization(device_path, callback); +} + +void FakeBluetoothAgentServiceProvider::AuthorizeService( + const dbus::ObjectPath& device_path, + const std::string& uuid, + const Delegate::ConfirmationCallback& callback) { + VLOG(1) << object_path_.value() << ": AuthorizeService " << uuid << " for " + << device_path.value(); + delegate_->AuthorizeService(device_path, uuid, callback); +} + +void FakeBluetoothAgentServiceProvider::Cancel() { + VLOG(1) << object_path_.value() << ": Cancel"; + delegate_->Cancel(); +} + +} // namespace chromeos diff --git a/chromeos/dbus/fake_bluetooth_agent_service_provider.h b/chromeos/dbus/fake_bluetooth_agent_service_provider.h new file mode 100644 index 0000000..23f232e --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_agent_service_provider.h @@ -0,0 +1,69 @@ +// Copyright (c) 2013 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_DBUS_FAKE_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_ +#define CHROMEOS_DBUS_FAKE_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_ + +#include "base/bind.h" +#include "base/callback.h" +#include "base/observer_list.h" +#include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client_implementation_type.h" +#include "chromeos/dbus/experimental_bluetooth_agent_service_provider.h" +#include "dbus/object_path.h" +#include "dbus/property.h" + +namespace chromeos { + +class FakeBluetoothAgentManagerClient; + +// FakeBluetoothAgentServiceProvider simulates the behavior of a local +// Bluetooth agent object and is used both in test cases in place of a +// mock and on the Linux desktop. +class CHROMEOS_EXPORT FakeBluetoothAgentServiceProvider + : public ExperimentalBluetoothAgentServiceProvider { + public: + FakeBluetoothAgentServiceProvider(const dbus::ObjectPath& object_path, + Delegate *delegate); + virtual ~FakeBluetoothAgentServiceProvider(); + + // Each of these calls the equivalent BluetoothAgentServiceProvider::Delegate + // method on the object passed on construction. + virtual void Release(); + virtual void RequestPinCode(const dbus::ObjectPath& device_path, + const Delegate::PinCodeCallback& callback); + virtual void DisplayPinCode(const dbus::ObjectPath& device_path, + const std::string& pincode); + virtual void RequestPasskey(const dbus::ObjectPath& device_path, + const Delegate::PasskeyCallback& callback); + virtual void DisplayPasskey(const dbus::ObjectPath& device_path, + uint32 passkey, int16 entered); + virtual void RequestConfirmation( + const dbus::ObjectPath& device_path, + uint32 passkey, + const Delegate::ConfirmationCallback& callback); + virtual void RequestAuthorization( + const dbus::ObjectPath& device_path, + const Delegate::ConfirmationCallback& callback); + virtual void AuthorizeService( + const dbus::ObjectPath& device_path, + const std::string& uuid, + const Delegate::ConfirmationCallback& callback); + virtual void Cancel(); + + private: + friend class FakeBluetoothAgentManagerClient; + + // D-Bus object path we are faking. + dbus::ObjectPath object_path_; + + // All incoming method calls are passed on to the Delegate and a callback + // passed to generate the reply. |delegate_| is generally the object that + // owns this one, and must outlive it. + Delegate* delegate_; +}; + +} // namespace chromeos + +#endif /* CHROMEOS_DBUS_FAKE_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_ */ diff --git a/chromeos/dbus/fake_bluetooth_device_client.cc b/chromeos/dbus/fake_bluetooth_device_client.cc new file mode 100644 index 0000000..00c8df4 --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_device_client.cc @@ -0,0 +1,807 @@ +// Copyright (c) 2013 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/dbus/fake_bluetooth_device_client.h" + +#include <algorithm> +#include <map> +#include <string> +#include <utility> +#include <vector> + +#include "base/bind.h" +#include "base/logging.h" +#include "base/message_loop.h" +#include "base/stl_util.h" +#include "base/time.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/fake_bluetooth_adapter_client.h" +#include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" +#include "chromeos/dbus/fake_bluetooth_agent_service_provider.h" +#include "dbus/object_path.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace { + +// Default interval between simulated events. +const int kSimulationIntervalMs = 750; + +} + +namespace chromeos { + +const char FakeBluetoothDeviceClient::kPairedDevicePath[] = + "/fake/hci0/dev0"; +const char FakeBluetoothDeviceClient::kPairedDeviceAddress[] = + "00:11:22:33:44:55"; +const char FakeBluetoothDeviceClient::kPairedDeviceName[] = + "Fake Device"; +const uint32 FakeBluetoothDeviceClient::kPairedDeviceClass = 0x000104; + +const char FakeBluetoothDeviceClient::kAppleMousePath[] = + "/fake/hci0/dev1"; +const char FakeBluetoothDeviceClient::kAppleMouseAddress[] = + "28:CF:DA:00:00:00"; +const char FakeBluetoothDeviceClient::kAppleMouseName[] = + "Apple Magic Mouse"; +const uint32 FakeBluetoothDeviceClient::kAppleMouseClass = 0x002580; + +const char FakeBluetoothDeviceClient::kAppleKeyboardPath[] = + "/fake/hci0/dev2"; +const char FakeBluetoothDeviceClient::kAppleKeyboardAddress[] = + "28:37:37:00:00:00"; +const char FakeBluetoothDeviceClient::kAppleKeyboardName[] = + "Apple Wireless Keyboard"; +const uint32 FakeBluetoothDeviceClient::kAppleKeyboardClass = 0x002540; + +const char FakeBluetoothDeviceClient::kVanishingDevicePath[] = + "/fake/hci0/dev3"; +const char FakeBluetoothDeviceClient::kVanishingDeviceAddress[] = + "01:02:03:04:05:06"; +const char FakeBluetoothDeviceClient::kVanishingDeviceName[] = + "Vanishing Device"; +const uint32 FakeBluetoothDeviceClient::kVanishingDeviceClass = 0x000104; + +const char FakeBluetoothDeviceClient::kMicrosoftMousePath[] = + "/fake/hci0/dev4"; +const char FakeBluetoothDeviceClient::kMicrosoftMouseAddress[] = + "7C:ED:8D:00:00:00"; +const char FakeBluetoothDeviceClient::kMicrosoftMouseName[] = + "Microsoft Mouse"; +const uint32 FakeBluetoothDeviceClient::kMicrosoftMouseClass = 0x002540; + +const char FakeBluetoothDeviceClient::kMotorolaKeyboardPath[] = + "/fake/hci0/dev5"; +const char FakeBluetoothDeviceClient::kMotorolaKeyboardAddress[] = + "00:0F:F6:00:00:00"; +const char FakeBluetoothDeviceClient::kMotorolaKeyboardName[] = + "Motorola Keyboard"; +const uint32 FakeBluetoothDeviceClient::kMotorolaKeyboardClass = 0x002580; + +const char FakeBluetoothDeviceClient::kSonyHeadphonesPath[] = + "/fake/hci0/dev6"; +const char FakeBluetoothDeviceClient::kSonyHeadphonesAddress[] = + "00:24:BE:00:00:00"; +const char FakeBluetoothDeviceClient::kSonyHeadphonesName[] = + "Sony BT-00"; +const uint32 FakeBluetoothDeviceClient::kSonyHeadphonesClass = 0x240408; + +const char FakeBluetoothDeviceClient::kPhonePath[] = + "/fake/hci0/dev7"; +const char FakeBluetoothDeviceClient::kPhoneAddress[] = + "20:7D:74:00:00:00"; +const char FakeBluetoothDeviceClient::kPhoneName[] = + "Phone"; +const uint32 FakeBluetoothDeviceClient::kPhoneClass = 0x7a020c; + +const char FakeBluetoothDeviceClient::kWeirdDevicePath[] = + "/fake/hci0/dev8"; +const char FakeBluetoothDeviceClient::kWeirdDeviceAddress[] = + "20:7D:74:00:00:01"; +const char FakeBluetoothDeviceClient::kWeirdDeviceName[] = + "Weird Device"; +const uint32 FakeBluetoothDeviceClient::kWeirdDeviceClass = 0x7a020c; + +FakeBluetoothDeviceClient::Properties::Properties( + const PropertyChangedCallback& callback) + : ExperimentalBluetoothDeviceClient::Properties( + NULL, + bluetooth_device::kExperimentalBluetoothDeviceInterface, + callback) { +} + +FakeBluetoothDeviceClient::Properties::~Properties() { +} + +void FakeBluetoothDeviceClient::Properties::Get( + dbus::PropertyBase* property, + dbus::PropertySet::GetCallback callback) { + VLOG(1) << "Get " << property->name(); + callback.Run(false); +} + +void FakeBluetoothDeviceClient::Properties::GetAll() { + VLOG(1) << "GetAll"; +} + +void FakeBluetoothDeviceClient::Properties::Set( + dbus::PropertyBase *property, + dbus::PropertySet::SetCallback callback) { + VLOG(1) << "Set " << property->name(); + if (property->name() == trusted.name()) { + callback.Run(true); + property->ReplaceValueWithSetValue(); + NotifyPropertyChanged(property->name()); + } else { + callback.Run(false); + } +} + + +FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() + : simulation_interval_ms_(kSimulationIntervalMs), + discovery_simulation_step_(0), + pairing_cancelled_(false) { + Properties* properties = new Properties(base::Bind( + &FakeBluetoothDeviceClient::OnPropertyChanged, + base::Unretained(this), + dbus::ObjectPath(kPairedDevicePath))); + properties->address.ReplaceValue(kPairedDeviceAddress); + properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); + properties->name.ReplaceValue("Fake Device (Name)"); + properties->alias.ReplaceValue(kPairedDeviceName); + properties->paired.ReplaceValue(true); + properties->trusted.ReplaceValue(true); + properties->adapter.ReplaceValue( + dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); + + std::vector<std::string> uuids; + uuids.push_back("00001800-0000-1000-8000-00805f9b34fb"); + uuids.push_back("00001801-0000-1000-8000-00805f9b34fb"); + properties->uuids.ReplaceValue(uuids); + + properties_map_[dbus::ObjectPath(kPairedDevicePath)] = properties; + device_list_.push_back(dbus::ObjectPath(kPairedDevicePath)); +} + +FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() { + // Clean up Properties structures + STLDeleteValues(&properties_map_); +} + +void FakeBluetoothDeviceClient::AddObserver(Observer* observer) { + observers_.AddObserver(observer); +} + +void FakeBluetoothDeviceClient::RemoveObserver(Observer* observer) { + observers_.RemoveObserver(observer); +} + +std::vector<dbus::ObjectPath> FakeBluetoothDeviceClient::GetDevicesForAdapter( + const dbus::ObjectPath& adapter_path) { + if (adapter_path == + dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)) + return device_list_; + else + return std::vector<dbus::ObjectPath>(); +} + +FakeBluetoothDeviceClient::Properties* +FakeBluetoothDeviceClient::GetProperties(const dbus::ObjectPath& object_path) { + PropertiesMap::iterator iter = properties_map_.find(object_path); + if (iter != properties_map_.end()) + return iter->second; + return NULL; +} + +void FakeBluetoothDeviceClient::Connect( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "Connect: " << object_path.value(); + Properties* properties = GetProperties(object_path); + + if (properties->connected.value() == true) { + // Already connected. + callback.Run(); + return; + } + + if (properties->paired.value() != true && + object_path != dbus::ObjectPath(kMicrosoftMousePath)) { + // Must be paired. + error_callback.Run(bluetooth_adapter::kErrorFailed, "Not paired"); + return; + } else if (properties->paired.value() == true && + object_path == dbus::ObjectPath(kMicrosoftMousePath)) { + // Must not be paired + error_callback.Run(bluetooth_adapter::kErrorFailed, + "Connection fails while paired"); + return; + } + + // The device can be connected. + properties->connected.ReplaceValue(true); + + callback.Run(); + properties->NotifyPropertyChanged(properties->connected.name()); +} + +void FakeBluetoothDeviceClient::Disconnect( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "Disconnect: " << object_path.value(); + Properties* properties = GetProperties(object_path); + + if (properties->connected.value() == true) { + properties->connected.ReplaceValue(false); + + callback.Run(); + properties->NotifyPropertyChanged(properties->connected.name()); + } else { + error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); + } +} + +void FakeBluetoothDeviceClient::ConnectProfile( + const dbus::ObjectPath& object_path, + const std::string& uuid, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "ConnectProfile: " << object_path.value() << " " << uuid; + error_callback.Run(kNoResponseError, ""); +} + +void FakeBluetoothDeviceClient::DisconnectProfile( + const dbus::ObjectPath& object_path, + const std::string& uuid, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "DisconnectProfile: " << object_path.value() << " " << uuid; + error_callback.Run(kNoResponseError, ""); +} + +void FakeBluetoothDeviceClient::Pair( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "Pair: " << object_path.value(); + Properties* properties = GetProperties(object_path); + + if (properties->paired.value() == true) { + // Already paired. + callback.Run(); + return; + } + + FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = + static_cast<FakeBluetoothAgentManagerClient*>( + DBusThreadManager::Get()-> + GetExperimentalBluetoothAgentManagerClient()); + FakeBluetoothAgentServiceProvider* agent_service_provider = + fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); + if (agent_service_provider == NULL) { + error_callback.Run(kNoResponseError, "Missing agent"); + return; + } + + if (object_path == dbus::ObjectPath(kAppleMousePath) || + object_path == dbus::ObjectPath(kMicrosoftMousePath)) { + // No need to call anything on the pairing delegate, just wait 3 times + // the interval before acting as if the other end accepted it. + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, + base::Unretained(this), + object_path, callback, error_callback), + base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); + + } else if (object_path == dbus::ObjectPath(kAppleKeyboardPath)) { + // Display a Pincode, and wait 7 times the interval before acting as + // if the other end accepted it. + agent_service_provider->DisplayPinCode(object_path, "123456"); + + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, + base::Unretained(this), + object_path, callback, error_callback), + base::TimeDelta::FromMilliseconds(7 * simulation_interval_ms_)); + + } else if (object_path == dbus::ObjectPath(kVanishingDevicePath)) { + // The vanishing device simulates being too far away, and thus times out. + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::TimeoutSimulatedPairing, + base::Unretained(this), + object_path, error_callback), + base::TimeDelta::FromMilliseconds(4 * simulation_interval_ms_)); + + } else if (object_path == dbus::ObjectPath(kMotorolaKeyboardPath)) { + // Display a passkey, and each interval act as if another key was entered + // for it. + agent_service_provider->DisplayPasskey(object_path, 123456, 0); + + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::SimulateKeypress, + base::Unretained(this), + 1, object_path, callback, error_callback), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); + + } else if (object_path == dbus::ObjectPath(kSonyHeadphonesPath)) { + // Request a Pincode. + agent_service_provider->RequestPinCode( + object_path, + base::Bind(&FakeBluetoothDeviceClient::PinCodeCallback, + base::Unretained(this), + object_path, + callback, + error_callback)); + + } else if (object_path == dbus::ObjectPath(kPhonePath)) { + // Request confirmation of a Passkey. + agent_service_provider->RequestConfirmation( + object_path, 123456, + base::Bind(&FakeBluetoothDeviceClient::ConfirmationCallback, + base::Unretained(this), + object_path, + callback, + error_callback)); + + } else if (object_path == dbus::ObjectPath(kWeirdDevicePath)) { + // Request a Passkey from the user. + agent_service_provider->RequestPasskey( + object_path, + base::Bind(&FakeBluetoothDeviceClient::PasskeyCallback, + base::Unretained(this), + object_path, + callback, + error_callback)); + + } else { + error_callback.Run(kNoResponseError, "No pairing fake"); + } +} + +void FakeBluetoothDeviceClient::CancelPairing( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "CancelPairing: " << object_path.value(); + pairing_cancelled_ = true; + callback.Run(); +} + + +void FakeBluetoothDeviceClient::BeginDiscoverySimulation( + const dbus::ObjectPath& adapter_path) { + VLOG(1) << "starting discovery simulation"; + + discovery_simulation_step_ = 1; + + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, + base::Unretained(this)), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); +} + +void FakeBluetoothDeviceClient::EndDiscoverySimulation( + const dbus::ObjectPath& adapter_path) { + VLOG(1) << "stopping discovery simulation"; + discovery_simulation_step_ = 0; +} + +void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { + simulation_interval_ms_ = interval_ms; +} + +void FakeBluetoothDeviceClient::RemoveDevice( + const dbus::ObjectPath& adapter_path, + const dbus::ObjectPath& device_path) { + std::vector<dbus::ObjectPath>::iterator listiter = + std::find(device_list_.begin(), device_list_.end(), device_path); + if (listiter == device_list_.end()) + return; + + PropertiesMap::iterator iter = properties_map_.find(device_path); + Properties* properties = iter->second; + + VLOG(1) << "removing device: " << properties->alias.value(); + device_list_.erase(listiter); + + FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, + DeviceRemoved(device_path)); + + delete properties; + properties_map_.erase(iter); +} + +void FakeBluetoothDeviceClient::OnPropertyChanged( + const dbus::ObjectPath& object_path, + const std::string& property_name) { + FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, + DevicePropertyChanged(object_path, property_name)); +} + +void FakeBluetoothDeviceClient::DiscoverySimulationTimer() { + if (!discovery_simulation_step_) + return; + + // Timer fires every .75s, the numbers below are arbitrary to give a feel + // for a discovery process. + VLOG(1) << "discovery simulation, step " << discovery_simulation_step_; + if (discovery_simulation_step_ == 2) { + if (std::find(device_list_.begin(), device_list_.end(), + dbus::ObjectPath(kAppleMousePath)) == device_list_.end()) { + Properties* properties = new Properties(base::Bind( + &FakeBluetoothDeviceClient::OnPropertyChanged, + base::Unretained(this), + dbus::ObjectPath(kAppleMousePath))); + properties->address.ReplaceValue(kAppleMouseAddress); + properties->bluetooth_class.ReplaceValue(kAppleMouseClass); + properties->name.ReplaceValue("Fake Apple Magic Mouse"); + properties->alias.ReplaceValue(kAppleMouseName); + properties->adapter.ReplaceValue( + dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); + + properties_map_[dbus::ObjectPath(kAppleMousePath)] = properties; + device_list_.push_back(dbus::ObjectPath(kAppleMousePath)); + FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, + DeviceAdded(dbus::ObjectPath(kAppleMousePath))); + } + + } else if (discovery_simulation_step_ == 4) { + if (std::find(device_list_.begin(), device_list_.end(), + dbus::ObjectPath(kAppleKeyboardPath)) == device_list_.end()) { + Properties *properties = new Properties(base::Bind( + &FakeBluetoothDeviceClient::OnPropertyChanged, + base::Unretained(this), + dbus::ObjectPath(kAppleKeyboardPath))); + properties->address.ReplaceValue(kAppleKeyboardAddress); + properties->bluetooth_class.ReplaceValue(kAppleKeyboardClass); + properties->name.ReplaceValue("Fake Apple Wireless Keyboard"); + properties->alias.ReplaceValue(kAppleKeyboardName); + properties->adapter.ReplaceValue( + dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); + + properties_map_[dbus::ObjectPath(kAppleKeyboardPath)] = properties; + device_list_.push_back(dbus::ObjectPath(kAppleKeyboardPath)); + FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, + DeviceAdded(dbus::ObjectPath(kAppleKeyboardPath))); + } + + if (std::find(device_list_.begin(), device_list_.end(), + dbus::ObjectPath(kVanishingDevicePath)) == + device_list_.end()) { + Properties* properties = new Properties(base::Bind( + &FakeBluetoothDeviceClient::OnPropertyChanged, + base::Unretained(this), + dbus::ObjectPath(kVanishingDevicePath))); + properties->address.ReplaceValue(kVanishingDeviceAddress); + properties->bluetooth_class.ReplaceValue(kVanishingDeviceClass); + properties->name.ReplaceValue("Fake Vanishing Device"); + properties->alias.ReplaceValue(kVanishingDeviceName); + properties->adapter.ReplaceValue( + dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); + + properties_map_[dbus::ObjectPath(kVanishingDevicePath)] = properties; + device_list_.push_back(dbus::ObjectPath(kVanishingDevicePath)); + FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, + DeviceAdded(dbus::ObjectPath(kVanishingDevicePath))); + } + + } else if (discovery_simulation_step_ == 7) { + if (std::find(device_list_.begin(), device_list_.end(), + dbus::ObjectPath(kMicrosoftMousePath)) == + device_list_.end()) { + Properties* properties = new Properties(base::Bind( + &FakeBluetoothDeviceClient::OnPropertyChanged, + base::Unretained(this), + dbus::ObjectPath(kMicrosoftMousePath))); + properties->address.ReplaceValue(kMicrosoftMouseAddress); + properties->bluetooth_class.ReplaceValue(kMicrosoftMouseClass); + properties->name.ReplaceValue("Fake Microsoft Mouse"); + properties->alias.ReplaceValue(kMicrosoftMouseName); + properties->adapter.ReplaceValue( + dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); + + properties_map_[dbus::ObjectPath(kMicrosoftMousePath)] = properties; + device_list_.push_back(dbus::ObjectPath(kMicrosoftMousePath)); + FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, + DeviceAdded(dbus::ObjectPath(kMicrosoftMousePath))); + } + + } else if (discovery_simulation_step_ == 8) { + if (std::find(device_list_.begin(), device_list_.end(), + dbus::ObjectPath(kMotorolaKeyboardPath)) == + device_list_.end()) { + Properties* properties = new Properties(base::Bind( + &FakeBluetoothDeviceClient::OnPropertyChanged, + base::Unretained(this), + dbus::ObjectPath(kMotorolaKeyboardPath))); + properties->address.ReplaceValue(kMotorolaKeyboardAddress); + properties->bluetooth_class.ReplaceValue(kMotorolaKeyboardClass); + properties->name.ReplaceValue("Fake Motorola Keyboard"); + properties->alias.ReplaceValue(kMotorolaKeyboardName); + properties->adapter.ReplaceValue( + dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); + + properties_map_[dbus::ObjectPath(kMotorolaKeyboardPath)] = properties; + device_list_.push_back(dbus::ObjectPath(kMotorolaKeyboardPath)); + FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, + DeviceAdded(dbus::ObjectPath(kMotorolaKeyboardPath))); + } + + if (std::find(device_list_.begin(), device_list_.end(), + dbus::ObjectPath(kSonyHeadphonesPath)) == + device_list_.end()) { + Properties* properties = new Properties(base::Bind( + &FakeBluetoothDeviceClient::OnPropertyChanged, + base::Unretained(this), + dbus::ObjectPath(kSonyHeadphonesPath))); + properties->address.ReplaceValue(kSonyHeadphonesAddress); + properties->bluetooth_class.ReplaceValue(kSonyHeadphonesClass); + properties->name.ReplaceValue("Fake Sony Headphones"); + properties->alias.ReplaceValue(kSonyHeadphonesName); + properties->adapter.ReplaceValue( + dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); + + properties_map_[dbus::ObjectPath(kSonyHeadphonesPath)] = properties; + device_list_.push_back(dbus::ObjectPath(kSonyHeadphonesPath)); + FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, + DeviceAdded(dbus::ObjectPath(kSonyHeadphonesPath))); + } + + } else if (discovery_simulation_step_ == 10) { + if (std::find(device_list_.begin(), device_list_.end(), + dbus::ObjectPath(kPhonePath)) == device_list_.end()) { + Properties* properties = new Properties(base::Bind( + &FakeBluetoothDeviceClient::OnPropertyChanged, + base::Unretained(this), + dbus::ObjectPath(kPhonePath))); + properties->address.ReplaceValue(kPhoneAddress); + properties->bluetooth_class.ReplaceValue(kPhoneClass); + properties->name.ReplaceValue("Fake Phone"); + properties->alias.ReplaceValue(kPhoneName); + properties->adapter.ReplaceValue( + dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); + + properties_map_[dbus::ObjectPath(kPhonePath)] = properties; + device_list_.push_back(dbus::ObjectPath(kPhonePath)); + FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, + DeviceAdded(dbus::ObjectPath(kPhonePath))); + } + + if (std::find(device_list_.begin(), device_list_.end(), + dbus::ObjectPath(kWeirdDevicePath)) == device_list_.end()) { + Properties* properties = new Properties(base::Bind( + &FakeBluetoothDeviceClient::OnPropertyChanged, + base::Unretained(this), + dbus::ObjectPath(kWeirdDevicePath))); + properties->address.ReplaceValue(kWeirdDeviceAddress); + properties->bluetooth_class.ReplaceValue(kWeirdDeviceClass); + properties->name.ReplaceValue("Fake Weird Device"); + properties->alias.ReplaceValue(kWeirdDeviceName); + properties->adapter.ReplaceValue( + dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); + + properties_map_[dbus::ObjectPath(kWeirdDevicePath)] = properties; + device_list_.push_back(dbus::ObjectPath(kWeirdDevicePath)); + FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, + DeviceAdded(dbus::ObjectPath(kWeirdDevicePath))); + } + + } else if (discovery_simulation_step_ == 13) { + RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), + dbus::ObjectPath(kVanishingDevicePath)); + + } else if (discovery_simulation_step_ == 14) { + return; + + } + + ++discovery_simulation_step_; + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, + base::Unretained(this)), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); +} + + +void FakeBluetoothDeviceClient::CompleteSimulatedPairing( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "CompleteSimulatedPairing: " << object_path.value(); + if (pairing_cancelled_) { + pairing_cancelled_ = false; + + error_callback.Run(bluetooth_adapter::kErrorAuthenticationCanceled, + "Cancaled"); + } else { + Properties* properties = GetProperties(object_path); + + properties->paired.ReplaceValue(true); + + callback.Run(); + properties->NotifyPropertyChanged(properties->paired.name()); + } +} + +void FakeBluetoothDeviceClient::TimeoutSimulatedPairing( + const dbus::ObjectPath& object_path, + const ErrorCallback& error_callback) { + VLOG(1) << "TimeoutSimulatedPairing: " << object_path.value(); + + error_callback.Run(bluetooth_adapter::kErrorAuthenticationTimeout, + "Timed out"); +} + +void FakeBluetoothDeviceClient::CancelSimulatedPairing( + const dbus::ObjectPath& object_path, + const ErrorCallback& error_callback) { + VLOG(1) << "CancelSimulatedPairing: " << object_path.value(); + + error_callback.Run(bluetooth_adapter::kErrorAuthenticationCanceled, + "Canceled"); +} + +void FakeBluetoothDeviceClient::RejectSimulatedPairing( + const dbus::ObjectPath& object_path, + const ErrorCallback& error_callback) { + VLOG(1) << "RejectSimulatedPairing: " << object_path.value(); + + error_callback.Run(bluetooth_adapter::kErrorAuthenticationRejected, + "Rejected"); +} + +void FakeBluetoothDeviceClient::PinCodeCallback( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback, + ExperimentalBluetoothAgentServiceProvider::Delegate::Status status, + const std::string& pincode) { + VLOG(1) << "PinCodeCallback: " << object_path.value(); + + if (status == ExperimentalBluetoothAgentServiceProvider::Delegate::SUCCESS) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, + base::Unretained(this), + object_path, callback, error_callback), + base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); + + } else if (status == + ExperimentalBluetoothAgentServiceProvider::Delegate::CANCELLED) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::CancelSimulatedPairing, + base::Unretained(this), + object_path, error_callback), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); + + } else if (status == + ExperimentalBluetoothAgentServiceProvider::Delegate::REJECTED) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::RejectSimulatedPairing, + base::Unretained(this), + object_path, error_callback), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); + + } +} + +void FakeBluetoothDeviceClient::PasskeyCallback( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback, + ExperimentalBluetoothAgentServiceProvider::Delegate::Status status, + uint32 passkey) { + VLOG(1) << "PasskeyCallback: " << object_path.value(); + + if (status == ExperimentalBluetoothAgentServiceProvider::Delegate::SUCCESS) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, + base::Unretained(this), + object_path, callback, error_callback), + base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); + + } else if (status == + ExperimentalBluetoothAgentServiceProvider::Delegate::CANCELLED) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::CancelSimulatedPairing, + base::Unretained(this), + object_path, error_callback), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); + + } else if (status == + ExperimentalBluetoothAgentServiceProvider::Delegate::REJECTED) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::RejectSimulatedPairing, + base::Unretained(this), + object_path, error_callback), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); + + } +} + +void FakeBluetoothDeviceClient::ConfirmationCallback( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback, + ExperimentalBluetoothAgentServiceProvider::Delegate::Status status) { + VLOG(1) << "ConfirmationCallback: " << object_path.value(); + + if (status == ExperimentalBluetoothAgentServiceProvider::Delegate::SUCCESS) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, + base::Unretained(this), + object_path, callback, error_callback), + base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); + + } else if (status == + ExperimentalBluetoothAgentServiceProvider::Delegate::CANCELLED) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::CancelSimulatedPairing, + base::Unretained(this), + object_path, error_callback), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); + + } else if (status == + ExperimentalBluetoothAgentServiceProvider::Delegate::REJECTED) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::RejectSimulatedPairing, + base::Unretained(this), + object_path, error_callback), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); + + } +} + +void FakeBluetoothDeviceClient::SimulateKeypress( + int16 entered, + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "SimulateKeypress " << entered << ": " << object_path.value(); + + FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client = + static_cast<FakeBluetoothAgentManagerClient*>( + DBusThreadManager::Get()-> + GetExperimentalBluetoothAgentManagerClient()); + FakeBluetoothAgentServiceProvider* agent_service_provider = + fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); + agent_service_provider->DisplayPasskey(object_path, 123456, entered); + + if (entered < 7) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::SimulateKeypress, + base::Unretained(this), + entered + 1, object_path, callback, error_callback), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); + + } else { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, + base::Unretained(this), + object_path, callback, error_callback), + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); + + } +} + +} // namespace chromeos diff --git a/chromeos/dbus/fake_bluetooth_device_client.h b/chromeos/dbus/fake_bluetooth_device_client.h new file mode 100644 index 0000000..34b7959 --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_device_client.h @@ -0,0 +1,188 @@ +// Copyright (c) 2013 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_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ +#define CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ + +#include <map> +#include <vector> + +#include "base/bind.h" +#include "base/callback.h" +#include "base/observer_list.h" +#include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client_implementation_type.h" +#include "chromeos/dbus/experimental_bluetooth_agent_service_provider.h" +#include "chromeos/dbus/experimental_bluetooth_device_client.h" +#include "dbus/object_path.h" +#include "dbus/property.h" + +namespace chromeos { + +// FakeBluetoothDeviceClient simulates the behavior of the Bluetooth Daemon +// device objects and is used both in test cases in place of a mock and on +// the Linux desktop. +class CHROMEOS_EXPORT FakeBluetoothDeviceClient + : public ExperimentalBluetoothDeviceClient { + public: + struct Properties : public ExperimentalBluetoothDeviceClient::Properties { + explicit Properties(const PropertyChangedCallback & callback); + virtual ~Properties(); + + // dbus::PropertySet override + virtual void Get(dbus::PropertyBase* property, + dbus::PropertySet::GetCallback callback) OVERRIDE; + virtual void GetAll() OVERRIDE; + virtual void Set(dbus::PropertyBase* property, + dbus::PropertySet::SetCallback callback) OVERRIDE; + }; + + FakeBluetoothDeviceClient(); + virtual ~FakeBluetoothDeviceClient(); + + // ExperimentalBluetoothDeviceClient override + virtual void AddObserver(Observer* observer) OVERRIDE; + virtual void RemoveObserver(Observer* observer) OVERRIDE; + virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( + const dbus::ObjectPath& adapter_path) OVERRIDE; + virtual Properties* GetProperties(const dbus::ObjectPath& object_path) + OVERRIDE; + virtual void Connect(const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void Disconnect(const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void ConnectProfile(const dbus::ObjectPath& object_path, + const std::string& uuid, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void DisconnectProfile(const dbus::ObjectPath& object_path, + const std::string& uuid, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void Pair(const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void CancelPairing(const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + + void SetSimulationIntervalMs(int interval_ms); + + // Simulate discovery of devices for the given adapter. + void BeginDiscoverySimulation(const dbus::ObjectPath& adapter_path); + void EndDiscoverySimulation(const dbus::ObjectPath& adapter_path); + + // Remove a device from the set we return for the given adapter. + void RemoveDevice(const dbus::ObjectPath& adapter_path, + const dbus::ObjectPath& device_path); + + // Object paths, names, addresses and bluetooth classes of the devices + // we can emulate. + static const char kPairedDevicePath[]; + static const char kPairedDeviceName[]; + static const char kPairedDeviceAddress[]; + static const uint32 kPairedDeviceClass; + + static const char kAppleMousePath[]; + static const char kAppleMouseName[]; + static const char kAppleMouseAddress[]; + static const uint32 kAppleMouseClass; + + static const char kAppleKeyboardPath[]; + static const char kAppleKeyboardName[]; + static const char kAppleKeyboardAddress[]; + static const uint32 kAppleKeyboardClass; + + static const char kVanishingDevicePath[]; + static const char kVanishingDeviceName[]; + static const char kVanishingDeviceAddress[]; + static const uint32 kVanishingDeviceClass; + + static const char kMicrosoftMousePath[]; + static const char kMicrosoftMouseName[]; + static const char kMicrosoftMouseAddress[]; + static const uint32 kMicrosoftMouseClass; + + static const char kMotorolaKeyboardPath[]; + static const char kMotorolaKeyboardName[]; + static const char kMotorolaKeyboardAddress[]; + static const uint32 kMotorolaKeyboardClass; + + static const char kSonyHeadphonesPath[]; + static const char kSonyHeadphonesName[]; + static const char kSonyHeadphonesAddress[]; + static const uint32 kSonyHeadphonesClass; + + static const char kPhonePath[]; + static const char kPhoneName[]; + static const char kPhoneAddress[]; + static const uint32 kPhoneClass; + + static const char kWeirdDevicePath[]; + static const char kWeirdDeviceName[]; + static const char kWeirdDeviceAddress[]; + static const uint32 kWeirdDeviceClass; + + private: + // Property callback passed when we create Properties* structures. + void OnPropertyChanged(const dbus::ObjectPath& object_path, + const std::string& property_name); + + void DiscoverySimulationTimer(); + + void CompleteSimulatedPairing( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback); + void TimeoutSimulatedPairing( + const dbus::ObjectPath& object_path, + const ErrorCallback& error_callback); + void CancelSimulatedPairing( + const dbus::ObjectPath& object_path, + const ErrorCallback& error_callback); + void RejectSimulatedPairing( + const dbus::ObjectPath& object_path, + const ErrorCallback& error_callback); + + void PinCodeCallback( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback, + ExperimentalBluetoothAgentServiceProvider::Delegate::Status status, + const std::string& pincode); + void PasskeyCallback( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback, + ExperimentalBluetoothAgentServiceProvider::Delegate::Status status, + uint32 passkey); + void ConfirmationCallback( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback, + ExperimentalBluetoothAgentServiceProvider::Delegate::Status status); + void SimulateKeypress( + int16 entered, + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback); + + // List of observers interested in event notifications from us. + ObserverList<Observer> observers_; + + // Static properties we return. + typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap; + PropertiesMap properties_map_; + std::vector<dbus::ObjectPath> device_list_; + + int simulation_interval_ms_; + uint32_t discovery_simulation_step_; + bool pairing_cancelled_; +}; + +} // namespace chromeos + +#endif /* CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ */ diff --git a/chromeos/dbus/fake_bluetooth_profile_manager_client.cc b/chromeos/dbus/fake_bluetooth_profile_manager_client.cc new file mode 100644 index 0000000..0547e4b1 --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_profile_manager_client.cc @@ -0,0 +1,41 @@ +// Copyright (c) 2013 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/dbus/fake_bluetooth_profile_manager_client.h" + +#include "base/bind.h" +#include "base/logging.h" +#include "dbus/bus.h" +#include "dbus/message.h" +#include "dbus/object_path.h" +#include "dbus/object_proxy.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace chromeos { + +FakeBluetoothProfileManagerClient::FakeBluetoothProfileManagerClient() { +} + +FakeBluetoothProfileManagerClient::~FakeBluetoothProfileManagerClient() { +} + +void FakeBluetoothProfileManagerClient::RegisterProfile( + const dbus::ObjectPath& profile_path, + const std::string& uuid, + const Options& options, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "RegisterProfile: " << profile_path.value() << ": " << uuid; + callback.Run(); +} + +void FakeBluetoothProfileManagerClient::UnregisterProfile( + const dbus::ObjectPath& profile_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + VLOG(1) << "UnregisterProfile: " << profile_path.value(); + callback.Run(); +} + +} // namespace chromeos diff --git a/chromeos/dbus/fake_bluetooth_profile_manager_client.h b/chromeos/dbus/fake_bluetooth_profile_manager_client.h new file mode 100644 index 0000000..fdda97a --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_profile_manager_client.h @@ -0,0 +1,41 @@ +// Copyright (c) 2013 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_DBUS_FAKE_BLUETOOTH_PROFILE_MANAGER_CLIENT_H_ +#define CHROMEOS_DBUS_FAKE_BLUETOOTH_PROFILE_MANAGER_CLIENT_H_ + +#include "base/bind.h" +#include "base/callback.h" +#include "base/observer_list.h" +#include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client_implementation_type.h" +#include "chromeos/dbus/experimental_bluetooth_profile_manager_client.h" +#include "dbus/object_path.h" +#include "dbus/property.h" + +namespace chromeos { + +// FakeBluetoothProfileManagerClient simulates the behavior of the Bluetooth +// Daemon's profile manager object and is used both in test cases in place of a +// mock and on the Linux desktop. +class CHROMEOS_EXPORT FakeBluetoothProfileManagerClient + : public ExperimentalBluetoothProfileManagerClient { + public: + FakeBluetoothProfileManagerClient(); + virtual ~FakeBluetoothProfileManagerClient(); + + // ExperimentalBluetoothProfileManagerClient override + virtual void RegisterProfile(const dbus::ObjectPath& profile_path, + const std::string& uuid, + const Options& options, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void UnregisterProfile(const dbus::ObjectPath& profile_path, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; +}; + +} // namespace chromeos + +#endif /* CHROMEOS_DBUS_FAKE_BLUETOOTH_PROFILE_MANAGER_CLIENT_H_ */ diff --git a/chromeos/dbus/fake_bluetooth_profile_service_provider.cc b/chromeos/dbus/fake_bluetooth_profile_service_provider.cc new file mode 100644 index 0000000..999da6f --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_profile_service_provider.cc @@ -0,0 +1,51 @@ +// Copyright (c) 2013 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/dbus/fake_bluetooth_profile_service_provider.h" + +#include "dbus/object_path.h" + +namespace chromeos { + +FakeBluetoothProfileServiceProvider::FakeBluetoothProfileServiceProvider( + const dbus::ObjectPath& object_path, + Delegate* delegate) + : object_path_(object_path), + delegate_(delegate) { + VLOG(1) << "Creating Bluetooth Profile: " << object_path_.value(); +} + +FakeBluetoothProfileServiceProvider::~FakeBluetoothProfileServiceProvider() { + VLOG(1) << "Cleaning up Bluetooth Profile: " << object_path_.value(); +} + +void FakeBluetoothProfileServiceProvider::Release() { + VLOG(1) << object_path_.value() << ": Release"; + delegate_->Release(); +} + +void FakeBluetoothProfileServiceProvider::NewConnection( + const dbus::ObjectPath& device_path, + dbus::FileDescriptor* fd, + const Delegate::Options& options, + const Delegate::ConfirmationCallback& callback) { + VLOG(1) << object_path_.value() << ": NewConnection for " + << device_path.value(); + delegate_->NewConnection(device_path, fd, options, callback); +} + +void FakeBluetoothProfileServiceProvider::RequestDisconnection( + const dbus::ObjectPath& device_path, + const Delegate::ConfirmationCallback& callback) { + VLOG(1) << object_path_.value() << ": RequestDisconnection for " + << device_path.value(); + delegate_->RequestDisconnection(device_path, callback); +} + +void FakeBluetoothProfileServiceProvider::Cancel() { + VLOG(1) << object_path_.value() << ": Cancel"; + delegate_->Cancel(); +} + +} // namespace chromeos diff --git a/chromeos/dbus/fake_bluetooth_profile_service_provider.h b/chromeos/dbus/fake_bluetooth_profile_service_provider.h new file mode 100644 index 0000000..730d6fe --- /dev/null +++ b/chromeos/dbus/fake_bluetooth_profile_service_provider.h @@ -0,0 +1,54 @@ +// Copyright (c) 2013 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_DBUS_FAKE_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_ +#define CHROMEOS_DBUS_FAKE_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_ + +#include "base/bind.h" +#include "base/callback.h" +#include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client_implementation_type.h" +#include "chromeos/dbus/experimental_bluetooth_profile_service_provider.h" +#include "dbus/file_descriptor.h" +#include "dbus/object_path.h" + +namespace chromeos { + +// FakeBluetoothProfileServiceProvider simulates the behavior of a local +// Bluetooth agent object and is used both in test cases in place of a +// mock and on the Linux desktop. +class CHROMEOS_EXPORT FakeBluetoothProfileServiceProvider + : public ExperimentalBluetoothProfileServiceProvider { + public: + FakeBluetoothProfileServiceProvider(const dbus::ObjectPath& object_path, + Delegate *delegate); + virtual ~FakeBluetoothProfileServiceProvider(); + + // Each of these calls the equivalent + // BluetoothProfileServiceProvider::Delegate method on the object passed on + // construction. + virtual void Release(); + virtual void NewConnection( + const dbus::ObjectPath& device_path, + dbus::FileDescriptor* fd, + const Delegate::Options& options, + const Delegate::ConfirmationCallback& callback); + virtual void RequestDisconnection( + const dbus::ObjectPath& device_path, + const Delegate::ConfirmationCallback& callback); + virtual void Cancel(); + + private: + // D-Bus object path we are faking. + dbus::ObjectPath object_path_; + + // All incoming method calls are passed on to the Delegate and a callback + // passed to generate the reply. |delegate_| is generally the object that + // owns this one, and must outlive it. + Delegate* delegate_; +}; + +} // namespace chromeos + +#endif /* CHROMEOS_DBUS_FAKE_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_ */ diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc index 49c5bbe..eee44dc 100644 --- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc +++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc @@ -5,6 +5,10 @@ #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h" #include "chromeos/dbus/dbus_thread_manager_observer.h" +#include "chromeos/dbus/fake_bluetooth_adapter_client.h" +#include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" +#include "chromeos/dbus/fake_bluetooth_device_client.h" +#include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" #include "chromeos/dbus/ibus/mock_ibus_client.h" #include "chromeos/dbus/ibus/mock_ibus_config_client.h" #include "chromeos/dbus/ibus/mock_ibus_engine_factory_service.h" @@ -15,7 +19,12 @@ namespace chromeos { MockDBusThreadManagerWithoutGMock::MockDBusThreadManagerWithoutGMock() - : mock_ibus_client_(new MockIBusClient), + : fake_bluetooth_adapter_client_(new FakeBluetoothAdapterClient()), + fake_bluetooth_agent_manager_client_(new FakeBluetoothAgentManagerClient()), + fake_bluetooth_device_client_(new FakeBluetoothDeviceClient()), + fake_bluetooth_profile_manager_client_( + new FakeBluetoothProfileManagerClient()), + mock_ibus_client_(new MockIBusClient), mock_ibus_input_context_client_(new MockIBusInputContextClient), ibus_bus_(NULL) { } @@ -104,28 +113,24 @@ DebugDaemonClient* MockDBusThreadManagerWithoutGMock::GetDebugDaemonClient() { ExperimentalBluetoothAdapterClient* MockDBusThreadManagerWithoutGMock::GetExperimentalBluetoothAdapterClient() { - NOTIMPLEMENTED(); - return NULL; + return fake_bluetooth_adapter_client_.get(); } ExperimentalBluetoothAgentManagerClient* MockDBusThreadManagerWithoutGMock:: GetExperimentalBluetoothAgentManagerClient() { - NOTIMPLEMENTED(); - return NULL; + return fake_bluetooth_agent_manager_client_.get(); } ExperimentalBluetoothDeviceClient* MockDBusThreadManagerWithoutGMock::GetExperimentalBluetoothDeviceClient() { - NOTIMPLEMENTED(); - return NULL; + return fake_bluetooth_device_client_.get(); } ExperimentalBluetoothProfileManagerClient* MockDBusThreadManagerWithoutGMock:: GetExperimentalBluetoothProfileManagerClient() { - NOTIMPLEMENTED(); - return NULL; + return fake_bluetooth_profile_manager_client_.get(); } ShillDeviceClient* diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h index 04853ed..0acbd81 100644 --- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h +++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h @@ -19,6 +19,10 @@ class ObjectPath; namespace chromeos { class DBusThreadManagerObserver; +class FakeBluetoothAdapterClient; +class FakeBluetoothAgentManagerClient; +class FakeBluetoothDeviceClient; +class FakeBluetoothProfileManagerClient; class MockIBusClient; class MockIBusConfigClient; class MockIBusEngineFactoryService; @@ -85,6 +89,22 @@ class MockDBusThreadManagerWithoutGMock : public DBusThreadManager { const dbus::ObjectPath& object_path) OVERRIDE; virtual IBusPanelService* GetIBusPanelService() OVERRIDE; + FakeBluetoothAdapterClient* fake_bluetooth_adapter_client() { + return fake_bluetooth_adapter_client_.get(); + } + + FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client() { + return fake_bluetooth_agent_manager_client_.get(); + } + + FakeBluetoothDeviceClient* fake_bluetooth_device_client() { + return fake_bluetooth_device_client_.get(); + } + + FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client() { + return fake_bluetooth_profile_manager_client_.get(); + } + MockIBusClient* mock_ibus_client() { return mock_ibus_client_.get(); } @@ -114,6 +134,12 @@ class MockDBusThreadManagerWithoutGMock : public DBusThreadManager { } private: + scoped_ptr<FakeBluetoothAdapterClient> fake_bluetooth_adapter_client_; + scoped_ptr<FakeBluetoothAgentManagerClient> + fake_bluetooth_agent_manager_client_; + scoped_ptr<FakeBluetoothDeviceClient> fake_bluetooth_device_client_; + scoped_ptr<FakeBluetoothProfileManagerClient> + fake_bluetooth_profile_manager_client_; scoped_ptr<MockIBusClient> mock_ibus_client_; scoped_ptr<MockIBusConfigClient> mock_ibus_config_client_; scoped_ptr<MockIBusInputContextClient> mock_ibus_input_context_client_; |