Skip to content

Commit

Permalink
[Android] Fallback to BLE Notification when Indication unsupported (#…
Browse files Browse the repository at this point in the history
…25444)

To support devices based on older revisions of the SDK that did not
include the GATT Server Characteristic property change (from
Notification to Indication), the GATT Characteristic properties are
queried to determine if Indication and/or Notification is supported.
When available, Indication is preferred.
  • Loading branch information
swan-amazon authored and pull[bot] committed Nov 22, 2023
1 parent b37b47d commit 5539783
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/platform/android/java/chip/platform/AndroidBleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public void onDescriptorWrite(
if (desc.getValue() == BluetoothGattDescriptor.ENABLE_INDICATION_VALUE) {
mPlatform.handleSubscribeComplete(
connId, svcIdBytes, charIdBytes, status == BluetoothGatt.GATT_SUCCESS);
} else if (desc.getValue() == BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) {
mPlatform.handleSubscribeComplete(
connId, svcIdBytes, charIdBytes, status == BluetoothGatt.GATT_SUCCESS);
} else if (desc.getValue() == BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE) {
mPlatform.handleUnsubscribeComplete(
connId, svcIdBytes, charIdBytes, status == BluetoothGatt.GATT_SUCCESS);
Expand Down Expand Up @@ -283,10 +286,18 @@ public boolean onSubscribeCharacteristic(int connId, byte[] svcId, byte[] charId

BluetoothGattDescriptor descriptor =
subscribeChar.getDescriptor(UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
if (!bluetoothGatt.writeDescriptor(descriptor)) {
Log.e(TAG, "writeDescriptor failed");
return false;
if ((subscribeChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) {
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
if (!bluetoothGatt.writeDescriptor(descriptor)) {
Log.e(TAG, "writeDescriptor failed");
return false;
}
} else if ((subscribeChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) {
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
if (!bluetoothGatt.writeDescriptor(descriptor)) {
Log.e(TAG, "writeDescriptor failed");
return false;
}
}
return true;
}
Expand Down

0 comments on commit 5539783

Please sign in to comment.