@onekeyfe/react-native-ble-utils 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,10 @@ class BleUtilsModule(private val reactContext: ReactApplicationContext) :
29
29
 
30
30
  override fun getName() = NAME
31
31
 
32
+ // Lets JS skip waiting for an event this OS version never broadcasts.
33
+ override fun getConstants(): MutableMap<String, Any> =
34
+ hashMapOf("supportsKeyMissingEvent" to supportsKeyMissingEvent())
35
+
32
36
  private fun getBluetoothManager(): BluetoothManager? {
33
37
  if (bluetoothManager == null) {
34
38
  bluetoothManager =
@@ -53,6 +57,9 @@ class BleUtilsModule(private val reactContext: ReactApplicationContext) :
53
57
 
54
58
  val filter = IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)
55
59
  filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED)
60
+ if (supportsKeyMissingEvent()) {
61
+ filter.addAction(ACTION_KEY_MISSING)
62
+ }
56
63
  val intentFilter = IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST)
57
64
  intentFilter.priority = IntentFilter.SYSTEM_HIGH_PRIORITY
58
65
  if (Build.VERSION.SDK_INT >= 34) {
@@ -78,6 +85,12 @@ class BleUtilsModule(private val reactContext: ReactApplicationContext) :
78
85
  .emit("onDeviceBondState", params)
79
86
  }
80
87
 
88
+ fun emitOnDeviceKeyMissing(params: WritableMap) {
89
+ reactContext
90
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
91
+ .emit("onDeviceKeyMissing", params)
92
+ }
93
+
81
94
  // 事件监听管理
82
95
  @ReactMethod
83
96
  fun addListener(eventName: String) {
@@ -138,6 +151,9 @@ class BleUtilsModule(private val reactContext: ReactApplicationContext) :
138
151
 
139
152
  var bonded = false
140
153
  var bonding = false
154
+ // False while bonding means the system (or another app) started it, e.g. the
155
+ // re-pairing Android runs by itself after it detects a lost bond.
156
+ var initiated = false
141
157
 
142
158
  when (device.bondState) {
143
159
  BluetoothDevice.BOND_BONDED -> {
@@ -154,12 +170,14 @@ class BleUtilsModule(private val reactContext: ReactApplicationContext) :
154
170
  val started = device.createBond()
155
171
  bonded = false
156
172
  bonding = started
173
+ initiated = started
157
174
  }
158
175
  }
159
176
 
160
177
  val map: WritableMap = Arguments.createMap()
161
178
  map.putBoolean("bonded", bonded)
162
179
  map.putBoolean("bonding", bonding)
180
+ map.putBoolean("initiated", initiated)
163
181
  callback.invoke(null, map)
164
182
  } catch (e: Exception) {
165
183
  Log.e(LOG_TAG, "pairDevice error: ${e.message}")
@@ -262,12 +280,31 @@ class BleUtilsModule(private val reactContext: ReactApplicationContext) :
262
280
  val bond = Arguments.createMap()
263
281
  bond.putString("state", bondStateStr)
264
282
  bond.putString("preState", prevBondStateStr)
283
+ // EXTRA_UNBOND_REASON is not exposed by the public Android SDK.
284
+ val reasonExtra = "android.bluetooth.device.extra.REASON"
285
+ if (bondState == BluetoothDevice.BOND_NONE && intent.hasExtra(reasonExtra)) {
286
+ bond.putInt("reason", intent.getIntExtra(reasonExtra, BluetoothDevice.ERROR))
287
+ }
265
288
 
266
289
  val peripheral = Peripheral(device!!)
267
290
  val map = peripheral.asWritableMap()
268
291
  map.putMap("bondState", bond)
269
292
  Log.d(LOG_TAG, "onReceive BluetoothDevice BondState Change ${map}")
270
293
  module.emitOnDeviceBondState(map)
294
+ } else if (action == ACTION_KEY_MISSING) {
295
+ val device: BluetoothDevice? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
296
+ intent.getParcelableExtra(
297
+ BluetoothDevice.EXTRA_DEVICE, BluetoothDevice::class.java
298
+ )
299
+ } else {
300
+ intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)
301
+ }
302
+ if (device == null) return
303
+
304
+ val map = Arguments.createMap()
305
+ map.putString("id", device.address)
306
+ Log.d(LOG_TAG, "onReceive BluetoothDevice KeyMissing")
307
+ module.emitOnDeviceKeyMissing(map)
271
308
  }
