diff options
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 | 72 |
1 files changed, 71 insertions, 1 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 46f9c66..f3d98a7 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 @@ -368,6 +368,7 @@ class Fakes { boolean mReadCharacteristicWillFailSynchronouslyOnce = false; boolean mSetCharacteristicNotificationWillFailSynchronouslyOnce = false; boolean mWriteCharacteristicWillFailSynchronouslyOnce = false; + boolean mReadDescriptorWillFailSynchronouslyOnce = false; boolean mWriteDescriptorWillFailSynchronouslyOnce = false; public FakeBluetoothGatt(FakeBluetoothDevice device) { @@ -431,6 +432,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; @@ -686,15 +697,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( @@ -710,6 +771,11 @@ class Fakes { // Wrappers.BluetoothGattDescriptorWrapper overrides: @Override + public Wrappers.BluetoothGattCharacteristicWrapper getCharacteristic() { + return mCharacteristic; + } + + @Override public UUID getUuid() { return mUuid; } @@ -759,6 +825,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); |