@onekeyfe/hd-transport-react-native 1.2.2-alpha.8 → 1.2.3-alpha.1
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.
- package/dist/bleStaleBond.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -16
- package/package.json +5 -5
- package/src/__tests__/bleStaleBond.test.ts +8 -0
- package/src/__tests__/protocolV2Link.test.ts +128 -0
- package/src/bleStaleBond.ts +3 -0
- package/src/index.ts +41 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bleStaleBond.d.ts","sourceRoot":"","sources":["../src/bleStaleBond.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,2BAA2B,EAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,2BAA2B,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"bleStaleBond.d.ts","sourceRoot":"","sources":["../src/bleStaleBond.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,2BAA2B,EAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,2BAA2B,EAAE,CAAC;AAmBvC,eAAO,MAAM,yBAAyB,UAAW,OAAO,KAAG,OAiB1D,CAAC;AAEF,eAAO,MAAM,2BAA2B,UAAW,OAAO,UAkBzD,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAGL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACp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AoB;YAgCpB,cAAc;YAqEd,iCAAiC;IAiB/C,OAAO,CAAC,8BAA8B;YAQxB,mCAAmC;IAsBjD,OAAO,CAAC,yCAAyC;YAanC,gCAAgC;IAoB9C,OAAO,CAAC,uBAAuB;IAmD/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
|
@@ -207,6 +207,8 @@ const isNativeBleStaleBondError = (error) => {
|
|
|
207
207
|
const nativeError = error;
|
|
208
208
|
if (nativeError.attErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
209
209
|
nativeError.attErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
210
|
+
nativeError.androidErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
211
|
+
nativeError.androidErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
210
212
|
nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION) {
|
|
211
213
|
return true;
|
|
212
214
|
}
|
|
@@ -404,10 +406,10 @@ const requestNegotiatedMtu = (device, stage, attempt) => __awaiter(void 0, void
|
|
|
404
406
|
}
|
|
405
407
|
});
|
|
406
408
|
const resolveNegotiatedMtu = (device) => requestNegotiatedMtu(device, 'connected', 0);
|
|
407
|
-
function remapError(error
|
|
409
|
+
function remapError(error) {
|
|
408
410
|
var _a;
|
|
409
411
|
if (error instanceof reactNativeBlePlx.BleError) {
|
|
410
|
-
if (
|
|
412
|
+
if (isNativeBleStaleBondError(error)) {
|
|
411
413
|
throw toBleStaleBondHardwareError(error);
|
|
412
414
|
}
|
|
413
415
|
if ((error === null || error === void 0 ? void 0 : error.attErrorCode) === 22) {
|
|
@@ -892,15 +894,6 @@ class ReactNativeBleTransport {
|
|
|
892
894
|
Log === null || Log === void 0 ? void 0 : Log.debug('subscribeBleOn error: ', error);
|
|
893
895
|
throw error;
|
|
894
896
|
}
|
|
895
|
-
if (reactNative.Platform.OS === 'android') {
|
|
896
|
-
const bondState = yield pairDevice(uuid);
|
|
897
|
-
if (bondState.bonding) {
|
|
898
|
-
yield onDeviceBondState(uuid);
|
|
899
|
-
}
|
|
900
|
-
else if (!bondState.bonded) {
|
|
901
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
897
|
if (!device) {
|
|
905
898
|
const devices = yield blePlxManager.devices([uuid]);
|
|
906
899
|
[device] = devices;
|
|
@@ -931,7 +924,7 @@ class ReactNativeBleTransport {
|
|
|
931
924
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleAlreadyConnected);
|
|
932
925
|
}
|
|
933
926
|
else {
|
|
934
|
-
remapError(e
|
|
927
|
+
remapError(e);
|
|
935
928
|
}
|
|
936
929
|
}
|
|
937
930
|
}
|
|
@@ -955,19 +948,46 @@ class ReactNativeBleTransport {
|
|
|
955
948
|
try {
|
|
956
949
|
device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(fallbackConnectOptions));
|
|
957
950
|
}
|
|
958
|
-
catch (
|
|
959
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('last try to reconnect error: ',
|
|
960
|
-
if (
|
|
951
|
+
catch (fallbackError) {
|
|
952
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('last try to reconnect error: ', fallbackError);
|
|
953
|
+
if (fallbackError.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
|
|
961
954
|
Log === null || Log === void 0 ? void 0 : Log.debug('last try to reconnect');
|
|
962
955
|
yield disconnectedDevice.cancelConnection();
|
|
963
956
|
device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(fallbackConnectOptions));
|
|
964
957
|
}
|
|
958
|
+
else {
|
|
959
|
+
remapError(fallbackError);
|
|
960
|
+
}
|
|
965
961
|
}
|
|
966
962
|
}
|
|
967
963
|
else {
|
|
968
|
-
remapError(e
|
|
964
|
+
remapError(e);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
if (reactNative.Platform.OS === 'android') {
|
|
969
|
+
const connectedDevice = device;
|
|
970
|
+
try {
|
|
971
|
+
if (!(yield connectedDevice.isConnected().catch(() => false))) {
|
|
972
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, `Device ${uuid} is not connected before bonding`);
|
|
973
|
+
}
|
|
974
|
+
const bondState = yield pairDevice(uuid);
|
|
975
|
+
if (bondState.bonding) {
|
|
976
|
+
yield onDeviceBondState(uuid);
|
|
977
|
+
}
|
|
978
|
+
else if (!bondState.bonded) {
|
|
979
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
|
969
980
|
}
|
|
970
981
|
}
|
|
982
|
+
catch (error) {
|
|
983
|
+
yield this.runNativeTeardown(uuid, blePlxManager, () => __awaiter(this, void 0, void 0, function* () {
|
|
984
|
+
yield Promise.all([
|
|
985
|
+
this.runBestEffortNativeOperation('bond failure: cancel manager connection', () => blePlxManager.cancelDeviceConnection(uuid)),
|
|
986
|
+
this.runBestEffortNativeOperation('bond failure: cancel device connection', () => connectedDevice.cancelConnection()),
|
|
987
|
+
]);
|
|
988
|
+
}));
|
|
989
|
+
throw error;
|
|
990
|
+
}
|
|
971
991
|
}
|
|
972
992
|
device = yield resolveNegotiatedMtu(device);
|
|
973
993
|
const acquiredDevice = device;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3-alpha.1",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"lint:fix": "eslint . --fix"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-core": "1.2.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.3-alpha.1",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.3-alpha.1",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.3-alpha.1",
|
|
26
26
|
"@onekeyfe/react-native-ble-utils": "^0.1.6",
|
|
27
27
|
"react-native-ble-plx": "3.5.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "fd4221863c00240fc4870fc50f8c517d97426de2"
|
|
30
30
|
}
|
|
@@ -12,6 +12,14 @@ describe('native BLE stale bond mapping', () => {
|
|
|
12
12
|
{ attErrorCode: 5, reason: 'GATT_INSUF_AUTHENTICATION' },
|
|
13
13
|
HardwareErrorCode.BleDeviceBondError,
|
|
14
14
|
],
|
|
15
|
+
[
|
|
16
|
+
{ androidErrorCode: 5, reason: 'Connection state changed with status 5' },
|
|
17
|
+
HardwareErrorCode.BleDeviceBondError,
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
{ androidErrorCode: 15, reason: 'Connection state changed with status 15' },
|
|
21
|
+
HardwareErrorCode.BleDeviceBondError,
|
|
22
|
+
],
|
|
15
23
|
[
|
|
16
24
|
{ iosErrorCode: 14, reason: 'Peer removed pairing information' },
|
|
17
25
|
HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
@@ -360,6 +360,134 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
360
360
|
expect(new ReactNativeBleTransport({}).scanTimeout).toBe(3000);
|
|
361
361
|
});
|
|
362
362
|
|
|
363
|
+
test('connects the Android GATT link before starting system bonding', async () => {
|
|
364
|
+
setPlatformOS('android');
|
|
365
|
+
const { transport, uuid, device } = createHarness();
|
|
366
|
+
const operationOrder: string[] = [];
|
|
367
|
+
const pairDeviceMock = jest.requireMock('../BleManager').pairDevice as jest.Mock;
|
|
368
|
+
|
|
369
|
+
device.isConnected.mockResolvedValueOnce(false);
|
|
370
|
+
device.connect = jest.fn(() => {
|
|
371
|
+
operationOrder.push('connect');
|
|
372
|
+
return Promise.resolve(device);
|
|
373
|
+
});
|
|
374
|
+
pairDeviceMock.mockImplementationOnce(() => {
|
|
375
|
+
operationOrder.push('bond');
|
|
376
|
+
return Promise.resolve({ bonded: true, bonding: false });
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).resolves.toEqual({
|
|
380
|
+
uuid,
|
|
381
|
+
protocolType: 'V2',
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
expect(operationOrder).toEqual(['connect', 'bond']);
|
|
385
|
+
await transport.release(uuid, true);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test('does not start Android bonding when both reconnect attempts fail', async () => {
|
|
389
|
+
setPlatformOS('android');
|
|
390
|
+
const { transport, uuid, device } = createHarness();
|
|
391
|
+
const BleErrorMock = jest.requireMock('react-native-ble-plx').BleError as new (
|
|
392
|
+
message: string
|
|
393
|
+
) => Error;
|
|
394
|
+
const pairDeviceMock = jest.requireMock('../BleManager').pairDevice as jest.Mock;
|
|
395
|
+
const firstError = Object.assign(new BleErrorMock('MTU change failed'), {
|
|
396
|
+
errorCode: 206,
|
|
397
|
+
reason: 'MTU change failed',
|
|
398
|
+
});
|
|
399
|
+
const fallbackError = Object.assign(new BleErrorMock('GATT connect failed'), {
|
|
400
|
+
errorCode: 205,
|
|
401
|
+
reason: 'GATT connect failed',
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
device.isConnected.mockResolvedValueOnce(false);
|
|
405
|
+
device.connect = jest
|
|
406
|
+
.fn()
|
|
407
|
+
.mockRejectedValueOnce(firstError)
|
|
408
|
+
.mockRejectedValueOnce(fallbackError);
|
|
409
|
+
pairDeviceMock.mockClear();
|
|
410
|
+
|
|
411
|
+
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
412
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
413
|
+
});
|
|
414
|
+
expect(device.connect).toHaveBeenCalledTimes(2);
|
|
415
|
+
expect(pairDeviceMock).not.toHaveBeenCalled();
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
test('checks that the Android GATT link is connected before bonding', async () => {
|
|
419
|
+
setPlatformOS('android');
|
|
420
|
+
const { transport, uuid, device, bleManager } = createHarness();
|
|
421
|
+
const pairDeviceMock = jest.requireMock('../BleManager').pairDevice as jest.Mock;
|
|
422
|
+
|
|
423
|
+
device.isConnected.mockResolvedValueOnce(false).mockResolvedValueOnce(false);
|
|
424
|
+
device.connect = jest.fn().mockResolvedValue(device);
|
|
425
|
+
pairDeviceMock.mockClear();
|
|
426
|
+
|
|
427
|
+
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toMatchObject({
|
|
428
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
429
|
+
});
|
|
430
|
+
expect(pairDeviceMock).not.toHaveBeenCalled();
|
|
431
|
+
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(uuid);
|
|
432
|
+
expect(device.cancelConnection).toHaveBeenCalledTimes(1);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test.each([
|
|
436
|
+
[
|
|
437
|
+
'ios',
|
|
438
|
+
'OneKey Neo',
|
|
439
|
+
{
|
|
440
|
+
iosErrorCode: 14,
|
|
441
|
+
reason: 'Peer removed pairing information',
|
|
442
|
+
},
|
|
443
|
+
HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
444
|
+
],
|
|
445
|
+
[
|
|
446
|
+
'android',
|
|
447
|
+
'OneKey Pro 2',
|
|
448
|
+
{
|
|
449
|
+
androidErrorCode: 5,
|
|
450
|
+
reason: 'Connection state changed with status 5',
|
|
451
|
+
},
|
|
452
|
+
HardwareErrorCode.BleDeviceBondError,
|
|
453
|
+
],
|
|
454
|
+
] as const)(
|
|
455
|
+
'maps a %s %s stale bond during connect before protocol detection',
|
|
456
|
+
async (platform, deviceName, nativeError, errorCode) => {
|
|
457
|
+
setPlatformOS(platform);
|
|
458
|
+
const { transport, uuid, device } = createHarness({ deviceName });
|
|
459
|
+
const BleErrorMock = jest.requireMock('react-native-ble-plx').BleError as new (
|
|
460
|
+
message: string
|
|
461
|
+
) => Error;
|
|
462
|
+
const pairDeviceMock = jest.requireMock('../BleManager').pairDevice as jest.Mock;
|
|
463
|
+
pairDeviceMock.mockClear();
|
|
464
|
+
|
|
465
|
+
device.isConnected.mockResolvedValueOnce(false);
|
|
466
|
+
device.connect = jest
|
|
467
|
+
.fn()
|
|
468
|
+
.mockRejectedValue(Object.assign(new BleErrorMock(nativeError.reason), nativeError));
|
|
469
|
+
|
|
470
|
+
await expect(transport.acquire({ uuid })).rejects.toMatchObject({ errorCode });
|
|
471
|
+
expect(pairDeviceMock).not.toHaveBeenCalled();
|
|
472
|
+
expect(transport.getProtocolType(uuid)).toBeUndefined();
|
|
473
|
+
}
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
test('closes the Android GATT link when system bonding fails', async () => {
|
|
477
|
+
setPlatformOS('android');
|
|
478
|
+
const { transport, uuid, device, bleManager } = createHarness();
|
|
479
|
+
const pairDeviceMock = jest.requireMock('../BleManager').pairDevice as jest.Mock;
|
|
480
|
+
|
|
481
|
+
pairDeviceMock.mockRejectedValueOnce(new Error('bonding canceled'));
|
|
482
|
+
|
|
483
|
+
await expect(transport.acquire({ uuid, expectedProtocol: 'V2' })).rejects.toThrow(
|
|
484
|
+
'bonding canceled'
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(uuid);
|
|
488
|
+
expect(device.cancelConnection).toHaveBeenCalledTimes(1);
|
|
489
|
+
});
|
|
490
|
+
|
|
363
491
|
test('uses withResponse for consecutive iOS Protocol V1 control commands without releasing', async () => {
|
|
364
492
|
const { transport, uuid, writeCharacteristic } = createV1Harness({
|
|
365
493
|
respondOnWriteCount: [1, 2],
|
package/src/bleStaleBond.ts
CHANGED
|
@@ -13,6 +13,7 @@ const IOS_PEER_REMOVED_PAIRING_INFORMATION = 14;
|
|
|
13
13
|
|
|
14
14
|
type NativeBleErrorFields = {
|
|
15
15
|
attErrorCode?: unknown;
|
|
16
|
+
androidErrorCode?: unknown;
|
|
16
17
|
iosErrorCode?: unknown;
|
|
17
18
|
reason?: unknown;
|
|
18
19
|
message?: unknown;
|
|
@@ -32,6 +33,8 @@ export const isNativeBleStaleBondError = (error: unknown): boolean => {
|
|
|
32
33
|
if (
|
|
33
34
|
nativeError.attErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
34
35
|
nativeError.attErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
36
|
+
nativeError.androidErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
37
|
+
nativeError.androidErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
35
38
|
nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION
|
|
36
39
|
) {
|
|
37
40
|
return true;
|
package/src/index.ts
CHANGED
|
@@ -320,9 +320,9 @@ const resolveNegotiatedMtu = (device: Device) => requestNegotiatedMtu(device, 'c
|
|
|
320
320
|
|
|
321
321
|
type IOBleErrorRemap = Error | BleError | null | undefined;
|
|
322
322
|
|
|
323
|
-
function remapError(error: IOBleErrorRemap
|
|
323
|
+
function remapError(error: IOBleErrorRemap) {
|
|
324
324
|
if (error instanceof BleError) {
|
|
325
|
-
if (
|
|
325
|
+
if (isNativeBleStaleBondError(error)) {
|
|
326
326
|
throw toBleStaleBondHardwareError(error);
|
|
327
327
|
}
|
|
328
328
|
|
|
@@ -980,15 +980,6 @@ export default class ReactNativeBleTransport {
|
|
|
980
980
|
throw error;
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
-
if (Platform.OS === 'android') {
|
|
984
|
-
const bondState = await pairDevice(uuid);
|
|
985
|
-
if (bondState.bonding) {
|
|
986
|
-
await onDeviceBondState(uuid);
|
|
987
|
-
} else if (!bondState.bonded) {
|
|
988
|
-
throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
|
|
992
983
|
if (!device) {
|
|
993
984
|
const devices = await blePlxManager.devices([uuid]);
|
|
994
985
|
[device] = devices;
|
|
@@ -1024,7 +1015,7 @@ export default class ReactNativeBleTransport {
|
|
|
1024
1015
|
Log?.debug('device already connected');
|
|
1025
1016
|
throw ERRORS.TypedError(HardwareErrorCode.BleAlreadyConnected);
|
|
1026
1017
|
} else {
|
|
1027
|
-
remapError(e
|
|
1018
|
+
remapError(e);
|
|
1028
1019
|
}
|
|
1029
1020
|
}
|
|
1030
1021
|
}
|
|
@@ -1055,21 +1046,55 @@ export default class ReactNativeBleTransport {
|
|
|
1055
1046
|
device = await this.connectWithTimeout(uuid, () =>
|
|
1056
1047
|
disconnectedDevice.connect(fallbackConnectOptions)
|
|
1057
1048
|
);
|
|
1058
|
-
} catch (
|
|
1059
|
-
Log?.debug('last try to reconnect error: ',
|
|
1049
|
+
} catch (fallbackError) {
|
|
1050
|
+
Log?.debug('last try to reconnect error: ', fallbackError);
|
|
1060
1051
|
// last try to reconnect device if this issue exists
|
|
1061
1052
|
// https://github.com/dotintent/react-native-ble-plx/issues/426
|
|
1062
|
-
if (
|
|
1053
|
+
if (fallbackError.errorCode === BleErrorCode.OperationCancelled) {
|
|
1063
1054
|
Log?.debug('last try to reconnect');
|
|
1064
1055
|
await disconnectedDevice.cancelConnection();
|
|
1065
1056
|
device = await this.connectWithTimeout(uuid, () =>
|
|
1066
1057
|
disconnectedDevice.connect(fallbackConnectOptions)
|
|
1067
1058
|
);
|
|
1059
|
+
} else {
|
|
1060
|
+
remapError(fallbackError);
|
|
1068
1061
|
}
|
|
1069
1062
|
}
|
|
1070
1063
|
} else {
|
|
1071
|
-
remapError(e
|
|
1064
|
+
remapError(e);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
if (Platform.OS === 'android') {
|
|
1070
|
+
// Establish the LE link before createBond(). Without an existing LE ACL,
|
|
1071
|
+
// Android TRANSPORT_AUTO can choose BR/EDR for a BLE-only device.
|
|
1072
|
+
const connectedDevice = device;
|
|
1073
|
+
try {
|
|
1074
|
+
if (!(await connectedDevice.isConnected().catch(() => false))) {
|
|
1075
|
+
throw ERRORS.TypedError(
|
|
1076
|
+
HardwareErrorCode.BleConnectedError,
|
|
1077
|
+
`Device ${uuid} is not connected before bonding`
|
|
1078
|
+
);
|
|
1072
1079
|
}
|
|
1080
|
+
const bondState = await pairDevice(uuid);
|
|
1081
|
+
if (bondState.bonding) {
|
|
1082
|
+
await onDeviceBondState(uuid);
|
|
1083
|
+
} else if (!bondState.bonded) {
|
|
1084
|
+
throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
|
1085
|
+
}
|
|
1086
|
+
} catch (error) {
|
|
1087
|
+
await this.runNativeTeardown(uuid, blePlxManager, async () => {
|
|
1088
|
+
await Promise.all([
|
|
1089
|
+
this.runBestEffortNativeOperation('bond failure: cancel manager connection', () =>
|
|
1090
|
+
blePlxManager.cancelDeviceConnection(uuid)
|
|
1091
|
+
),
|
|
1092
|
+
this.runBestEffortNativeOperation('bond failure: cancel device connection', () =>
|
|
1093
|
+
connectedDevice.cancelConnection()
|
|
1094
|
+
),
|
|
1095
|
+
]);
|
|
1096
|
+
});
|
|
1097
|
+
throw error;
|
|
1073
1098
|
}
|
|
1074
1099
|
}
|
|
1075
1100
|
|