272
309
  }
273
310
  }
@@ -275,5 +312,12 @@ class BleUtilsModule(private val reactContext: ReactApplicationContext) :
275
312
  companion object {
276
313
  const val NAME = "BleUtilsModule"
277
314
  const val LOG_TAG: String = "RNBleUtils"
315
+
316
+ // BluetoothDevice.ACTION_KEY_MISSING is public from API 36. The literal keeps this
317
+ // module building against older compileSdk versions.
318
+ const val ACTION_KEY_MISSING = "android.bluetooth.device.action.KEY_MISSING"
319
+ private const val KEY_MISSING_MIN_SDK = 36
320
+
321
+ fun supportsKeyMissingEvent(): Boolean = Build.VERSION.SDK_INT >= KEY_MISSING_MIN_SDK
278
322
  }
279
323
  }
@@ -8,6 +8,13 @@ var _reactNative = require("react-native");
8
8
  const {
9
9
  BleUtilsModule
10
10
  } = _reactNative.NativeModules;
11
+ const readSupportsKeyMissingEvent = () => {
12
+ if (_reactNative.Platform.OS !== 'android' || !BleUtilsModule) return false;
13
+ // Interop exposes legacy constants through getConstants(); the bridge exposes them
14
+ // as plain properties.
15
+ const constants = typeof BleUtilsModule.getConstants === 'function' ? BleUtilsModule.getConstants() : BleUtilsModule;
16
+ return constants?.supportsKeyMissingEvent === true;
17
+ };
11
18
  class BleUtils {
12
19
  UiEventEmitter = null;
13
20
  constructor() {
@@ -105,6 +112,30 @@ class BleUtils {
105
112
  this.UiEventEmitter?.removeAllListeners('onDeviceBondState');
106
113
  };
107
114
  }
115
+
116
+ /**
117
+ * [Android only]
118
+ * Whether this OS version and native build report `onDeviceKeyMissing`. When false
119
+ * the event never fires, so callers should not wait for it.
120
+ */
121
+ supportsDeviceKeyMissing() {
122
+ return readSupportsKeyMissingEvent();
123
+ }
124
+
125
+ /**
126
+ * [Android 16+ only]
127
+ * A bonded device could not provide its keys when the link was encrypted: the device
128
+ * was wiped or removed the bond. Android keeps its side of the bond, so the device
129
+ * stays unusable until the user forgets it in system Bluetooth settings.
130
+ * Each subscription is removed on its own, so several callers can listen at once.
131
+ * @param callback
132
+ */
133
+ onDeviceKeyMissing(callback) {
134
+ const subscription = this.UiEventEmitter?.addListener('onDeviceKeyMissing', callback);
135
+ return () => {
136
+ subscription?.remove();
137
+ };
138
+ }
108
139
  }
109
140
  var _default = exports.default = new BleUtils();
