Skip to content

Commit

Permalink
Merge pull request #545 from NordicSemiconductor/bugfix/privilaged
Browse files Browse the repository at this point in the history
Catching SecurityException from setCharacteristicNotification(...)
  • Loading branch information
philips77 authored Feb 16, 2024
2 parents f924120 + e8adafb commit eb3ae99
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions ble/src/main/java/no/nordicsemi/android/ble/BleManagerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,12 @@ private boolean internalEnableNotifications(@Nullable final BluetoothGattCharact
final BluetoothGattDescriptor descriptor = getCccd(characteristic, BluetoothGattCharacteristic.PROPERTY_NOTIFY);
if (descriptor != null) {
log(Log.DEBUG, () -> "gatt.setCharacteristicNotification(" + characteristic.getUuid() + ", true)");
gatt.setCharacteristicNotification(characteristic, true);
try {
gatt.setCharacteristicNotification(characteristic, true);
} catch (final SecurityException e) {
log(Log.ERROR, e::getLocalizedMessage);
return false;
}

log(Log.VERBOSE, () -> "Enabling notifications for " + characteristic.getUuid());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Expand Down Expand Up @@ -965,7 +970,12 @@ private boolean internalDisableNotifications(@Nullable final BluetoothGattCharac
BluetoothGattCharacteristic.PROPERTY_NOTIFY | BluetoothGattCharacteristic.PROPERTY_INDICATE);
if (descriptor != null) {
log(Log.DEBUG, () -> "gatt.setCharacteristicNotification(" + characteristic.getUuid() + ", false)");
gatt.setCharacteristicNotification(characteristic, false);
try {
gatt.setCharacteristicNotification(characteristic, false);
} catch (final SecurityException e) {
log(Log.ERROR, e::getLocalizedMessage);
return false;
}

log(Log.VERBOSE, () -> "Disabling notifications and indications for " + characteristic.getUuid());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Expand Down Expand Up @@ -994,7 +1004,12 @@ private boolean internalEnableIndications(@Nullable final BluetoothGattCharacter
final BluetoothGattDescriptor descriptor = getCccd(characteristic, BluetoothGattCharacteristic.PROPERTY_INDICATE);
if (descriptor != null) {
log(Log.DEBUG, () -> "gatt.setCharacteristicNotification(" + characteristic.getUuid() + ", true)");
gatt.setCharacteristicNotification(characteristic, true);
try {
gatt.setCharacteristicNotification(characteristic, true);
} catch (final SecurityException e) {
log(Log.ERROR, e::getLocalizedMessage);
return false;
}

log(Log.VERBOSE, () -> "Enabling indications for " + characteristic.getUuid());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Expand Down

0 comments on commit eb3ae99

Please sign in to comment.