From 2371f8fd69947d57e620bae5cb947c0a3696ba18 Mon Sep 17 00:00:00 2001 From: wabicai Date: Tue, 8 Sep 2026 21:03:59 +0900 Subject: [PATCH] fix: report Android bond failure reasons in 0.1.7 --- .../src/main/java/so/onekey/lib/ble/utils/BleUtilsModule.kt | 5 +++++ package.json | 2 +- src/type.ts | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/so/onekey/lib/ble/utils/BleUtilsModule.kt b/android/src/main/java/so/onekey/lib/ble/utils/BleUtilsModule.kt index bbf63f9..598d9d8 100644 --- a/android/src/main/java/so/onekey/lib/ble/utils/BleUtilsModule.kt +++ b/android/src/main/java/so/onekey/lib/ble/utils/BleUtilsModule.kt @@ -262,6 +262,11 @@ class BleUtilsModule(private val reactContext: ReactApplicationContext) : val bond = Arguments.createMap() bond.putString("state", bondStateStr) bond.putString("preState", prevBondStateStr) + // EXTRA_UNBOND_REASON is not exposed by the public Android SDK. + val reasonExtra = "android.bluetooth.device.extra.REASON" + if (bondState == BluetoothDevice.BOND_NONE && intent.hasExtra(reasonExtra)) { + bond.putInt("reason", intent.getIntExtra(reasonExtra, BluetoothDevice.ERROR)) + } val peripheral = Peripheral(device!!) val map = peripheral.asWritableMap() diff --git a/package.json b/package.json index e037dc9..012eda9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/react-native-ble-utils", - "version": "0.1.6", + "version": "0.1.7", "description": "ble uilts", "source": "./src/index.tsx", "main": "./dist/commonjs/index.js", diff --git a/src/type.ts b/src/type.ts index 1f6d920..5ee4faa 100644 --- a/src/type.ts +++ b/src/type.ts @@ -39,6 +39,8 @@ export interface Peripheral { export interface BondState { state: string; preState: string; + /** Android EXTRA_UNBOND_REASON, when supplied by the system. */ + reason?: number; } export interface AdvertisingData {