110
141
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","BleUtilsModule","NativeModules","BleUtils","UiEventEmitter","constructor","Platform","OS","NativeEventEmitter","checkState","Promise","fulfill","_","state","pairDevice","macAddress","resolve","bonded","bonding","reject","error","result","getConnectedPeripherals","serviceUUIDs","getBondedPeripherals","onDeviceBondState","callback","addListener","removeAllListeners","_default","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGA,MAAM;EAAEC;AAAe,CAAC,GAAGC,0BAAa;AAMxC,MAAMC,QAAQ,CAAC;EACbC,cAAc,GAA8B,IAAI;EAEhDC,WAAWA,CAAA,EAAG;IACZ,IAAIC,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACH,cAAc,GAAG,IAAII,+BAAkB,CAACP,cAAc,CAAC;EAC9D;EAEAQ,UAAUA,CAAA,EAAG;IACX,OAAO,IAAIC,OAAO,CAAW,CAACC,OAAO,EAAEC,CAAC,KAAK;MAC3CX,cAAc,CAACQ,UAAU,CAAEI,KAAe,IAAK;QAC7CF,OAAO,CAACE,KAAK,CAAC;MAChB,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;EACEC,UAAUA,CAACC,UAAkB,EAA6B;IACxD,IAAIT,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAC3B,OAAOG,OAAO,CAACM,OAAO,CAAC;MACrBC,MAAM,EAAE,IAAI;MACZC,OAAO,EAAE;IACX,CAAC,CAAC;IACJ,OAAO,IAAIR,OAAO,CAAmB,CAACC,OAAO,EAAEQ,MAAM,KAAK;MACxDlB,cAAc,CAACa,UAAU,CACvBC,UAAU,EACV,C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B,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACH,cAAc,EAAEuB,WAAW,CAAC,mBAAmB,EAAED,QAAQ,CAAC;IAC/D,OAAO,MAAM;MACX,IAAI,CAACtB,cAAc,EAAEwB,kBAAkB,CAAC,mBAAmB,CAAC;IAC9D,CAAC;EACH;AACF;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc,IAAI5B,QAAQ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","BleUtilsModule","NativeModules","readSupportsKeyMissingEvent","Platform","OS","constants","getConstants","supportsKeyMissingEvent","BleUtils","UiEventEmitter","constructor","NativeEventEmitter","checkState","Promise","fulfill","_","state","pairDevice","macAddress","resolve","bonded","bonding","reject","error","result","getConnectedPeripherals","serviceUUIDs","getBondedPeripherals","onDeviceBondState","callback","addListener","removeAllListeners","supportsDeviceKeyMissing","onDeviceKeyMissing","subscription","remove","_default","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AASA,MAAM;EAAEC;AAAe,CAAC,GAAGC,0BAAa;AAYxC,MAAMC,2BAA2B,GAAGA,CAAA,KAAe;EACjD,IAAIC,qBAAQ,CAACC,EAAE,KAAK,SAAS,IAAI,CAACJ,cAAc,EAAE,OAAO,KAAK;EAC9D;EACA;EACA,MAAMK,SAAS,GACb,OAAOL,cAAc,CAACM,YAAY,KAAK,UAAU,GAC7CN,cAAc,CAACM,YAAY,CAAC,CAAC,GAC7BN,cAAc;EACpB,OAAOK,SAAS,EAAEE,uBAAuB,KAAK,IAAI;AACpD,CAAC;AAED,MAAMC,QAAQ,CAAC;EACbC,cAAc,GAA8B,IAAI;EAEhDC,WAAWA,CAAA,EAAG;IACZ,IAAIP,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACK,cAAc,GAAG,IAAIE,+BAAkB,CAACX,cAAc,CAA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ACb;QACF;MACF,CACF,CAAC;IACH,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;EACEa,oBAAoBA,CAAA,EAAG;IACrB,OAAO,IAAId,OAAO,CAAe,CAACC,OAAO,EAAEQ,MAAM,KAAK;MACpDtB,cAAc,CAAC2B,oBAAoB,CACjC,CAACJ,KAAoB,EAAEC,MAA2B,KAAK;QACrD,IAAID,KAAK,EAAE;UACTD,MAAM,CAACC,KAAK,CAAC;QACf,CAAC,MAAM;UACL,IAAIC,MAAM,EAAE;YACVV,OAAO,CAACU,MAAM,CAAC;UACjB,CAAC,MAAM;YACLV,OAAO,CAAC,EAAE,CAAC;UACb;QACF;MACF,CACF,CAAC;IACH,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEc,iBAAiBA,CAACC,QAA0C,EAAE;IAC5D,IAAI1B,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACK,cAAc,EAAEqB,WAAW,CAAC,mBAAmB,EAAED,QAAQ,CAAC;IAC/D,OAAO,MAAM;MACX,IAAI,CAACpB,cAAc,EAAEsB,kBAAkB,CAAC,mBAAmB,CAAC;IAC9D,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;EACEC,wBAAwBA,CAAA,EAAG;IACzB,OAAO9B,2BAA2B,CAAC,CAAC;EACtC;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE+B,kBAAkBA,CAACJ,QAAoD,EAAE;IACvE,MAAMK,YAAY,GAAG,IAAI,CAACzB,cAAc,EAAEqB,WAAW,CACnD,oBAAoB,EACpBD,QACF,CAAC;IACD,OAAO,MAAM;MACXK,YAAY,EAAEC,MAAM,CAAC,CAAC;IACxB,CAAC;EACH;AACF;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc,IAAI9B,QAAQ,CAAC,CAAC","ignoreList":[]}
@@ -4,6 +4,13 @@ import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
4
4
  const {
5
5
  BleUtilsModule
6
6
  } = NativeModules;
