Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catching read and write errors #518

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

philips77
Copy link
Member

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 is FailCallback.REASON_NULL_ATTRIBUTE.

@philips77
Copy link
Member Author

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).

@philips77 philips77 merged commit 25b363c into main Sep 25, 2023
1 check passed
@philips77 philips77 deleted the improvement/catching-security-exception branch September 25, 2023 13:42
philips77 added a commit that referenced this pull request Sep 25, 2023
…-security-exception

Catching read and write errors
@j0bro
Copy link

j0bro commented Oct 10, 2023

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:
image

@WYZEHanYu
Copy link

@philips77 My problem is the same as @j0bro 's. Can you solve it?

@ghost
Copy link

ghost commented Nov 24, 2023

@philips77 Can you please catch the same exception on the call of the gatt.setCharacteristicNotification? It is called into internalEnableIndications, internalDisableNotifications, internalEnableNotifications functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need BLUETOOTH PRIVILEGED permission - Android 13
3 participants