summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
diff options
context:
space:
mode:
authorscheib <scheib@chromium.org>2016-01-12 19:52:18 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-13 03:53:34 +0000
commit98cb300cb67c773598bd01184b0ffce8537004b1 (patch)
treec8ce92c10196fb388d4be8c614945b5ad3591034 /device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
parent22db67376d036a11c6e62cab341b7bf7d6ba84e5 (diff)
downloadchromium_src-98cb300cb67c773598bd01184b0ffce8537004b1.zip
chromium_src-98cb300cb67c773598bd01184b0ffce8537004b1.tar.gz
chromium_src-98cb300cb67c773598bd01184b0ffce8537004b1.tar.bz2
bluetooth: android: Implement Descriptor Write as needed for notifications.
Implements the ability to write to descriptor values in preparation for [following patch] that will use descriptors for enabling notifications. Testing is deferred to [following patch], as this code isn't exposed to public API until that patch. [following patch] https://codereview.chromium.org/1502833002/ BUG=566533 Review URL: https://codereview.chromium.org/1577623002 Cr-Commit-Position: refs/heads/master@{#369105}
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.java48
1 files changed, 46 insertions, 2 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 f9656e9..56c950e 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
@@ -306,6 +306,7 @@ class Fakes {
boolean mReadCharacteristicWillFailSynchronouslyOnce = false;
boolean mSetCharacteristicNotificationWillFailSynchronouslyOnce = false;
boolean mWriteCharacteristicWillFailSynchronouslyOnce = false;
+ boolean mWriteDescriptorWillFailSynchronouslyOnce = false;
public FakeBluetoothGatt(FakeBluetoothDevice device) {
super(null, null);
@@ -361,6 +362,17 @@ class Fakes {
mDevice.mAdapter.mNativeBluetoothTestAndroid, characteristic.getValue());
return true;
}
+
+ @Override
+ boolean writeDescriptor(Wrappers.BluetoothGattDescriptorWrapper descriptor) {
+ if (mWriteDescriptorWillFailSynchronouslyOnce) {
+ mWriteDescriptorWillFailSynchronouslyOnce = false;
+ return false;
+ }
+ nativeOnFakeBluetoothGattWriteDescriptor(
+ mDevice.mAdapter.mNativeBluetoothTestAndroid, descriptor.getValue());
+ return true;
+ }
}
/**
@@ -533,7 +545,8 @@ class Fakes {
+ uuidString + "' that has already been added to this characteristic.");
}
}
- fakeCharacteristic.mDescriptors.add(new FakeBluetoothGattDescriptor(uuid));
+ fakeCharacteristic.mDescriptors.add(
+ new FakeBluetoothGattDescriptor(fakeCharacteristic, uuid));
}
// -----------------------------------------------------------------------------------------
@@ -575,11 +588,27 @@ class Fakes {
* Fakes android.bluetooth.BluetoothGattDescriptor.
*/
static class FakeBluetoothGattDescriptor extends Wrappers.BluetoothGattDescriptorWrapper {
+ final FakeBluetoothGattCharacteristic mCharacteristic;
final UUID mUuid;
+ byte[] mValue;
- public FakeBluetoothGattDescriptor(UUID uuid) {
+ public FakeBluetoothGattDescriptor(
+ FakeBluetoothGattCharacteristic characteristic, UUID uuid) {
super(null);
+ mCharacteristic = characteristic;
mUuid = uuid;
+ mValue = new byte[0];
+ }
+
+ // Cause subsequent value write of a descriptor to fail synchronously.
+ @CalledByNative("FakeBluetoothGattDescriptor")
+ private static void setWriteDescriptorWillFailSynchronouslyOnce(
+ ChromeBluetoothRemoteGattDescriptor chromeDescriptor) {
+ FakeBluetoothGattDescriptor fakeDescriptor =
+ (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
+
+ fakeDescriptor.mCharacteristic.mService.mDevice.mGatt
+ .mWriteDescriptorWillFailSynchronouslyOnce = true;
}
// -----------------------------------------------------------------------------------------
@@ -589,6 +618,17 @@ class Fakes {
public UUID getUuid() {
return mUuid;
}
+
+ @Override
+ public byte[] getValue() {
+ return mValue;
+ }
+
+ @Override
+ public boolean setValue(byte[] value) {
+ mValue = value;
+ return true;
+ }
}
// ---------------------------------------------------------------------------------------------
@@ -616,4 +656,8 @@ class Fakes {
// Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic.
private static native void nativeOnFakeBluetoothGattWriteCharacteristic(
long nativeBluetoothTestAndroid, byte[] value);
+
+ // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor.
+ private static native void nativeOnFakeBluetoothGattWriteDescriptor(
+ long nativeBluetoothTestAndroid, byte[] value);
}