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 64df07f72732b930e288b20c410f6f0e8e0110f2..cf7a57e2cf1ca99c7f99a9146d5c2167aed85e85 100644 |
--- a/chromeos/dbus/fake_bluetooth_device_client.cc |
+++ b/chromeos/dbus/fake_bluetooth_device_client.cc |
@@ -26,6 +26,7 @@ |
#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 "chromeos/dbus/fake_bluetooth_gatt_service_client.h" |
#include "chromeos/dbus/fake_bluetooth_input_client.h" |
#include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" |
#include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" |
@@ -167,6 +168,15 @@ const char FakeBluetoothDeviceClient::kJustWorksName[] = |
"Just-Works Device"; |
const uint32 FakeBluetoothDeviceClient::kJustWorksClass = 0x240428; |
+const char FakeBluetoothDeviceClient::kLowEnergyPath[] = |
+ "/fake/hci0/devC"; |
+const char FakeBluetoothDeviceClient::kLowEnergyAddress[] = |
+ "00:1A:11:00:15:30"; |
+const char FakeBluetoothDeviceClient::kLowEnergyName[] = |
+ "Bluetooth 4.0 Heart Rate Monitor"; |
+const uint32 FakeBluetoothDeviceClient::kLowEnergyClass = |
+ 0x000918; // Major class "Health", Minor class "Heart/Pulse Rate Monitor." |
+ |
FakeBluetoothDeviceClient::Properties::Properties( |
const PropertyChangedCallback& callback) |
: BluetoothDeviceClient::Properties( |
@@ -293,6 +303,15 @@ void FakeBluetoothDeviceClient::Connect( |
properties->connected.ReplaceValue(true); |
callback.Run(); |
+ // Expose GATT services if connected to LE device. |
+ if (object_path == dbus::ObjectPath(kLowEnergyPath)) { |
+ FakeBluetoothGattServiceClient* gatt_service_client = |
+ static_cast<FakeBluetoothGattServiceClient*>( |
+ DBusThreadManager::Get()->GetBluetoothGattServiceClient()); |
+ gatt_service_client->ExposeHeartRateService( |
+ dbus::ObjectPath(kLowEnergyPath)); |
+ } |
+ |
AddInputDeviceIfNeeded(object_path, properties); |
} |
@@ -303,12 +322,21 @@ void FakeBluetoothDeviceClient::Disconnect( |
VLOG(1) << "Disconnect: " << object_path.value(); |
Properties* properties = GetProperties(object_path); |
- if (properties->connected.value() == true) { |
- callback.Run(); |
- properties->connected.ReplaceValue(false); |
- } else { |
+ if (!properties->connected.value()) { |
error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); |
+ return; |
+ } |
+ |
+ // Hide the Heart Rate Service if disconnected from LE device. |
+ if (object_path == dbus::ObjectPath(kLowEnergyPath)) { |
+ FakeBluetoothGattServiceClient* gatt_service_client = |
+ static_cast<FakeBluetoothGattServiceClient*>( |
+ DBusThreadManager::Get()->GetBluetoothGattServiceClient()); |
+ gatt_service_client->HideHeartRateService(); |
} |
+ |
+ callback.Run(); |
+ properties->connected.ReplaceValue(false); |
} |
void FakeBluetoothDeviceClient::ConnectProfile( |
@@ -564,6 +592,16 @@ void FakeBluetoothDeviceClient::CreateDevice( |
properties->name.ReplaceValue("JustWorks"); |
properties->alias.ReplaceValue(kJustWorksName); |
+ } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { |
+ properties->address.ReplaceValue(kLowEnergyAddress); |
+ properties->bluetooth_class.ReplaceValue(kLowEnergyClass); |
+ properties->name.ReplaceValue("Heart Rate Monitor"); |
+ properties->alias.ReplaceValue(kLowEnergyName); |
+ |
+ std::vector<std::string> uuids; |
+ uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); |
+ properties->uuids.ReplaceValue(uuids); |
+ |
} else { |
NOTREACHED(); |
@@ -597,6 +635,13 @@ void FakeBluetoothDeviceClient::RemoveDevice( |
DBusThreadManager::Get()->GetBluetoothInputClient()); |
fake_bluetooth_input_client->RemoveInputDevice(device_path); |
+ if (device_path == dbus::ObjectPath(kLowEnergyPath)) { |
+ FakeBluetoothGattServiceClient* gatt_service_client = |
+ static_cast<FakeBluetoothGattServiceClient*>( |
+ DBusThreadManager::Get()->GetBluetoothGattServiceClient()); |
+ gatt_service_client->HideHeartRateService(); |
+ } |
+ |
FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
DeviceRemoved(device_path)); |
@@ -637,6 +682,8 @@ void FakeBluetoothDeviceClient::DiscoverySimulationTimer() { |
dbus::ObjectPath(kDisplayPasskeyPath)); |
CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
dbus::ObjectPath(kRequestPinCodePath)); |
+ CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
+ dbus::ObjectPath(kLowEnergyPath)); |
keybuk
2014/03/21 19:57:53
Since this is an LE device, following the pattern
armansito
2014/03/21 23:18:11
Done.
|
} else if (discovery_simulation_step_ == 10) { |
CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
@@ -744,7 +791,8 @@ void FakeBluetoothDeviceClient::SimulatePairing( |
if (object_path == dbus::ObjectPath(kLegacyAutopairPath) || |
object_path == dbus::ObjectPath(kConnectUnpairablePath) || |
- object_path == dbus::ObjectPath(kUnconnectableDevicePath)) { |
+ 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::MessageLoop::current()->PostDelayedTask( |