diff options
author | scheib <scheib@chromium.org> | 2015-10-27 19:26:47 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-28 02:27:49 +0000 |
commit | 3e992aaafae77b4e6c6fd78c77f686ff7eb11443 (patch) | |
tree | aaff53afb303ac8748b8d7f76a60388b28b4429c | |
parent | e61501e21cce896426e724c047e2d7998e89b05e (diff) | |
download | chromium_src-3e992aaafae77b4e6c6fd78c77f686ff7eb11443.zip chromium_src-3e992aaafae77b4e6c6fd78c77f686ff7eb11443.tar.gz chromium_src-3e992aaafae77b4e6c6fd78c77f686ff7eb11443.tar.bz2 |
bluetooth: android: BluetoothRemoteGattCharacteristicAndroid::GetProperties()
BUG=545682
Review URL: https://codereview.chromium.org/1423093003
Cr-Commit-Position: refs/heads/master@{#356497}
9 files changed, 74 insertions, 24 deletions
diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothRemoteGattCharacteristic.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothRemoteGattCharacteristic.java index fbb7962..814602f 100644 --- a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothRemoteGattCharacteristic.java +++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothRemoteGattCharacteristic.java @@ -44,4 +44,11 @@ final class ChromeBluetoothRemoteGattCharacteristic { private String getUUID() { return mCharacteristic.getUuid().toString(); } + + // Implements BluetoothRemoteGattCharacteristicAndroid::GetProperties. + @CalledByNative + private int getProperties() { + // TODO(scheib): Must read Extended Properties Descriptor. crbug.com/548449 + return mCharacteristic.getProperties(); + } } diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java index 9bfaeda..115c317 100644 --- a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java +++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java @@ -365,6 +365,10 @@ class Wrappers { return mCharacteristic.getInstanceId(); } + public int getProperties() { + return mCharacteristic.getProperties(); + } + public UUID getUuid() { return mCharacteristic.getUuid(); } diff --git a/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc b/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc index e7e412b..914be35 100644 --- a/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc +++ b/device/bluetooth/bluetooth_gatt_characteristic_unittest.cc @@ -46,12 +46,12 @@ TEST_F(BluetoothGattCharacteristicTest, GetIdentifier) { BluetoothGattService* service2 = device2->GetGattServices()[0]; BluetoothGattService* service3 = device2->GetGattServices()[1]; // 6 characteristics (same UUID), 2 on each service. - SimulateGattCharacteristic(service1, uuid); - SimulateGattCharacteristic(service1, uuid); - SimulateGattCharacteristic(service2, uuid); - SimulateGattCharacteristic(service2, uuid); - SimulateGattCharacteristic(service3, uuid); - SimulateGattCharacteristic(service3, uuid); + SimulateGattCharacteristic(service1, uuid, /* properties */ 0); + SimulateGattCharacteristic(service1, uuid, /* properties */ 0); + SimulateGattCharacteristic(service2, uuid, /* properties */ 0); + SimulateGattCharacteristic(service2, uuid, /* properties */ 0); + SimulateGattCharacteristic(service3, uuid, /* properties */ 0); + SimulateGattCharacteristic(service3, uuid, /* properties */ 0); BluetoothGattCharacteristic* char1 = service1->GetCharacteristics()[0]; BluetoothGattCharacteristic* char2 = service1->GetCharacteristics()[1]; BluetoothGattCharacteristic* char3 = service2->GetCharacteristics()[0]; @@ -100,9 +100,9 @@ TEST_F(BluetoothGattCharacteristicTest, GetUUID) { std::string uuid_str2("22222222-0000-1000-8000-00805f9b34fb"); BluetoothUUID uuid1(uuid_str1); BluetoothUUID uuid2(uuid_str2); - SimulateGattCharacteristic(service, uuid_str1); - SimulateGattCharacteristic(service, uuid_str2); - SimulateGattCharacteristic(service, uuid_str2); + SimulateGattCharacteristic(service, uuid_str1, /* properties */ 0); + SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0); + SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0); BluetoothGattCharacteristic* char1 = service->GetCharacteristics()[0]; BluetoothGattCharacteristic* char2 = service->GetCharacteristics()[1]; BluetoothGattCharacteristic* char3 = service->GetCharacteristics()[2]; @@ -120,4 +120,32 @@ TEST_F(BluetoothGattCharacteristicTest, GetUUID) { } #endif // defined(OS_ANDROID) +#if defined(OS_ANDROID) +TEST_F(BluetoothGattCharacteristicTest, GetProperties) { + InitWithFakeAdapter(); + StartLowEnergyDiscoverySession(); + BluetoothDevice* device = DiscoverLowEnergyDevice(3); + device->CreateGattConnection(GetGattConnectionCallback(), + GetConnectErrorCallback()); + SimulateGattConnection(device); + std::vector<std::string> services; + std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); + services.push_back(uuid); + SimulateGattServicesDiscovered(device, services); + BluetoothGattService* service = device->GetGattServices()[0]; + + // Create two characteristics with different properties: + SimulateGattCharacteristic(service, uuid, /* properties */ 0); + SimulateGattCharacteristic(service, uuid, /* properties */ 7); + + // Read the properties. Because ordering is unknown swap as necessary. + int properties1 = service->GetCharacteristics()[0]->GetProperties(); + int properties2 = service->GetCharacteristics()[1]->GetProperties(); + if (properties2 == 0) + std::swap(properties1, properties2); + EXPECT_EQ(0, properties1); + EXPECT_EQ(7, properties2); +} +#endif // defined(OS_ANDROID) + } // namespace device diff --git a/device/bluetooth/bluetooth_gatt_service_unittest.cc b/device/bluetooth/bluetooth_gatt_service_unittest.cc index c435fba..cd8c0d8 100644 --- a/device/bluetooth/bluetooth_gatt_service_unittest.cc +++ b/device/bluetooth/bluetooth_gatt_service_unittest.cc @@ -116,10 +116,10 @@ TEST_F(BluetoothGattServiceTest, GetCharacteristics_and_GetCharacteristic) { std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb"; std::string characteristic_uuid3 = characteristic_uuid2; // Duplicate UUID. std::string characteristic_uuid4 = "33333333-0000-1000-8000-00805f9b34fb"; - SimulateGattCharacteristic(service, characteristic_uuid1); - SimulateGattCharacteristic(service, characteristic_uuid2); - SimulateGattCharacteristic(service, characteristic_uuid3); - SimulateGattCharacteristic(service, characteristic_uuid4); + SimulateGattCharacteristic(service, characteristic_uuid1, /* properties */ 0); + SimulateGattCharacteristic(service, characteristic_uuid2, /* properties */ 0); + SimulateGattCharacteristic(service, characteristic_uuid3, /* properties */ 0); + SimulateGattCharacteristic(service, characteristic_uuid4, /* properties */ 0); // Verify that GetCharacteristic can retrieve characteristics again by ID, // and that the same Characteristics come back. diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc b/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc index aa85463..f720474 100644 --- a/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc +++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc @@ -66,8 +66,8 @@ BluetoothGattService* BluetoothRemoteGattCharacteristicAndroid::GetService() BluetoothGattCharacteristic::Properties BluetoothRemoteGattCharacteristicAndroid::GetProperties() const { - NOTIMPLEMENTED(); - return 0; + return Java_ChromeBluetoothRemoteGattCharacteristic_getProperties( + AttachCurrentThread(), j_characteristic_.obj()); } BluetoothGattCharacteristic::Permissions diff --git a/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java index 7bf77c8..443da83 100644 --- a/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java +++ b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java @@ -317,7 +317,7 @@ class Fakes { // Create a characteristic and add it to this service. @CalledByNative("FakeBluetoothGattService") private static void addCharacteristic( - ChromeBluetoothRemoteGattService chromeService, String uuidString) { + ChromeBluetoothRemoteGattService chromeService, String uuidString, int properties) { FakeBluetoothGattService fakeService = (FakeBluetoothGattService) chromeService.mService; UUID uuid = UUID.fromString(uuidString); @@ -330,7 +330,7 @@ class Fakes { } } fakeService.mCharacteristics.add(new FakeBluetoothGattCharacteristic( - uuid, /* instanceId */ countOfDuplicateUUID)); + /* instanceId */ countOfDuplicateUUID, properties, uuid)); } // ----------------------------------------------------------------------------------------- @@ -357,13 +357,15 @@ class Fakes { */ static class FakeBluetoothGattCharacteristic extends Wrappers.BluetoothGattCharacteristicWrapper { - final UUID mUuid; final int mInstanceId; + final int mProperties; + final UUID mUuid; - public FakeBluetoothGattCharacteristic(UUID uuid, int instanceId) { + public FakeBluetoothGattCharacteristic(int instanceId, int properties, UUID uuid) { super(null); - mUuid = uuid; mInstanceId = instanceId; + mProperties = properties; + mUuid = uuid; } @Override @@ -372,6 +374,11 @@ class Fakes { } @Override + public int getProperties() { + return mProperties; + } + + @Override public UUID getUuid() { return mUuid; } diff --git a/device/bluetooth/test/bluetooth_test.h b/device/bluetooth/test/bluetooth_test.h index fa946a3..4b84e75 100644 --- a/device/bluetooth/test/bluetooth_test.h +++ b/device/bluetooth/test/bluetooth_test.h @@ -94,8 +94,10 @@ class BluetoothTestBase : public testing::Test { // Simulates failure to discover services. virtual void SimulateGattServicesDiscoveryError(BluetoothDevice* device) {} + // Simulates a Characteristic on a service. virtual void SimulateGattCharacteristic(BluetoothGattService* service, - const std::string& uuid){}; + const std::string& uuid, + int properties) {} // Remove the device from the adapter and delete it. virtual void DeleteDevice(BluetoothDevice* device); diff --git a/device/bluetooth/test/bluetooth_test_android.cc b/device/bluetooth/test/bluetooth_test_android.cc index 7761f56..5610722 100644 --- a/device/bluetooth/test/bluetooth_test_android.cc +++ b/device/bluetooth/test/bluetooth_test_android.cc @@ -143,14 +143,15 @@ void BluetoothTestAndroid::SimulateGattServicesDiscoveryError( void BluetoothTestAndroid::SimulateGattCharacteristic( BluetoothGattService* service, - const std::string& uuid) { + const std::string& uuid, + int properties) { BluetoothRemoteGattServiceAndroid* service_android = static_cast<BluetoothRemoteGattServiceAndroid*>(service); JNIEnv* env = base::android::AttachCurrentThread(); Java_FakeBluetoothGattService_addCharacteristic( env, service_android->GetJavaObject().obj(), - base::android::ConvertUTF8ToJavaString(env, uuid).obj()); + base::android::ConvertUTF8ToJavaString(env, uuid).obj(), properties); } void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled( diff --git a/device/bluetooth/test/bluetooth_test_android.h b/device/bluetooth/test/bluetooth_test_android.h index beb5e2b..99b807d87 100644 --- a/device/bluetooth/test/bluetooth_test_android.h +++ b/device/bluetooth/test/bluetooth_test_android.h @@ -36,7 +36,8 @@ class BluetoothTestAndroid : public BluetoothTestBase { const std::vector<std::string>& uuids) override; void SimulateGattServicesDiscoveryError(BluetoothDevice* device) override; void SimulateGattCharacteristic(BluetoothGattService* service, - const std::string& uuid) override; + const std::string& uuid, + int properties) override; // Records that Java FakeBluetoothDevice connectGatt was called. void OnFakeBluetoothDeviceConnectGattCalled(JNIEnv* env, jobject caller); |