diff options
author | scheib <scheib@chromium.org> | 2015-10-15 18:23:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-16 01:23:46 +0000 |
commit | 33aa3f45ab74c7d832cc9f717be85abb7bb53011 (patch) | |
tree | 388c007229b5d2e3677a728aa5721e44627f9115 /device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java | |
parent | d4b788f7c8a5c6523fd0d01a4e7aa64f1e9dd624 (diff) | |
download | chromium_src-33aa3f45ab74c7d832cc9f717be85abb7bb53011.zip chromium_src-33aa3f45ab74c7d832cc9f717be85abb7bb53011.tar.gz chromium_src-33aa3f45ab74c7d832cc9f717be85abb7bb53011.tar.bz2 |
bluetooth: android: BluetoothRemoteGattServiceAndroid::GetUUID
Create a Java class ChromeBluetoothRemoteGattService to
implement BluetoothRemoteGattServiceAndroid, and implement
GetUUID.
Correct mistaken implementation of instanceID. Android's
getInstanceId is only unique for services with the same
UUID, so a device unique instance ID must join the UUID and
Android's getInstanceId.
Add the ability for tests to create services by providing a
vector of UUID strings.
BUG=541400
Review URL: https://codereview.chromium.org/1395783005
Cr-Commit-Position: refs/heads/master@{#354420}
Diffstat (limited to 'device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java')
-rw-r--r-- | device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java | 26 |
1 files changed, 20 insertions, 6 deletions
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 062c3c8..2499c7b 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 @@ -17,7 +17,9 @@ import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.JNINamespace; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.UUID; /** * Fake implementations of android.bluetooth.* classes for testing. @@ -212,15 +214,20 @@ class Fakes { // Create a call to onServicesDiscovered on the |chrome_device| using parameter // |status|. @CalledByNative("FakeBluetoothDevice") - private static void servicesDiscovered(ChromeBluetoothDevice chromeDevice, int status) { + private static void servicesDiscovered( + ChromeBluetoothDevice chromeDevice, int status, String uuidsSpaceDelimited) { FakeBluetoothDevice fakeDevice = (FakeBluetoothDevice) chromeDevice.mDevice; - // TODO(scheib): Add more control over how many services are created and - // their properties. http://crbug.com/541400 if (status == android.bluetooth.BluetoothGatt.GATT_SUCCESS) { fakeDevice.mGatt.mServices.clear(); - fakeDevice.mGatt.mServices.add(new FakeBluetoothGattService(0)); - fakeDevice.mGatt.mServices.add(new FakeBluetoothGattService(1)); + HashMap<String, Integer> uuidsToInstanceIdMap = new HashMap<String, Integer>(); + for (String uuid : uuidsSpaceDelimited.split(" ")) { + Integer previousId = uuidsToInstanceIdMap.get(uuid); + int instanceId = (previousId == null) ? 0 : previousId + 1; + uuidsToInstanceIdMap.put(uuid, instanceId); + fakeDevice.mGatt.mServices.add( + new FakeBluetoothGattService(UUID.fromString(uuid), instanceId)); + } } fakeDevice.mGattCallback.onServicesDiscovered(status); @@ -297,9 +304,11 @@ class Fakes { */ static class FakeBluetoothGattService extends Wrappers.BluetoothGattServiceWrapper { final int mInstanceId; + final UUID mUuid; - public FakeBluetoothGattService(int instanceId) { + public FakeBluetoothGattService(UUID uuid, int instanceId) { super(null); + mUuid = uuid; mInstanceId = instanceId; } @@ -307,6 +316,11 @@ class Fakes { public int getInstanceId() { return mInstanceId; } + + @Override + public UUID getUuid() { + return mUuid; + } } // --------------------------------------------------------------------------------------------- |