Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Unified Diff: device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java

Issue 1712593002: bluetooth: android: Confirm the notify session after the descriptor has been written. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Vincent's comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
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 538f618d6aa7efeadd0f9e9cea26a499a4920c99..b13488a516e1ab75a187bbfad8a77b6a330246bc 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
@@ -354,6 +354,7 @@ class Fakes {
boolean mReadCharacteristicWillFailSynchronouslyOnce = false;
boolean mSetCharacteristicNotificationWillFailSynchronouslyOnce = false;
boolean mWriteCharacteristicWillFailSynchronouslyOnce = false;
+ boolean mReadDescriptorWillFailSynchronouslyOnce = false;
boolean mWriteDescriptorWillFailSynchronouslyOnce = false;
public FakeBluetoothGatt(FakeBluetoothDevice device) {
@@ -417,6 +418,16 @@ class Fakes {
}
@Override
+ boolean readDescriptor(Wrappers.BluetoothGattDescriptorWrapper descriptor) {
+ if (mReadDescriptorWillFailSynchronouslyOnce) {
+ mReadDescriptorWillFailSynchronouslyOnce = false;
+ return false;
+ }
+ nativeOnFakeBluetoothGattReadDescriptor(mDevice.mAdapter.mNativeBluetoothTestAndroid);
+ return true;
+ }
+
+ @Override
boolean writeDescriptor(Wrappers.BluetoothGattDescriptorWrapper descriptor) {
if (mWriteDescriptorWillFailSynchronouslyOnce) {
mWriteDescriptorWillFailSynchronouslyOnce = false;
@@ -672,15 +683,65 @@ class Fakes {
final FakeBluetoothGattCharacteristic mCharacteristic;
final UUID mUuid;
byte[] mValue;
+ static FakeBluetoothGattDescriptor sRememberedDescriptor;
public FakeBluetoothGattDescriptor(
FakeBluetoothGattCharacteristic characteristic, UUID uuid) {
- super(null);
+ super(null, null);
mCharacteristic = characteristic;
mUuid = uuid;
mValue = new byte[0];
}
+ // Implements BluetoothTestAndroid::RememberDescriptorForSubsequentAction.
+ @CalledByNative("FakeBluetoothGattDescriptor")
+ private static void rememberDescriptorForSubsequentAction(
+ ChromeBluetoothRemoteGattDescriptor chromeDescriptor) {
+ sRememberedDescriptor = (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
+ }
+
+ // Simulate a value being read from a descriptor.
+ @CalledByNative("FakeBluetoothGattDescriptor")
+ private static void valueRead(
+ ChromeBluetoothRemoteGattDescriptor chromeDescriptor, int status, byte[] value) {
+ if (chromeDescriptor == null && sRememberedDescriptor == null)
+ throw new IllegalArgumentException("rememberDescriptor wasn't called previously.");
+
+ FakeBluetoothGattDescriptor fakeDescriptor = (chromeDescriptor == null)
+ ? sRememberedDescriptor
+ : (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
+
+ fakeDescriptor.mValue = value;
+ fakeDescriptor.mCharacteristic.mService.mDevice.mGattCallback.onDescriptorRead(
+ fakeDescriptor, status);
+ }
+
+ // Simulate a value being written to a descriptor.
+ @CalledByNative("FakeBluetoothGattDescriptor")
+ private static void valueWrite(
+ ChromeBluetoothRemoteGattDescriptor chromeDescriptor, int status) {
+ if (chromeDescriptor == null && sRememberedDescriptor == null)
+ throw new IllegalArgumentException("rememberDescriptor wasn't called previously.");
+
+ FakeBluetoothGattDescriptor fakeDescriptor = (chromeDescriptor == null)
+ ? sRememberedDescriptor
+ : (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
+
+ fakeDescriptor.mCharacteristic.mService.mDevice.mGattCallback.onDescriptorWrite(
+ fakeDescriptor, status);
+ }
+
+ // Cause subsequent value read of a descriptor to fail synchronously.
+ @CalledByNative("FakeBluetoothGattDescriptor")
+ private static void setReadDescriptorWillFailSynchronouslyOnce(
+ ChromeBluetoothRemoteGattDescriptor chromeDescriptor) {
+ FakeBluetoothGattDescriptor fakeDescriptor =
+ (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
+
+ fakeDescriptor.mCharacteristic.mService.mDevice.mGatt
+ .mReadDescriptorWillFailSynchronouslyOnce = true;
+ }
+
// Cause subsequent value write of a descriptor to fail synchronously.
@CalledByNative("FakeBluetoothGattDescriptor")
private static void setWriteDescriptorWillFailSynchronouslyOnce(
@@ -696,6 +757,11 @@ class Fakes {
// Wrappers.BluetoothGattDescriptorWrapper overrides:
@Override
+ public Wrappers.BluetoothGattCharacteristicWrapper getCharacteristic() {
+ return mCharacteristic;
+ }
+
+ @Override
public UUID getUuid() {
return mUuid;
}
@@ -741,6 +807,10 @@ class Fakes {
private static native void nativeOnFakeBluetoothGattWriteCharacteristic(
long nativeBluetoothTestAndroid, byte[] value);
+ // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor.
+ private static native void nativeOnFakeBluetoothGattReadDescriptor(
+ long nativeBluetoothTestAndroid);
+
// Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor.
private static native void nativeOnFakeBluetoothGattWriteDescriptor(
long nativeBluetoothTestAndroid, byte[] value);

Powered by Google App Engine
This is Rietveld 408576698