| 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..2363b7f34292a702042a74dde2d4826633a6f433 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;
|
| @@ -533,6 +544,26 @@ class Fakes {
|
| (FakeBluetoothGattCharacteristic) chromeCharacteristic.mCharacteristic;
|
| }
|
|
|
| + // Simulate a notifySessionStarted descriptor write callback
|
| + @CalledByNative("FakeBluetoothGattCharacteristic")
|
| + private static void notifySessionStarted(
|
| + ChromeBluetoothRemoteGattCharacteristic chromeCharacteristic, int status) {
|
| + if (chromeCharacteristic == null && sRememberedCharacteristic == null)
|
| + throw new IllegalArgumentException(
|
| + "rememberCharacteristic wasn't called previously.");
|
| +
|
| + FakeBluetoothGattCharacteristic fakeCharacteristic = (chromeCharacteristic == null)
|
| + ? sRememberedCharacteristic
|
| + : (FakeBluetoothGattCharacteristic) chromeCharacteristic.mCharacteristic;
|
| +
|
| + FakeBluetoothGattDescriptor fakeClientCharacteristicConfigurationDescriptor =
|
| + new FakeBluetoothGattDescriptor(fakeCharacteristic,
|
| + UUID.fromString("00002902-0000-1000-8000-00805F9B34FB"));
|
| +
|
| + fakeCharacteristic.mService.mDevice.mGattCallback.onDescriptorWrite(
|
| + fakeClientCharacteristicConfigurationDescriptor, status);
|
| + }
|
| +
|
| // Simulate a value being read from a characteristic.
|
| @CalledByNative("FakeBluetoothGattCharacteristic")
|
| private static void valueRead(ChromeBluetoothRemoteGattCharacteristic chromeCharacteristic,
|
| @@ -672,15 +703,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 +777,11 @@ class Fakes {
|
| // Wrappers.BluetoothGattDescriptorWrapper overrides:
|
|
|
| @Override
|
| + public Wrappers.BluetoothGattCharacteristicWrapper getCharacteristic() {
|
| + return mCharacteristic;
|
| + }
|
| +
|
| + @Override
|
| public UUID getUuid() {
|
| return mUuid;
|
| }
|
| @@ -741,6 +827,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);
|
|
|