7
+ const readSupportsKeyMissingEvent = () => {
8
+ if (Platform.OS !== 'android' || !BleUtilsModule) return false;
9
+ // Interop exposes legacy constants through getConstants(); the bridge exposes them
10
+ // as plain properties.
11
+ const constants = typeof BleUtilsModule.getConstants === 'function' ? BleUtilsModule.getConstants() : BleUtilsModule;
12
+ return constants?.supportsKeyMissingEvent === true;
13
+ };
7
14
  class BleUtils {
8
15
  UiEventEmitter = null;
9
16
  constructor() {
@@ -101,6 +108,30 @@ class BleUtils {
101
108
  this.UiEventEmitter?.removeAllListeners('onDeviceBondState');
102
109
  };
103
110
  }
111
+
112
+ /**
113
+ * [Android only]
114
+ * Whether this OS version and native build report `onDeviceKeyMissing`. When false
115
+ * the event never fires, so callers should not wait for it.
116
+ */
117
+ supportsDeviceKeyMissing() {
118
+ return readSupportsKeyMissingEvent();
119
+ }
120
+
121
+ /**
122
+ * [Android 16+ only]
123
+ * A bonded device could not provide its keys when the link was encrypted: the device
124
+ * was wiped or removed the bond. Android keeps its side of the bond, so the device
125
+ * stays unusable until the user forgets it in system Bluetooth settings.
126
+ * Each subscription is removed on its own, so several callers can listen at once.
127
+ * @param callback
128
+ */
129
+ onDeviceKeyMissing(callback) {
130
+ const subscription = this.UiEventEmitter?.addListener('onDeviceKeyMissing', callback);
131
+ return () => {
132
+ subscription?.remove();
133
+ };
134
+ }
104
135
  }
105
136
  export default new BleUtils();
