react-native-ble-manager icon indicating copy to clipboard operation
react-native-ble-manager copied to clipboard

Android 10 - startNotification gives error "Error writing descriptor stats=133"

Open viktorbk opened this issue 4 years ago • 7 comments

Version

  • react-native-ble-manager v7.4.1
  • react-native v0.63.4
  • iOS/Android v.10 kernel 4.19.95

Expected behaviour

startNotification should start notification on characteristic

Actual behaviour

Gives error: Error writing descriptor stats=133

Code to reproduce

AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

App.js

  const connect = async device => {
    await BleManager.connect(device.id)
    console.log('Connected......')
    const info = await BleManager.retrieveServices(device.id)
    console.log('Got service...', info)
    const characteristic = info.characteristics[3]
    const service = characteristic.service
    const charect = characteristic.characteristic
    console.log(service, charect)
    setTimeout(async () => {
      await BleManager.startNotification(device.id, service, charect)
      debugger
      await BleManager.disconnect(device.id)
      console.log('Disonnected......')
    }, 500)
  }

Stack trace and console log

{advertising: {…}, rssi: -56, id: "04:91:62:93:03:59", name: "MyDevice"}
App.js:65 Connected......
App.js:67 Got service... {characteristics: Array(4), services: Array(3), advertising: {…}, name: "MyDevice", rssi: -56, …}
App.js:71 11020304-0506-0708-0900-0a0b0c0d0e0f 11223344-5566-7788-9900-aabbccddeeff
backend.js:32 Possible Unhandled Promise Rejection (id: 0):
"Error writing descriptor stats=133"
...

Could it be the new UBSan (Bounds Sanitizer) in Android 10? https://source.android.com/devices/tech/debug/bounds-sanitizer

signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: 'ubsan: out-of-bounds'

It here in Peripheral.java where it fails: (line 501)

if (gatt.writeDescriptor(descriptor)) {
    Log.d(BleManager.LOG_TAG, "setNotify complete");
} else {
    registerNotifyCallback = null;
    callback.invoke(
        "Failed to set client characteristic notification for " + characteristicUUID);
}

viktorbk avatar Dec 11 '20 10:12 viktorbk

Hi, I don't have an android 10 phone so i can't reproduce your issue.

marcosinigaglia avatar Dec 16 '20 11:12 marcosinigaglia

Hi, if you buy Nokia 5.3 with Android 10 as I did i will pay for the phone. There are already customers complaining since our app is in Google Play store and important functionality for our company.

viktorbk avatar Dec 16 '20 12:12 viktorbk

i got same issue

zorba0517 avatar Jun 10 '21 07:06 zorba0517

It's a OS/Hardware bug.

marcosinigaglia avatar Jun 10 '21 15:06 marcosinigaglia

Did anybody find a workaround for this?

atornatore avatar Jun 17 '21 16:06 atornatore

I have this same problem, on a Samsung note 10 Android 11 (Kernel 4.14) But works fine on Android 11 (Kernel 4.9) Galaxy Tab S5e

Any update on this issue?

jimhuf avatar Jul 27 '21 14:07 jimhuf

I had the same issue with the phone OPPO A53 (ColorOS 7.2 based on Android 10). After struggling on it for several days, I found out that I need to create a bond first and then it works (I never had to do that with any other Android phones).

After catching the error stats=133, the following seems to work:

  1. Wait until the device is truly disconnected (about 10 sec),
  2. Call the function BleManager.createBond(peripheral.id),
  3. Accept the pairing pop-up that shows up on the screen,
  4. Wait until the device is truly disconnected (about 25 sec),
  5. Start again with BleManager.connect, BleManager.retrieveServices, BleManager.startNotification

This needs to be done only once. The next connections are working as usual, since the two devices are bonded.

I hope it helps someone...

DomLeMarin avatar Aug 30 '21 18:08 DomLeMarin

the error rarely occured. I saw it once.

2sem avatar Sep 05 '23 05:09 2sem