@onekeyfe/hd-transport-react-native 1.2.2-alpha.116 → 1.2.2-alpha.117
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/index.d.ts +13 -59
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +91 -179
- package/package.json +5 -5
- package/src/__tests__/connectTimeout.test.ts +18 -38
- package/src/__tests__/protocolV2Link.test.ts +255 -298
- package/src/index.ts +135 -330
|
@@ -7,7 +7,6 @@ import { ERRORS, HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
|
|
|
7
7
|
import { onDeviceBondState } from '../BleManager';
|
|
8
8
|
import ReactNativeBleTransport, {
|
|
9
9
|
ANDROID_LINK_DROP_QUIET_MS,
|
|
10
|
-
ANDROID_LINK_DROP_TIMEOUT_MS,
|
|
11
10
|
ANDROID_MTU_EXCHANGE_TIMEOUT_MS,
|
|
12
11
|
BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD,
|
|
13
12
|
BLE_CONNECT_TIMEOUT_MS,
|
|
@@ -611,6 +610,19 @@ describe('BLE connect timeout', () => {
|
|
|
611
610
|
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(UUID);
|
|
612
611
|
});
|
|
613
612
|
|
|
613
|
+
test('a native GATT timeout abandons the native connection', async () => {
|
|
614
|
+
const { transport, device, bleManager } = createHarness(() => Promise.resolve());
|
|
615
|
+
const nativeTimeout = Object.assign(new Error('Operation timed out'), {
|
|
616
|
+
errorCode: BleErrorCode.OperationTimedOut,
|
|
617
|
+
});
|
|
618
|
+
device.discoverAllServicesAndCharacteristics.mockRejectedValueOnce(nativeTimeout);
|
|
619
|
+
|
|
620
|
+
await expect((transport as any).resolveCharacteristicsWithTimeout(UUID, device)).rejects.toBe(
|
|
621
|
+
nativeTimeout
|
|
622
|
+
);
|
|
623
|
+
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(UUID);
|
|
624
|
+
});
|
|
625
|
+
|
|
614
626
|
test('a successful GATT retry clears the timeout budget before an abandoned call settles', async () => {
|
|
615
627
|
const { transport, device, bleManager } = createHarness(() => Promise.resolve());
|
|
616
628
|
let resolveAbandonedDiscovery: (() => void) | undefined;
|
|
@@ -643,35 +655,8 @@ describe('BLE connect timeout', () => {
|
|
|
643
655
|
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledTimes(1);
|
|
644
656
|
expect((transport as any).connectionSetupTimeoutCounts.has(UUID)).toBe(false);
|
|
645
657
|
});
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
describe('Android MTU and link-drop bounds', () => {
|
|
649
|
-
beforeAll(() => {
|
|
650
|
-
jest.useFakeTimers({ doNotFake: ['setImmediate', 'performance'] });
|
|
651
|
-
});
|
|
652
658
|
|
|
653
|
-
|
|
654
|
-
jest.useRealTimers();
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
afterEach(() => {
|
|
658
|
-
jest.clearAllTimers();
|
|
659
|
-
jest.restoreAllMocks();
|
|
660
|
-
Object.assign(Platform, { OS: 'ios' });
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
test('the bounds sit above a cold-cache discovery and the 4s GATT link idle timer', () => {
|
|
664
|
-
// Single discovery passes on a Pro 2 at MTU 23 measured up to 4.8s, a refresh plus
|
|
665
|
-
// restart 7.7s; a stuck exchange never completes, so the bound only has to clear those.
|
|
666
|
-
expect(ANDROID_MTU_EXCHANGE_TIMEOUT_MS).toBeGreaterThanOrEqual(10_000);
|
|
667
|
-
expect(ANDROID_MTU_EXCHANGE_TIMEOUT_MS).toBeLessThanOrEqual(20_000);
|
|
668
|
-
// Android keeps the LE link for 4s after the last GATT client closes.
|
|
669
|
-
expect(ANDROID_LINK_DROP_QUIET_MS).toBeGreaterThan(4000);
|
|
670
|
-
expect(ANDROID_LINK_DROP_QUIET_MS).toBeLessThanOrEqual(ANDROID_LINK_DROP_TIMEOUT_MS);
|
|
671
|
-
expect(ANDROID_LINK_DROP_TIMEOUT_MS).toBeLessThanOrEqual(10_000);
|
|
672
|
-
});
|
|
673
|
-
|
|
674
|
-
test('holds an unusable link past the idle timer even when the GATT registry is already empty', async () => {
|
|
659
|
+
test('holds an unusable link past the idle timer', async () => {
|
|
675
660
|
Object.assign(Platform, { OS: 'android' });
|
|
676
661
|
const { transport, device, bleManager } = createHarness(() => Promise.resolve(device));
|
|
677
662
|
device.isConnected.mockResolvedValue(true);
|
|
@@ -689,20 +674,15 @@ describe('Android MTU and link-drop bounds', () => {
|
|
|
689
674
|
await flush();
|
|
690
675
|
expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(UUID);
|
|
691
676
|
|
|
692
|
-
// BluetoothManager.getConnectedDevices(GATT) reports this app's GATT client, which is
|
|
693
|
-
// already closed; the LE link itself stays up for the idle timer, so the wait must not
|
|
694
|
-
// release on that signal alone.
|
|
695
|
-
expect(
|
|
696
|
-
(BleUtils as unknown as { getConnectedPeripherals: jest.Mock }).getConnectedPeripherals
|
|
697
|
-
).toHaveBeenCalled();
|
|
698
677
|
jest.advanceTimersByTime(4000);
|
|
699
678
|
await flush();
|
|
700
679
|
await flush();
|
|
701
680
|
expect(settled).toBeUndefined();
|
|
702
681
|
|
|
703
|
-
await advanceUntil(() => !!settled,
|
|
682
|
+
await advanceUntil(() => !!settled, ANDROID_LINK_DROP_QUIET_MS);
|
|
704
683
|
await acquire;
|
|
705
684
|
expect(settled).toMatchObject({ errorCode: HardwareErrorCode.BleConnectedError });
|
|
685
|
+
expect(device.discoverAllServicesAndCharacteristics).not.toHaveBeenCalled();
|
|
706
686
|
});
|
|
707
687
|
|
|
708
688
|
test('a slow but successful MTU exchange completes inside the bound', async () => {
|
|
@@ -716,7 +696,7 @@ describe('Android MTU and link-drop bounds', () => {
|
|
|
716
696
|
requestMTU: jest.fn(
|
|
717
697
|
() =>
|
|
718
698
|
new Promise(resolve => {
|
|
719
|
-
setTimeout(() => resolve(negotiated),
|
|
699
|
+
setTimeout(() => resolve(negotiated), 10_000);
|
|
720
700
|
})
|
|
721
701
|
),
|
|
722
702
|
});
|
|
@@ -736,7 +716,7 @@ describe('Android MTU and link-drop bounds', () => {
|
|
|
736
716
|
await flush();
|
|
737
717
|
expect(device.discoverAllServicesAndCharacteristics).not.toHaveBeenCalled();
|
|
738
718
|
|
|
739
|
-
jest.advanceTimersByTime(
|
|
719
|
+
jest.advanceTimersByTime(10_000);
|
|
740
720
|
await advanceUntil(() => result !== undefined || failure !== undefined, 5000);
|
|
741
721
|
await acquire;
|
|
742
722
|
expect(failure).toBeUndefined();
|