106
137
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NativeEventEmitter","NativeModules","Platform","BleUtilsModule","BleUtils","UiEventEmitter","constructor","OS","checkState","Promise","fulfill","_","state","pairDevice","macAddress","resolve","bonded","bonding","reject","error","result","getConnectedPeripherals","serviceUUIDs","getBondedPeripherals","onDeviceBondState","callback","addListener","removeAllListeners"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,kBAAkB,EAAEC,aAAa,EAAEC,QAAQ,QAAQ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,CAACkB,uBAAuB,CACpCC,YAAY,EACZ,CAACH,KAAoB,EAAEC,MAA2B,KAAK;QACrD,IAAID,KAAK,EAAE;UACTD,MAAM,CAACC,KAAK,CAAC;QACf,CAAC,MAAM;UACL,IAAIC,MAAM,EAAE;YACVV,OAAO,CAACU,MAAM,CAAC;UACjB,CAAC,MAAM;YACLV,OAAO,CAAC,EAAE,CAAC;UACb;QACF;MACF,CACF,CAAC;IACH,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;EACEa,oBAAoBA,CAAA,EAAG;IACrB,OAAO,IAAId,OAAO,CAAe,CAACC,OAAO,EAAEQ,MAAM,KAAK;MACpDf,cAAc,CAACoB,oBAAoB,CACjC,CAACJ,KAAoB,EAAEC,MAA2B,KAAK;QACrD,IAAID,KAAK,EAAE;UACTD,MAAM,CAACC,KAAK,CAAC;QACf,CAAC,MAAM;UACL,IAAIC,MAAM,EAAE;YACVV,OAAO,CAACU,MAAM,CAAC;UACjB,CAAC,MAAM;YACLV,OAAO,CAAC,EAAE,CAAC;UACb;QACF;MACF,CACF,CAAC;IACH,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEc,iBAAiBA,CAACC,QAA0C,EAAE;IAC5D,IAAIvB,QAAQ,CAACK,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACF,cAAc,EAAEqB,WAAW,CAAC,mBAAmB,EAAED,QAAQ,CAAC;IAC/D,OAAO,MAAM;MACX,IAAI,CAACpB,cAAc,EAAEsB,kBAAkB,CAAC,mBAAmB,CAAC;IAC9D,CAAC;EACH;AACF;AAEA,eAAe,IAAIvB,QAAQ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["NativeEventEmitter","NativeModules","Platform","BleUtilsModule","readSupportsKeyMissingEvent","OS","constants","getConstants","supportsKeyMissingEvent","BleUtils","UiEventEmitter","constructor","checkState","Promise","fulfill","_","state","pairDevice","macAddress","resolve","bonded","bonding","reject","error","result","getConnectedPeripherals","serviceUUIDs","getBondedPeripherals","onDeviceBondState","callback","addListener","removeAllListeners","supportsDeviceKeyMissing","onDeviceKeyMissing","subscription","remove"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,kBAAkB,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAS1E,MAAM;EAAEC;AAAe,CAAC,GAAGF,aAAa;AAYxC,MAAMG,2BAA2B,GAAGA,CAAA,KAAe;EACjD,IAAIF,QAAQ,CAACG,EAAE,KAAK,SAAS,IAAI,CAACF,cAAc,EAAE,OAAO,KAAK;EAC9D;EACA;EACA,MAAMG,SAAS,GACb,OAAOH,cAAc,CAACI,YAAY,KAAK,UAAU,GAC7CJ,cAAc,CAACI,YAAY,CAAC,CAAC,GAC7BJ,cAAc;EACpB,OAAOG,SAAS,EAAEE,uBAAuB,KAAK,IAAI;AACpD,CAAC;AAED,MAAMC,QAAQ,CAAC;EACbC,cAAc,GAA8B,IAAI;EAEhDC,WAAWA,CAAA,EAAG;IACZ,IAAIT,QAAQ,CAACG,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACK,cAAc,GAAG,IAAIV,kBAAkB,CAACG,cAAc,CAAC;EAC9D;EAEAS,UAAUA,CAAA,EAAG;IACX,OAAO,IAAIC,OAAO,CAAW,CAACC,OAAO,EAAEC,CAAC,KAAK;MAC3CZ,cAAc,CAACS,UAAU,CAAEI,KAAe,IAAK;QAC7CF,OAAO,CAACE,KAAK,CAAC;MAChB,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;EACEC,UAAUA,CAACC,UAAkB,EAA6B;IACxD,IAAIhB,QAAQ,CAACG,EAAE,KAAK,SAAS,EAC3B,OAAOQ,OAAO,CAACM,OAAO,CAAC;MACrBC,MAAM,EAAE,IAAI;MACZC,OAAO,EAAE;IACX,CAAC,CAAC;IACJ,OAAO,IAAIR,OAAO,CAAmB,CAACC,OAAO,EAAEQ,MAAM,KAAK;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Ec,iBAAiBA,CAACC,QAA0C,EAAE;IAC5D,IAAI3B,QAAQ,CAACG,EAAE,KAAK,SAAS,EAAE;IAC/B,IAAI,CAACK,cAAc,EAAEoB,WAAW,CAAC,mBAAmB,EAAED,QAAQ,CAAC;IAC/D,OAAO,MAAM;MACX,IAAI,CAACnB,cAAc,EAAEqB,kBAAkB,CAAC,mBAAmB,CAAC;IAC9D,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;EACEC,wBAAwBA,CAAA,EAAG;IACzB,OAAO5B,2BAA2B,CAAC,CAAC;EACtC;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE6B,kBAAkBA,CAACJ,QAAoD,EAAE;IACvE,MAAMK,YAAY,GAAG,IAAI,CAACxB,cAAc,EAAEoB,WAAW,CACnD,oBAAoB,EACpBD,QACF,CAAC;IACD,OAAO,MAAM;MACXK,YAAY,EAAEC,MAAM,CAAC,CAAC;IACxB,CAAC;EACH;AACF;AAEA,eAAe,IAAI1B,QAAQ,CAAC,CAAC","ignoreList":[]}
@@ -1,8 +1,14 @@
1
1
  import { NativeEventEmitter } from 'react-native';
2
- import type { BleState, Peripheral, BondState, AdvertisingData } from './type';
2
+ import type { BleState, Peripheral, BondState, AdvertisingData, KeyMissingPeripheral } from './type';
3
3
  type PairDeviceResult = {
4
4
  bonded: boolean;
5
5
  bonding: boolean;
6
+ /**
7
+ * [Android only] True when this call started the bonding. False while `bonding` is
8
+ * true means the system started it, e.g. its own re-pairing after a lost bond.
9
+ * Undefined on native builds that predate the field.
10
+ */
11
+ initiated?: boolean;
6
12
  };
