Closed philips77 closed 11 months ago
Btw, the same error is returned when the BluetoothGattCharacteristic
or BluetoothGattDescriptor
instances are null, or they don't have required property (e.g no READ property when trying to read).
We have seen this crash in the field on several phone models (see below) running Android 13 as well, but crashlytics shows it happening when registering for notifications only, not the read/write operations. Would this improvement fix that as well? Here is the stacktrace of such an occurrence:
Fatal Exception: java.lang.SecurityException: Need BLUETOOTH PRIVILEGED permission: Neither user 10258 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
at android.app.ContextImpl.enforce(ContextImpl.java:2240)
at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:2268)
at android.content.ContextWrapper.enforceCallingOrSelfPermission(ContextWrapper.java:948)
at com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission(Utils.java:411)
at com.android.bluetooth.gatt.GattService.permissionCheck(GattService.java:480)
at com.android.bluetooth.gatt.GattService.registerForNotification(GattService.java:3807)
at com.android.bluetooth.gatt.GattService$BluetoothGattBinder.registerForNotification(GattService.java:1091)
at com.android.bluetooth.gatt.GattService$BluetoothGattBinder.registerForNotification(GattService.java:1079)
at android.bluetooth.IBluetoothGatt$Stub.onTransact(IBluetoothGatt.java:812)
at android.os.Binder.execTransactInternal(Binder.java:1285)
at android.os.Binder.execTransact(Binder.java:1244)
Device distribution:
@philips77 My problem is the same as @j0bro 's. Can you solve it?
@philips77 Can you please catch the same exception on the call of the gatt.setCharacteristicNotification
? It is called into internalEnableIndications
, internalDisableNotifications
, internalEnableNotifications
functions.
This PR fixes #507.
Reading or writing characteristics or descriptors with some restricted UUIDs may throw
SecurityExeception
. This PR adds a try-catch block. The error returned to the user isFailCallback.REASON_NULL_ATTRIBUTE
.