Skip to content

Commit 880e8c9

Browse files
committed
Fix https://github.com/pauldemarco/flutter_blue/issues/185 by pauldemarco#797 - bad BLE implementations without CCCD wouldn't DoS flutter_blue hopefully
1 parent 159f6f4 commit 880e8c9

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

android/src/main/java/com/pauldemarco/flutter_blue/FlutterBluePlugin.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,9 @@ public void onMethodCall(MethodCall call, Result result) {
536536
characteristic = locateCharacteristic(gattServer, request.getServiceUuid(), request.getSecondaryServiceUuid(), request.getCharacteristicUuid());
537537
cccDescriptor = characteristic.getDescriptor(CCCD_ID);
538538
if(cccDescriptor == null) {
539-
throw new Exception("could not locate CCCD descriptor for characteristic: " +characteristic.getUuid().toString());
539+
//Some devices - including the widely used Bluno do not actually set the CCCD_ID.
540+
//thus setNotifications works perfectly (tested on Bluno) without cccDescriptor
541+
log(LogLevel.INFO, "could not locate CCCD descriptor for characteristic: " + characteristic.getUuid().toString());
540542
}
541543
} catch(Exception e) {
542544
result.error("set_notification_error", e.getMessage(), null);
@@ -567,14 +569,16 @@ public void onMethodCall(MethodCall call, Result result) {
567569
return;
568570
}
569571

570-
if(!cccDescriptor.setValue(value)) {
571-
result.error("set_notification_error", "error when setting the descriptor value to: " + value, null);
572-
return;
573-
}
572+
if(cccDescriptor != null) {
573+
if (!cccDescriptor.setValue(value)) {
574+
result.error("set_notification_error", "error when setting the descriptor value to: " + value, null);
575+
return;
576+
}
574577

575-
if(!gattServer.writeDescriptor(cccDescriptor)) {
576-
result.error("set_notification_error", "error when writing the descriptor", null);
577-
return;
578+
if (!gattServer.writeDescriptor(cccDescriptor)) {
579+
result.error("set_notification_error", "error when writing the descriptor", null);
580+
return;
581+
}
578582
}
579583

580584
result.success(null);

0 commit comments

Comments
 (0)