Skip to content

Commit 1366544

Browse files
swan-amazonpull[bot]
authored andcommitted
[Android] Fallback to BLE Notification when Indication unsupported (#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.
1 parent 5a95eb4 commit 1366544

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/platform/android/java/chip/platform/AndroidBleManager.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ public void onDescriptorWrite(
157157
if (desc.getValue() == BluetoothGattDescriptor.ENABLE_INDICATION_VALUE) {
158158
mPlatform.handleSubscribeComplete(
159159
connId, svcIdBytes, charIdBytes, status == BluetoothGatt.GATT_SUCCESS);
160+
} else if (desc.getValue() == BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) {
161+
mPlatform.handleSubscribeComplete(
162+
connId, svcIdBytes, charIdBytes, status == BluetoothGatt.GATT_SUCCESS);
160163
} else if (desc.getValue() == BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE) {
161164
mPlatform.handleUnsubscribeComplete(
162165
connId, svcIdBytes, charIdBytes, status == BluetoothGatt.GATT_SUCCESS);
@@ -283,10 +286,18 @@ public boolean onSubscribeCharacteristic(int connId, byte[] svcId, byte[] charId
283286

284287
BluetoothGattDescriptor descriptor =
285288
subscribeChar.getDescriptor(UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG));
286-
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
287-
if (!bluetoothGatt.writeDescriptor(descriptor)) {
288-
Log.e(TAG, "writeDescriptor failed");
289-
return false;
289+
if ((subscribeChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) {
290+
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
291+
if (!bluetoothGatt.writeDescriptor(descriptor)) {
292+
Log.e(TAG, "writeDescriptor failed");
293+
return false;
294+
}
295+
} else if ((subscribeChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) {
296+
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
297+
if (!bluetoothGatt.writeDescriptor(descriptor)) {
298+
Log.e(TAG, "writeDescriptor failed");
299+
return false;
300+
}
290301
}
291302
return true;
292303
}

0 commit comments

Comments
 (0)