summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorkeybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-27 04:33:49 +0000
committerkeybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-27 04:33:49 +0000
commite0e18d0066c61e7ff053e548c301c45b65a8449d (patch)
tree3c758efff91f1013c0df7c0b2c4435683faa52ea /chromeos
parentfdf93ecf35b0ad0647ca1ba4d9b4e972e966fe7b (diff)
downloadchromium_src-e0e18d0066c61e7ff053e548c301c45b65a8449d.zip
chromium_src-e0e18d0066c61e7ff053e548c301c45b65a8449d.tar.gz
chromium_src-e0e18d0066c61e7ff053e548c301c45b65a8449d.tar.bz2
BluetoothAdapter: add ability to set default pairing delegate
The default pairing delegate will be used for incoming pairing requests. Permit multiple to be registered so that the UI can have one for popup notifications, and a JS application could register one at a higher priority, so the JS application will be favored. BUG=338492 TEST=device_unittests included Review URL: https://codereview.chromium.org/170063008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253715 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/dbus/fake_bluetooth_device_client.cc533
-rw-r--r--chromeos/dbus/fake_bluetooth_device_client.h17
2 files changed, 240 insertions, 310 deletions
diff --git a/chromeos/dbus/fake_bluetooth_device_client.cc b/chromeos/dbus/fake_bluetooth_device_client.cc
index 08f748a..b77a956 100644
--- a/chromeos/dbus/fake_bluetooth_device_client.cc
+++ b/chromeos/dbus/fake_bluetooth_device_client.cc
@@ -400,105 +400,7 @@ void FakeBluetoothDeviceClient::Pair(
return;
}
- pairing_cancelled_ = false;
-
- FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client =
- static_cast<FakeBluetoothAgentManagerClient*>(
- DBusThreadManager::Get()->GetBluetoothAgentManagerClient());
- 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) ||
- object_path == dbus::ObjectPath(kUnconnectableDevicePath)) {
- // No need to call anything on the pairing delegate, just wait 3 times
- // the interval before acting as if the other end accepted it.
- base::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");
-
- base::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.
- base::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);
-
- base::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 if (object_path == dbus::ObjectPath(kUnpairableDevicePath)) {
- // Fails the pairing with an org.bluez.Error.Failed error.
- base::MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&FakeBluetoothDeviceClient::FailSimulatedPairing,
- base::Unretained(this),
- object_path, error_callback),
- base::TimeDelta::FromMilliseconds(simulation_interval_ms_));
-
- } else {
- error_callback.Run(kNoResponseError, "No pairing fake");
- }
+ SimulatePairing(object_path, false, callback, error_callback);
}
void FakeBluetoothDeviceClient::CancelPairing(
@@ -534,6 +436,106 @@ void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) {
simulation_interval_ms_ = interval_ms;
}
+void FakeBluetoothDeviceClient::CreateDevice(
+ const dbus::ObjectPath& adapter_path,
+ const dbus::ObjectPath& device_path) {
+ if (std::find(device_list_.begin(),
+ device_list_.end(), device_path) != device_list_.end())
+ return;
+
+ Properties* properties = new Properties(base::Bind(
+ &FakeBluetoothDeviceClient::OnPropertyChanged,
+ base::Unretained(this),
+ device_path));
+ properties->adapter.ReplaceValue(adapter_path);
+
+ if (device_path == dbus::ObjectPath(kAppleMousePath)) {
+ properties->address.ReplaceValue(kAppleMouseAddress);
+ properties->bluetooth_class.ReplaceValue(kAppleMouseClass);
+ properties->name.ReplaceValue("Fake Apple Magic Mouse");
+ properties->alias.ReplaceValue(kAppleMouseName);
+
+ std::vector<std::string> uuids;
+ uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
+ properties->uuids.ReplaceValue(uuids);
+
+ } else if (device_path == dbus::ObjectPath(kAppleKeyboardPath)) {
+ properties->address.ReplaceValue(kAppleKeyboardAddress);
+ properties->bluetooth_class.ReplaceValue(kAppleKeyboardClass);
+ properties->name.ReplaceValue("Fake Apple Wireless Keyboard");
+ properties->alias.ReplaceValue(kAppleKeyboardName);
+
+ std::vector<std::string> uuids;
+ uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
+ properties->uuids.ReplaceValue(uuids);
+
+ } else if (device_path == dbus::ObjectPath(kVanishingDevicePath)) {
+ properties->address.ReplaceValue(kVanishingDeviceAddress);
+ properties->bluetooth_class.ReplaceValue(kVanishingDeviceClass);
+ properties->name.ReplaceValue("Fake Vanishing Device");
+ properties->alias.ReplaceValue(kVanishingDeviceName);
+
+ } else if (device_path == dbus::ObjectPath(kMicrosoftMousePath)) {
+ properties->address.ReplaceValue(kMicrosoftMouseAddress);
+ properties->bluetooth_class.ReplaceValue(kMicrosoftMouseClass);
+ properties->name.ReplaceValue("Fake Microsoft Mouse");
+ properties->alias.ReplaceValue(kMicrosoftMouseName);
+
+ std::vector<std::string> uuids;
+ uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
+ properties->uuids.ReplaceValue(uuids);
+
+ } else if (device_path == dbus::ObjectPath(kMotorolaKeyboardPath)) {
+ properties->address.ReplaceValue(kMotorolaKeyboardAddress);
+ properties->bluetooth_class.ReplaceValue(kMotorolaKeyboardClass);
+ properties->name.ReplaceValue("Fake Motorola Keyboard");
+ properties->alias.ReplaceValue(kMotorolaKeyboardName);
+
+ std::vector<std::string> uuids;
+ uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
+ properties->uuids.ReplaceValue(uuids);
+
+ } else if (device_path == dbus::ObjectPath(kSonyHeadphonesPath)) {
+ properties->address.ReplaceValue(kSonyHeadphonesAddress);
+ properties->bluetooth_class.ReplaceValue(kSonyHeadphonesClass);
+ properties->name.ReplaceValue("Fake Sony Headphones");
+ properties->alias.ReplaceValue(kSonyHeadphonesName);
+
+ } else if (device_path == dbus::ObjectPath(kPhonePath)) {
+ properties->address.ReplaceValue(kPhoneAddress);
+ properties->bluetooth_class.ReplaceValue(kPhoneClass);
+ properties->name.ReplaceValue("Fake Phone");
+ properties->alias.ReplaceValue(kPhoneName);
+
+ } else if (device_path == dbus::ObjectPath(kWeirdDevicePath)) {
+ properties->address.ReplaceValue(kWeirdDeviceAddress);
+ properties->bluetooth_class.ReplaceValue(kWeirdDeviceClass);
+ properties->name.ReplaceValue("Fake Weird Device");
+ properties->alias.ReplaceValue(kWeirdDeviceName);
+
+ } else if (device_path == dbus::ObjectPath(kUnconnectableDevicePath)) {
+ properties->address.ReplaceValue(kUnconnectableDeviceAddress);
+ properties->bluetooth_class.ReplaceValue(kUnconnectableDeviceClass);
+ properties->name.ReplaceValue("Fake Unconnectable Device");
+ properties->alias.ReplaceValue(kUnconnectableDeviceName);
+
+ } else if (device_path == dbus::ObjectPath(kUnpairableDevicePath)) {
+ properties->address.ReplaceValue(kUnpairableDeviceAddress);
+ properties->bluetooth_class.ReplaceValue(kUnpairableDeviceClass);
+ properties->name.ReplaceValue("Fake Unpairable Device");
+ properties->alias.ReplaceValue(kUnpairableDeviceName);
+
+ } else {
+ NOTREACHED();
+
+ }
+
+ properties_map_[device_path] = properties;
+ device_list_.push_back(device_path);
+ FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
+ DeviceAdded(device_path));
+}
+
void FakeBluetoothDeviceClient::RemoveDevice(
const dbus::ObjectPath& adapter_path,
const dbus::ObjectPath& device_path) {
@@ -578,222 +580,34 @@ void FakeBluetoothDeviceClient::DiscoverySimulationTimer() {
// 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));
-
- std::vector<std::string> uuids;
- uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
- properties->uuids.ReplaceValue(uuids);
-
- properties_map_[dbus::ObjectPath(kAppleMousePath)] = properties;
- device_list_.push_back(dbus::ObjectPath(kAppleMousePath));
- FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
- DeviceAdded(dbus::ObjectPath(kAppleMousePath)));
- }
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ 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));
-
- std::vector<std::string> uuids;
- uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
- properties->uuids.ReplaceValue(uuids);
-
- properties_map_[dbus::ObjectPath(kAppleKeyboardPath)] = properties;
- device_list_.push_back(dbus::ObjectPath(kAppleKeyboardPath));
- FOR_EACH_OBSERVER(BluetoothDeviceClient::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(BluetoothDeviceClient::Observer, observers_,
- DeviceAdded(dbus::ObjectPath(kVanishingDevicePath)));
- }
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ dbus::ObjectPath(kAppleKeyboardPath));
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ 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));
-
- std::vector<std::string> uuids;
- uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
- properties->uuids.ReplaceValue(uuids);
-
- properties_map_[dbus::ObjectPath(kMicrosoftMousePath)] = properties;
- device_list_.push_back(dbus::ObjectPath(kMicrosoftMousePath));
- FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
- DeviceAdded(dbus::ObjectPath(kMicrosoftMousePath)));
- }
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ 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));
-
- std::vector<std::string> uuids;
- uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
- properties->uuids.ReplaceValue(uuids);
-
- properties_map_[dbus::ObjectPath(kMotorolaKeyboardPath)] = properties;
- device_list_.push_back(dbus::ObjectPath(kMotorolaKeyboardPath));
- FOR_EACH_OBSERVER(BluetoothDeviceClient::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(BluetoothDeviceClient::Observer, observers_,
- DeviceAdded(dbus::ObjectPath(kSonyHeadphonesPath)));
- }
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ dbus::ObjectPath(kMotorolaKeyboardPath));
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ 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(BluetoothDeviceClient::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(BluetoothDeviceClient::Observer, observers_,
- DeviceAdded(dbus::ObjectPath(kWeirdDevicePath)));
- }
-
- if (std::find(device_list_.begin(), device_list_.end(),
- dbus::ObjectPath(kUnconnectableDevicePath)) ==
- device_list_.end()) {
- Properties* properties = new Properties(base::Bind(
- &FakeBluetoothDeviceClient::OnPropertyChanged,
- base::Unretained(this),
- dbus::ObjectPath(kUnconnectableDevicePath)));
- properties->address.ReplaceValue(kUnconnectableDeviceAddress);
- properties->bluetooth_class.ReplaceValue(kUnconnectableDeviceClass);
- properties->name.ReplaceValue("Fake Unconnectable Device");
- properties->alias.ReplaceValue(kUnconnectableDeviceName);
- properties->adapter.ReplaceValue(
- dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
-
- properties_map_[dbus::ObjectPath(kUnconnectableDevicePath)] = properties;
- device_list_.push_back(dbus::ObjectPath(kUnconnectableDevicePath));
- FOR_EACH_OBSERVER(
- BluetoothDeviceClient::Observer, observers_,
- DeviceAdded(dbus::ObjectPath(kUnconnectableDevicePath)));
- }
-
- if (std::find(device_list_.begin(), device_list_.end(),
- dbus::ObjectPath(kUnpairableDevicePath)) ==
- device_list_.end()) {
- Properties* properties = new Properties(base::Bind(
- &FakeBluetoothDeviceClient::OnPropertyChanged,
- base::Unretained(this),
- dbus::ObjectPath(kUnpairableDevicePath)));
- properties->address.ReplaceValue(kUnpairableDeviceAddress);
- properties->bluetooth_class.ReplaceValue(kUnpairableDeviceClass);
- properties->name.ReplaceValue("Fake Unpairable Device");
- properties->alias.ReplaceValue(kUnpairableDeviceName);
- properties->adapter.ReplaceValue(
- dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
-
- properties_map_[dbus::ObjectPath(kUnpairableDevicePath)] = properties;
- device_list_.push_back(dbus::ObjectPath(kUnpairableDevicePath));
- FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
- DeviceAdded(dbus::ObjectPath(kUnpairableDevicePath)));
- }
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ dbus::ObjectPath(kPhonePath));
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ dbus::ObjectPath(kWeirdDevicePath));
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ dbus::ObjectPath(kUnconnectableDevicePath));
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
+ dbus::ObjectPath(kUnpairableDevicePath));
} else if (discovery_simulation_step_ == 13) {
RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
@@ -813,6 +627,109 @@ void FakeBluetoothDeviceClient::DiscoverySimulationTimer() {
}
+void FakeBluetoothDeviceClient::SimulatePairing(
+ const dbus::ObjectPath& object_path,
+ bool incoming_request,
+ const base::Closure& callback,
+ const ErrorCallback& error_callback) {
+ pairing_cancelled_ = false;
+
+ FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client =
+ static_cast<FakeBluetoothAgentManagerClient*>(
+ DBusThreadManager::Get()->GetBluetoothAgentManagerClient());
+ FakeBluetoothAgentServiceProvider* agent_service_provider =
+ fake_bluetooth_agent_manager_client->GetAgentServiceProvider();
+ CHECK(agent_service_provider != NULL);
+
+ if (object_path == dbus::ObjectPath(kAppleMousePath) ||
+ object_path == dbus::ObjectPath(kMicrosoftMousePath) ||
+ object_path == dbus::ObjectPath(kUnconnectableDevicePath)) {
+ // No need to call anything on the pairing delegate, just wait 3 times
+ // the interval before acting as if the other end accepted it.
+ base::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");
+
+ base::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.
+ base::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);
+
+ base::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 if (object_path == dbus::ObjectPath(kUnpairableDevicePath)) {
+ // Fails the pairing with an org.bluez.Error.Failed error.
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&FakeBluetoothDeviceClient::FailSimulatedPairing,
+ base::Unretained(this),
+ object_path, error_callback),
+ base::TimeDelta::FromMilliseconds(simulation_interval_ms_));
+
+ } else {
+ error_callback.Run(kNoResponseError, "No pairing fake");
+ }
+}
+
void FakeBluetoothDeviceClient::CompleteSimulatedPairing(
const dbus::ObjectPath& object_path,
const base::Closure& callback,
@@ -822,7 +739,7 @@ void FakeBluetoothDeviceClient::CompleteSimulatedPairing(
pairing_cancelled_ = false;
error_callback.Run(bluetooth_device::kErrorAuthenticationCanceled,
- "Cancaled");
+ "Cancelled");
} else {
Properties* properties = GetProperties(object_path);
diff --git a/chromeos/dbus/fake_bluetooth_device_client.h b/chromeos/dbus/fake_bluetooth_device_client.h
index 95b21ba..e232416 100644
--- a/chromeos/dbus/fake_bluetooth_device_client.h
+++ b/chromeos/dbus/fake_bluetooth_device_client.h
@@ -72,14 +72,27 @@ class CHROMEOS_EXPORT FakeBluetoothDeviceClient
void SetSimulationIntervalMs(int interval_ms);
- // Simulate discovery of devices for the given adapter.
+ // Simulates 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.
+ // Creates a device from the set we return for the given adapter.
+ void CreateDevice(const dbus::ObjectPath& adapter_path,
+ const dbus::ObjectPath& device_path);
+
+ // Removes a device from the set we return for the given adapter.
void RemoveDevice(const dbus::ObjectPath& adapter_path,
const dbus::ObjectPath& device_path);
+ // Simulates a pairing for the device with the given D-Bus object path,
+ // |object_path|. Set |incoming_request| to true if simulating an incoming
+ // pairing request, false for an outgoing one. On successful completion
+ // |callback| will be called, on failure, |error_callback| is called.
+ void SimulatePairing(const dbus::ObjectPath& object_path,
+ bool incoming_request,
+ const base::Closure& callback,
+ const ErrorCallback& error_callback);
+
// Object paths, names, addresses and bluetooth classes of the devices
// we can emulate.
static const char kPairedDevicePath[];