7
13
  declare class BleUtils {
8
14
  UiEventEmitter: NativeEventEmitter | null;
@@ -33,8 +39,23 @@ declare class BleUtils {
33
39
  * @param callback
34
40
  */
35
41
  onDeviceBondState(callback: (peripheral: Peripheral) => void): (() => void) | undefined;
42
+ /**
43
+ * [Android only]
44
+ * Whether this OS version and native build report `onDeviceKeyMissing`. When false
45
+ * the event never fires, so callers should not wait for it.
46
+ */
47
+ supportsDeviceKeyMissing(): boolean;
48
+ /**
49
+ * [Android 16+ only]
50
+ * A bonded device could not provide its keys when the link was encrypted: the device
51
+ * was wiped or removed the bond. Android keeps its side of the bond, so the device
52
+ * stays unusable until the user forgets it in system Bluetooth settings.
53
+ * Each subscription is removed on its own, so several callers can listen at once.
54
+ * @param callback
55
+ */
56
+ onDeviceKeyMissing(callback: (peripheral: KeyMissingPeripheral) => void): () => void;
36
57
  }
37
58
  declare const _default: BleUtils;
38
59
  export default _default;
39
- export type { BleState, Peripheral, BondState, AdvertisingData };
60
+ export type { BleState, Peripheral, BondState, AdvertisingData, KeyMissingPeripheral, PairDeviceResult, };
40
61
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG/E,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,cAAM,QAAQ;IACZ,cAAc,EAAE,kBAAkB,GAAG,IAAI,CAAQ;;IAOjD,UAAU;IAQV;;;;OAIG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2BzD;;;;OAIG;IACH,uBAAuB,CAAC,YAAY,GAAE,MAAM,EAAO;IAmBnD;;;OAGG;IACH,oBAAoB;IAkBpB;;;;;;OAMG;IACH,iBAAiB,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI;CAO7D;;AAED,wBAA8B;AAC9B,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,eAAe,EACf,oBAAoB,EACrB,MAAM,QAAQ,CAAC;AAGhB,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAaF,cAAM,QAAQ;IACZ,cAAc,EAAE,kBAAkB,GAAG,IAAI,CAAQ;;IAOjD,UAAU;IAQV;;;;OAIG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2BzD;;;;OAIG;IACH,uBAAuB,CAAC,YAAY,GAAE,MAAM,EAAO;IAmBnD;;;OAGG;IACH,oBAAoB;IAkBpB;;;;;;OAMG;IACH,iBAAiB,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI;IAQ5D;;;;OAIG;IACH,wBAAwB;IAIxB;;;;;;;OAOG;IACH,kBAAkB,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,oBAAoB,KAAK,IAAI;CASxE;;AAED,wBAA8B;AAC9B,YAAY,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,gBAAgB,GACjB,CAAC"}
@@ -37,6 +37,12 @@ export interface Peripheral {
37
37
  export interface BondState {
38
38
  state: string;
39
39
  preState: string;
40
+ /** Android EXTRA_UNBOND_REASON, when supplied by the system. */
41
+ reason?: number;
42
+ }
43
+ export interface KeyMissingPeripheral {
44
+ /** Device MAC address. */
45
+ id: string;
40
46
  }
41
47
  export interface AdvertisingData {
42
48
  isConnectable?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../../src/type.ts"],"names":[],"mappings":"AAAA;;;KAGK;AACL,oBAAY,QAAQ;IAClB;;OAEG;IACH,OAAO,YAAY;IACnB;;OAEG;IACH,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B;;OAEG;IACH,YAAY,iBAAiB;IAC7B,EAAE,OAAO;IACT,GAAG,QAAQ;IACX;;OAEG;IACH,SAAS,eAAe;IACxB;;OAEG;IACH,UAAU,gBAAgB;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,eAAe,CAAC;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../../src/type.ts"],"names":[],"mappings":"AAAA;;;KAGK;AACL,oBAAY,QAAQ;IAClB;;OAEG;IACH,OAAO,YAAY;IACnB;;OAEG;IACH,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B;;OAEG;IACH,YAAY,iBAAiB;IAC7B,EAAE,OAAO;IACT,GAAG,QAAQ;IACX;;OAEG;IACH,SAAS,eAAe;IACxB;;OAEG;IACH,UAAU,gBAAgB;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,eAAe,CAAC;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
@@ -1,8 +1,14 @@
1
1
  import { NativeEventEmitter } from 'react-native';
2
- import type { BleState, Peripheral, BondState, AdvertisingData } from './type';
2
+ import type { BleState, Peripheral, BondState, AdvertisingData, KeyMissingPeripheral } from './type';
3
3
  type PairDeviceResult = {
4
4
  bonded: boolean;
5
5
  bonding: boolean;
6
+ /**
7
+ * [Android only] True when this call started the bonding. False while `bonding` is
8
+ * true means the system started it, e.g. its own re-pairing after a lost bond.
9
+ * Undefined on native builds that predate the field.
10
+ */
11
+ initiated?: boolean;
6
12
  };
7
13
  declare class BleUtils {
8
14
  UiEventEmitter: NativeEventEmitter | null;
@@ -33,8 +39,23 @@ declare class BleUtils {
33
39
  * @param callback
34
40
  */
35
41
  onDeviceBondState(callback: (peripheral: Peripheral) => void): (() => void) | undefined;
42
+ /**
43
+ * [Android only]
44
+ * Whether this OS version and native build report `onDeviceKeyMissing`. When false
45
+ * the event never fires, so callers should not wait for it.
46
+ */
47
+ supportsDeviceKeyMissing(): boolean;
48
+ /**
49
+ * [Android 16+ only]
50
+ * A bonded device could not provide its keys when the link was encrypted: the device
51
+ * was wiped or removed the bond. Android keeps its side of the bond, so the device
52
+ * stays unusable until the user forgets it in system Bluetooth settings.
53
+ * Each subscription is removed on its own, so several callers can listen at once.
54
+ * @param callback
55
+ */
56
+ onDeviceKeyMissing(callback: (peripheral: KeyMissingPeripheral) => void): () => void;
36
57
  }
37
58
  declare const _default: BleUtils;
38
59
  export default _default;
39
- export type { BleState, Peripheral, BondState, AdvertisingData };
60
+ export type { BleState, Peripheral, BondState, AdvertisingData, KeyMissingPeripheral, PairDeviceResult, };
40
61
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG/E,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,cAAM,QAAQ;IACZ,cAAc,EAAE,kBAAkB,GAAG,IAAI,CAAQ;;IAOjD,UAAU;IAQV;;;;OAIG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2BzD;;;;OAIG;IACH,uBAAuB,CAAC,YAAY,GAAE,MAAM,EAAO;IAmBnD;;;OAGG;IACH,oBAAoB;IAkBpB;;;;;;OAMG;IACH,iBAAiB,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI;CAO7D;;AAED,wBAA8B;AAC9B,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,eAAe,EACf,oBAAoB,EACrB,MAAM,QAAQ,CAAC;AAGhB,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAaF,cAAM,QAAQ;IACZ,cAAc,EAAE,kBAAkB,GAAG,IAAI,CAAQ;;IAOjD,UAAU;IAQV;;;;OAIG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2BzD;;;;OAIG;IACH,uBAAuB,CAAC,YAAY,GAAE,MAAM,EAAO;IAmBnD;;;OAGG;IACH,oBAAoB;IAkBpB;;;;;;OAMG;IACH,iBAAiB,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI;IAQ5D;;;;OAIG;IACH,wBAAwB;IAIxB;;;;;;;OAOG;IACH,kBAAkB,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,oBAAoB,KAAK,IAAI;CASxE;;AAED,wBAA8B;AAC9B,YAAY,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,gBAAgB,GACjB,CAAC"}
@@ -37,6 +37,12 @@ export interface Peripheral {
37
37
  export interface BondState {
38
38
  state: string;
39
39
  preState: string;
40
+ /** Android EXTRA_UNBOND_REASON, when supplied by the system. */
41
+ reason?: number;
42
+ }
43
+ export interface KeyMissingPeripheral {
44
+ /** Device MAC address. */
45
+ id: string;
40
46
  }
41
47
  export interface AdvertisingData {
42
48
  isConnectable?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../../src/type.ts"],"names":[],"mappings":"AAAA;;;KAGK;AACL,oBAAY,QAAQ;IAClB;;OAEG;IACH,OAAO,YAAY;IACnB;;OAEG;IACH,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B;;OAEG;IACH,YAAY,iBAAiB;IAC7B,EAAE,OAAO;IACT,GAAG,QAAQ;IACX;;OAEG;IACH,SAAS,eAAe;IACxB;;OAEG;IACH,UAAU,gBAAgB;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,eAAe,CAAC;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../../src/type.ts"],"names":[],"mappings":"AAAA;;;KAGK;AACL,oBAAY,QAAQ;IAClB;;OAEG;IACH,OAAO,YAAY;IACnB;;OAEG;IACH,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B;;OAEG;IACH,YAAY,iBAAiB;IAC7B,EAAE,OAAO;IACT,GAAG,QAAQ;IACX;;OAEG;IACH,SAAS,eAAe;IACxB;;OAEG;IACH,UAAU,gBAAgB;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,eAAe,CAAC;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-ble-utils",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "ble uilts",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./dist/commonjs/index.js",
package/src/index.ts CHANGED
@@ -1,10 +1,33 @@
1
1
  import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
2
- import type { BleState, Peripheral, BondState, AdvertisingData } from './type';
2
+ import type {
3
+ BleState,
4
+ Peripheral,
5
+ BondState,
6
+ AdvertisingData,
7
+ KeyMissingPeripheral,
8
+ } from './type';
3
9
 
4
10
  const { BleUtilsModule } = NativeModules;
5
11
  type PairDeviceResult = {
6
12
  bonded: boolean;
7
13
  bonding: boolean;
14
+ /**
15
+ * [Android only] True when this call started the bonding. False while `bonding` is
16
+ * true means the system started it, e.g. its own re-pairing after a lost bond.
17
+ * Undefined on native builds that predate the field.
18
+ */
19
+ initiated?: boolean;
20
+ };
21
+
22
+ const readSupportsKeyMissingEvent = (): boolean => {
23
+ if (Platform.OS !== 'android' || !BleUtilsModule) return false;
24
+ // Interop exposes legacy constants through getConstants(); the bridge exposes them
25
+ // as plain properties.
26
+ const constants =
27
+ typeof BleUtilsModule.getConstants === 'function'
28
+ ? BleUtilsModule.getConstants()
29
+ : BleUtilsModule;
30
+ return constants?.supportsKeyMissingEvent === true;
8
31
  };
9
32
 
10
33
  class BleUtils {
@@ -115,7 +138,41 @@ class BleUtils {
115
138
  this.UiEventEmitter?.removeAllListeners('onDeviceBondState');
116
139
  };
117
140
  }
141
+
142
+ /**
143
+ * [Android only]
144
+ * Whether this OS version and native build report `onDeviceKeyMissing`. When false
145
+ * the event never fires, so callers should not wait for it.
146
+ */
147
+ supportsDeviceKeyMissing() {
148
+ return readSupportsKeyMissingEvent();
149
+ }
150
+
151
+ /**
152
+ * [Android 16+ only]
153
+ * A bonded device could not provide its keys when the link was encrypted: the device
154
+ * was wiped or removed the bond. Android keeps its side of the bond, so the device
155
+ * stays unusable until the user forgets it in system Bluetooth settings.
156
+ * Each subscription is removed on its own, so several callers can listen at once.
157
+ * @param callback
158
+ */
159
+ onDeviceKeyMissing(callback: (peripheral: KeyMissingPeripheral) => void) {
160
+ const subscription = this.UiEventEmitter?.addListener(
161
+ 'onDeviceKeyMissing',
162
+ callback
163
+ );
164
+ return () => {
165
+ subscription?.remove();
166
+ };
167
+ }
118
168
  }
119
169
 
120
170
  export default new BleUtils();
121
- export type { BleState, Peripheral, BondState, AdvertisingData };
171
+ export type {
172
+ BleState,
173
+ Peripheral,
174
+ BondState,
175
+ AdvertisingData,
176
+ KeyMissingPeripheral,
177
+ PairDeviceResult,
178
+ };
package/src/type.ts CHANGED
@@ -39,6 +39,13 @@ export interface Peripheral {
39
39
  export interface BondState {
40
40
  state: string;
41
41
  preState: string;
42
+ /** Android EXTRA_UNBOND_REASON, when supplied by the system. */
43
+ reason?: number;
44
+ }
45
+
46
+ export interface KeyMissingPeripheral {
47
+ /** Device MAC address. */
48
+ id: string;
42
49
  }
43
50
 
44
51
  export interface AdvertisingData {