Chromium Code Reviews| Index: chromeos/dbus/fake_bluetooth_device_client.cc |
| diff --git a/chromeos/dbus/fake_bluetooth_device_client.cc b/chromeos/dbus/fake_bluetooth_device_client.cc |
| index 4bc3708051ccf7af86412bd8db444418ded79384..8b61eff80c72d08a2f556c7f3b36bfffb0091d13 100644 |
| --- a/chromeos/dbus/fake_bluetooth_device_client.cc |
| +++ b/chromeos/dbus/fake_bluetooth_device_client.cc |
| @@ -69,11 +69,6 @@ void SimulatedProfileSocket(int fd) { |
| close(fd); |
| } |
| -void SimpleErrorCallback(const std::string& error_name, |
| - const std::string& error_message) { |
| - VLOG(1) << "Bluetooth Error: " << error_name << ": " << error_message; |
| -} |
| - |
| } // namespace |
| namespace chromeos { |
| @@ -311,6 +306,15 @@ FakeBluetoothDeviceClient::GetProperties(const dbus::ObjectPath& object_path) { |
| return NULL; |
| } |
| +FakeBluetoothDeviceClient::SimulatedPairingOptions* |
| +FakeBluetoothDeviceClient::GetPairingOptions( |
| + const dbus::ObjectPath& object_path) { |
| + PairingOptionsMap::iterator iter = pairing_options_map_.find(object_path); |
| + if (iter != pairing_options_map_.end()) |
| + return iter->second; |
| + return NULL; |
| +} |
| + |
| void FakeBluetoothDeviceClient::Connect( |
| const dbus::ObjectPath& object_path, |
| const base::Closure& callback, |
| @@ -555,6 +559,12 @@ void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) { |
| simulation_interval_ms_ = interval_ms; |
| } |
| +void FakeBluetoothDeviceClient::SimpleErrorCallback( |
|
xiyuan
2015/07/30 17:21:22
Why move this into FakeBluetoothDeviceClient inter
rfrappier
2015/07/30 22:21:39
Forgot to revert this change (I thought I needed i
|
| + const std::string& error_name, |
| + const std::string& error_message) { |
| + VLOG(1) << "Bluetooth Error: " << error_name << ": " << error_message; |
| +} |
| + |
| void FakeBluetoothDeviceClient::CreateDevice( |
| const dbus::ObjectPath& adapter_path, |
| const dbus::ObjectPath& device_path) { |
| @@ -671,6 +681,44 @@ void FakeBluetoothDeviceClient::CreateDevice( |
| DeviceAdded(device_path)); |
| } |
| +void FakeBluetoothDeviceClient::CreateDeviceWithProperties( |
| + const dbus::ObjectPath& adapter_path, |
| + const dbus::ObjectPath& device_path, |
| + const std::string& device_name, |
| + const std::string& device_alias, |
| + const std::string& device_address, |
| + const std::string& pairing_method, |
| + const std::string& pairing_auth_token, |
| + const uint32& device_class, |
| + const bool is_trusted) { |
| + if (std::find(device_list_.begin(), device_list_.end(), device_path) != |
| + device_list_.end()) |
|
stevenjb
2015/07/30 18:28:52
LOG(ERROR) << "Bluetootl device already exists: "
rfrappier
2015/07/30 22:21:39
This will probably be removed later to allow for e
|
| + return; |
| + |
| + Properties* properties = |
|
stevenjb
2015/07/30 18:28:51
Use a scoped_ptr here so that ownership passing is
rfrappier
2015/07/30 22:21:39
Done.
|
| + new Properties(base::Bind(&FakeBluetoothDeviceClient::OnPropertyChanged, |
| + base::Unretained(this), device_path)); |
| + properties->adapter.ReplaceValue(adapter_path); |
| + properties->name.ReplaceValue(device_name); |
| + properties->alias.ReplaceValue(device_alias); |
| + properties->address.ReplaceValue(device_address); |
| + properties->bluetooth_class.ReplaceValue(device_class); |
| + properties->trusted.ReplaceValue(is_trusted); |
| + |
| + if (is_trusted) |
| + properties->paired.ReplaceValue(true); |
| + |
| + SimulatedPairingOptions* options = new SimulatedPairingOptions; |
|
stevenjb
2015/07/30 18:28:52
scoped_ptr
rfrappier
2015/07/30 22:21:39
Done.
|
| + options->pairing_method = pairing_method; |
| + options->pairing_auth_token = pairing_auth_token; |
| + |
| + properties_map_[device_path] = properties; |
|
stevenjb
2015/07/30 18:28:52
If we make this a ScopedPtrMap, this will be prope
rfrappier
2015/07/30 22:21:39
Acknowledged.
|
| + device_list_.push_back(device_path); |
| + pairing_options_map_[device_path] = options; |
|
xiyuan
2015/07/30 17:21:22
This leaks. You need to do "STLDeleteValues()" sim
stevenjb
2015/07/30 18:28:52
A good reason to use ScopedPtrMap for both of thes
rfrappier
2015/07/30 22:21:39
Done.
|
| + FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| + DeviceAdded(device_path)); |
| +} |
| + |
| void FakeBluetoothDeviceClient::RemoveDevice( |
| const dbus::ObjectPath& adapter_path, |
| const dbus::ObjectPath& device_path) { |
| @@ -796,44 +844,49 @@ void FakeBluetoothDeviceClient::IncomingPairingSimulationTimer() { |
| case 1: |
| CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| dbus::ObjectPath(kConfirmPasskeyPath)); |
| - SimulatePairing(dbus::ObjectPath(kConfirmPasskeyPath), true, |
| - base::Bind(&base::DoNothing), |
| - base::Bind(&SimpleErrorCallback)); |
| + SimulatePairing( |
| + dbus::ObjectPath(kConfirmPasskeyPath), true, |
| + base::Bind(&base::DoNothing), |
| + base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); |
| break; |
| case 2: |
| CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| dbus::ObjectPath(kJustWorksPath)); |
| - SimulatePairing(dbus::ObjectPath(kJustWorksPath), true, |
| - base::Bind(&base::DoNothing), |
| - base::Bind(&SimpleErrorCallback)); |
| + SimulatePairing( |
| + dbus::ObjectPath(kJustWorksPath), true, base::Bind(&base::DoNothing), |
| + base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); |
| break; |
| case 3: |
| CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| dbus::ObjectPath(kDisplayPinCodePath)); |
| - SimulatePairing(dbus::ObjectPath(kDisplayPinCodePath), true, |
| - base::Bind(&base::DoNothing), |
| - base::Bind(&SimpleErrorCallback)); |
| + SimulatePairing( |
| + dbus::ObjectPath(kDisplayPinCodePath), true, |
| + base::Bind(&base::DoNothing), |
| + base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); |
| break; |
| case 4: |
| CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| dbus::ObjectPath(kDisplayPasskeyPath)); |
| - SimulatePairing(dbus::ObjectPath(kDisplayPasskeyPath), true, |
| - base::Bind(&base::DoNothing), |
| - base::Bind(&SimpleErrorCallback)); |
| + SimulatePairing( |
| + dbus::ObjectPath(kDisplayPasskeyPath), true, |
| + base::Bind(&base::DoNothing), |
| + base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); |
| break; |
| case 5: |
| CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| dbus::ObjectPath(kRequestPinCodePath)); |
| - SimulatePairing(dbus::ObjectPath(kRequestPinCodePath), true, |
| - base::Bind(&base::DoNothing), |
| - base::Bind(&SimpleErrorCallback)); |
| + SimulatePairing( |
| + dbus::ObjectPath(kRequestPinCodePath), true, |
| + base::Bind(&base::DoNothing), |
| + base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); |
| break; |
| case 6: |
| CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| dbus::ObjectPath(kRequestPasskeyPath)); |
| - SimulatePairing(dbus::ObjectPath(kRequestPasskeyPath), true, |
| - base::Bind(&base::DoNothing), |
| - base::Bind(&SimpleErrorCallback)); |
| + SimulatePairing( |
| + dbus::ObjectPath(kRequestPasskeyPath), true, |
| + base::Bind(&base::DoNothing), |
| + base::Bind(&FakeBluetoothDeviceClient::SimpleErrorCallback)); |
| break; |
| default: |
| return; |
| @@ -861,111 +914,148 @@ void FakeBluetoothDeviceClient::SimulatePairing( |
| fake_bluetooth_agent_manager_client->GetAgentServiceProvider(); |
| CHECK(agent_service_provider != NULL); |
| - if (object_path == dbus::ObjectPath(kLegacyAutopairPath) || |
| - object_path == dbus::ObjectPath(kConnectUnpairablePath) || |
| - object_path == dbus::ObjectPath(kUnconnectableDevicePath) || |
| - object_path == dbus::ObjectPath(kLowEnergyPath)) { |
| - // 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::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| - FROM_HERE, |
| - base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| - base::Unretained(this), object_path, callback, |
| - error_callback), |
| - base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); |
| + // Grab the device's pairing properties. |
| + PairingOptionsMap::iterator iter = pairing_options_map_.find(object_path); |
| - } else if (object_path == dbus::ObjectPath(kDisplayPinCodePath)) { |
| - // 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"); |
| + // If the device with path |object_path| has simulated pairing properties |
| + // defined, then pair it based on its |pairing_method|. |
| + if (iter != pairing_options_map_.end()) { |
| + if (iter->second->pairing_method == "None" || |
|
xiyuan
2015/07/30 17:21:22
nit: Put "None", "PIN Code" etc in const.
rfrappier
2015/07/30 22:21:39
Done.
|
| + iter->second->pairing_method == "") { |
| + // Simply pair and connect the device. |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| + base::Unretained(this), object_path, callback, |
| + error_callback), |
| + base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); |
| + } else if (iter->second->pairing_method == "PIN Code") { |
| + // Display a Pincode, and wait 7 times the interval before acting as |
| + // if the other end accepted it. |
| + agent_service_provider->DisplayPinCode(object_path, |
| + iter->second->pairing_auth_token); |
| - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| - FROM_HERE, |
| - base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| - base::Unretained(this), object_path, callback, |
| - error_callback), |
| - base::TimeDelta::FromMilliseconds(7 * simulation_interval_ms_)); |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| + base::Unretained(this), object_path, callback, |
| + error_callback), |
| + base::TimeDelta::FromMilliseconds(7 * simulation_interval_ms_)); |
|
stevenjb
2015/07/30 18:28:52
7 should be a const and used here and below.
rfrappier
2015/07/30 22:21:39
Done.
|
| + } else if (iter->second->pairing_method == "PassKey") { |
| + // Display a passkey, and each interval act as if another key was entered |
| + // for it. |
| + agent_service_provider->DisplayPasskey( |
| + object_path, std::stoi(iter->second->pairing_auth_token), 0); |
| - } else if (object_path == dbus::ObjectPath(kVanishingDevicePath)) { |
| - // The vanishing device simulates being too far away, and thus times out. |
| - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| - FROM_HERE, |
| - base::Bind(&FakeBluetoothDeviceClient::TimeoutSimulatedPairing, |
| - base::Unretained(this), object_path, error_callback), |
| - base::TimeDelta::FromMilliseconds(4 * simulation_interval_ms_)); |
| + base::ThreadTaskRunnerHandle::Get()->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(kLegacyAutopairPath) || |
| + object_path == dbus::ObjectPath(kConnectUnpairablePath) || |
| + object_path == dbus::ObjectPath(kUnconnectableDevicePath) || |
| + object_path == dbus::ObjectPath(kLowEnergyPath)) { |
| + // 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::ThreadTaskRunnerHandle::Get()->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(kDisplayPasskeyPath)) { |
| - // Display a passkey, and each interval act as if another key was entered |
| - // for it. |
| - agent_service_provider->DisplayPasskey(object_path, 123456, 0); |
| + } else if (object_path == dbus::ObjectPath(kDisplayPinCodePath)) { |
| + // 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"); |
|
stevenjb
2015/07/30 18:28:52
"123456" should be declared as a const char[].
rfrappier
2015/07/30 22:21:39
Done.
|
| - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| - FROM_HERE, base::Bind(&FakeBluetoothDeviceClient::SimulateKeypress, |
| - base::Unretained(this), 1, object_path, callback, |
| - error_callback), |
| - base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| + base::ThreadTaskRunnerHandle::Get()->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(kRequestPinCodePath)) { |
| - // 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(kConfirmPasskeyPath)) { |
| - // 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(kRequestPasskeyPath)) { |
| - // 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::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| - FROM_HERE, |
| - base::Bind(&FakeBluetoothDeviceClient::FailSimulatedPairing, |
| - base::Unretained(this), object_path, error_callback), |
| - base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| + } else if (object_path == dbus::ObjectPath(kVanishingDevicePath)) { |
| + // The vanishing device simulates being too far away, and thus times out. |
| + base::ThreadTaskRunnerHandle::Get()->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(kDisplayPasskeyPath)) { |
| + // Display a passkey, and each interval act as if another key was entered |
| + // for it. |
| + agent_service_provider->DisplayPasskey(object_path, 123456, 0); |
|
stevenjb
2015/07/30 18:28:52
const int for 123456
rfrappier
2015/07/30 22:21:39
Done.
|
| - } else if (object_path == dbus::ObjectPath(kJustWorksPath)) { |
| - if (incoming_request) { |
| - agent_service_provider->RequestAuthorization( |
| - object_path, |
| + base::ThreadTaskRunnerHandle::Get()->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(kRequestPinCodePath)) { |
| + // 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(kConfirmPasskeyPath)) { |
| + // Request confirmation of a Passkey. |
| + agent_service_provider->RequestConfirmation( |
| + object_path, 123456, |
| base::Bind(&FakeBluetoothDeviceClient::ConfirmationCallback, |
| - base::Unretained(this), |
| - object_path, |
| - callback, |
| + base::Unretained(this), object_path, callback, |
| error_callback)); |
| + } else if (object_path == dbus::ObjectPath(kRequestPasskeyPath)) { |
| + // 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::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&FakeBluetoothDeviceClient::FailSimulatedPairing, |
| + base::Unretained(this), object_path, error_callback), |
| + base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); |
| + |
| + } else if (object_path == dbus::ObjectPath(kJustWorksPath)) { |
| + if (incoming_request) { |
| + agent_service_provider->RequestAuthorization( |
| + object_path, |
| + base::Bind(&FakeBluetoothDeviceClient::ConfirmationCallback, |
| + base::Unretained(this), object_path, callback, |
| + error_callback)); |
| + |
| + } else { |
| + // 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::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| + base::Unretained(this), object_path, callback, |
| + error_callback), |
| + base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); |
|
stevenjb
2015/07/30 18:28:52
const int for 3
rfrappier
2015/07/30 22:21:39
Done.
|
| + } |
| + |
| } else { |
| - // 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::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| FROM_HERE, |
| base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, |
| base::Unretained(this), object_path, callback, |
| error_callback), |
| base::TimeDelta::FromMilliseconds(3 * simulation_interval_ms_)); |
| + // error_callback.Run(kNoResponseError, "No pairing fake"); |
| } |
| - |
| - } else { |
| - error_callback.Run(kNoResponseError, "No pairing fake"); |
| } |
| } |