diff options
6 files changed, 90 insertions, 2 deletions
diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java index ea78782..d53e233 100644 --- a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java +++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java @@ -330,6 +330,10 @@ class Wrappers { boolean writeCharacteristic(BluetoothGattCharacteristicWrapper characteristic) { return mGatt.writeCharacteristic(characteristic.mCharacteristic); } + + boolean writeDescriptor(BluetoothGattDescriptorWrapper descriptor) { + return mGatt.writeDescriptor(descriptor.mDescriptor); + } } /** @@ -499,5 +503,13 @@ class Wrappers { public UUID getUuid() { return mDescriptor.getUuid(); } + + public byte[] getValue() { + return mDescriptor.getValue(); + } + + public boolean setValue(byte[] value) { + return mDescriptor.setValue(value); + } } } 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); } diff --git a/device/bluetooth/test/bluetooth_test.cc b/device/bluetooth/test/bluetooth_test.cc index 0c4e891..5feec01 100644 --- a/device/bluetooth/test/bluetooth_test.cc +++ b/device/bluetooth/test/bluetooth_test.cc @@ -231,6 +231,7 @@ void BluetoothTestBase::ResetEventCounts() { gatt_notify_characteristic_attempts_ = 0; gatt_read_characteristic_attempts_ = 0; gatt_write_characteristic_attempts_ = 0; + gatt_write_descriptor_attempts_ = 0; } } // namespace device diff --git a/device/bluetooth/test/bluetooth_test.h b/device/bluetooth/test/bluetooth_test.h index c0b5092..8f0bd31 100644 --- a/device/bluetooth/test/bluetooth_test.h +++ b/device/bluetooth/test/bluetooth_test.h @@ -176,6 +176,11 @@ class BluetoothTestBase : public testing::Test { BluetoothGattCharacteristic* characteristic, const std::string& uuid) {} + // Simulates a Descriptor Write operation failing synchronously once for + // an unknown reason. + virtual void SimulateGattDescriptorWriteWillFailSynchronouslyOnce( + BluetoothGattDescriptor* descriptor) {} + // Removes the device from the adapter and deletes it. virtual void DeleteDevice(BluetoothDevice* device); @@ -232,6 +237,7 @@ class BluetoothTestBase : public testing::Test { int gatt_notify_characteristic_attempts_ = 0; int gatt_read_characteristic_attempts_ = 0; int gatt_write_characteristic_attempts_ = 0; + int gatt_write_descriptor_attempts_ = 0; // The following values are used to make sure the correct callbacks // have been called. They are not reset when calling ResetEventCounts(). diff --git a/device/bluetooth/test/bluetooth_test_android.cc b/device/bluetooth/test/bluetooth_test_android.cc index eb48b0b..3ae446f 100644 --- a/device/bluetooth/test/bluetooth_test_android.cc +++ b/device/bluetooth/test/bluetooth_test_android.cc @@ -299,6 +299,15 @@ void BluetoothTestAndroid::SimulateGattDescriptor( base::android::ConvertUTF8ToJavaString(env, uuid).obj()); } +void BluetoothTestAndroid::SimulateGattDescriptorWriteWillFailSynchronouslyOnce( + BluetoothGattDescriptor* descriptor) { + BluetoothRemoteGattDescriptorAndroid* descriptor_android = + static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); + Java_FakeBluetoothGattDescriptor_setWriteDescriptorWillFailSynchronouslyOnce( + base::android::AttachCurrentThread(), + descriptor_android->GetJavaObject().obj()); +} + void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled( JNIEnv* env, const JavaParamRef<jobject>& caller) { @@ -337,4 +346,12 @@ void BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic( base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); } +void BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor( + JNIEnv* env, + const JavaParamRef<jobject>& caller, + const JavaParamRef<jbyteArray>& value) { + gatt_write_descriptor_attempts_++; + base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); +} + } // namespace device diff --git a/device/bluetooth/test/bluetooth_test_android.h b/device/bluetooth/test/bluetooth_test_android.h index 290faa6..be11c4c 100644 --- a/device/bluetooth/test/bluetooth_test_android.h +++ b/device/bluetooth/test/bluetooth_test_android.h @@ -64,6 +64,8 @@ class BluetoothTestAndroid : public BluetoothTestBase { BluetoothGattCharacteristic* characteristic) override; void SimulateGattDescriptor(BluetoothGattCharacteristic* characteristic, const std::string& uuid) override; + void SimulateGattDescriptorWriteWillFailSynchronouslyOnce( + BluetoothGattDescriptor* descriptor) override; // Records that Java FakeBluetoothDevice connectGatt was called. void OnFakeBluetoothDeviceConnectGattCalled( @@ -97,6 +99,12 @@ class BluetoothTestAndroid : public BluetoothTestBase { const base::android::JavaParamRef<jobject>& caller, const base::android::JavaParamRef<jbyteArray>& value); + // Records that Java FakeBluetoothGatt writeDescriptor was called. + void OnFakeBluetoothGattWriteDescriptor( + JNIEnv* env, + const base::android::JavaParamRef<jobject>& caller, + const base::android::JavaParamRef<jbyteArray>& value); + base::android::ScopedJavaGlobalRef<jobject> j_fake_bluetooth_adapter_; }; |