@onekeyfe/hd-transport-react-native 1.2.2-alpha.120 → 1.2.2-alpha.122

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.2-alpha.120",
3
+ "version": "1.2.2-alpha.122",
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.2-alpha.120",
24
- "@onekeyfe/hd-shared": "1.2.2-alpha.120",
25
- "@onekeyfe/hd-transport": "1.2.2-alpha.120",
23
+ "@onekeyfe/hd-core": "1.2.2-alpha.122",
24
+ "@onekeyfe/hd-shared": "1.2.2-alpha.122",
25
+ "@onekeyfe/hd-transport": "1.2.2-alpha.122",
26
26
  "@onekeyfe/react-native-ble-utils": "0.1.6",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "26958fa2be6aa34a07f42403fb7022d2785e70b9"
29
+ "gitHead": "37770cd3ae109751f082715228b6155487b7da56"
30
30
  }
@@ -6,6 +6,8 @@ import { ERRORS, HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
6
6
 
7
7
  import { onDeviceBondState } from '../BleManager';
8
8
  import ReactNativeBleTransport, {
9
+ ANDROID_LINK_DROP_QUIET_MS,
10
+ ANDROID_MTU_EXCHANGE_TIMEOUT_MS,
9
11
  BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD,
10
12
  BLE_CONNECT_TIMEOUT_MS,
11
13
  BLE_GATT_SETUP_TIMEOUT_MS,
@@ -446,7 +448,7 @@ describe('BLE connect timeout', () => {
446
448
  const nativeOperation = createDeferred<typeof device>();
447
449
  const nativeDisconnect = createDeferred<void>();
448
450
  const requestMtu = jest.fn(() => Promise.resolve(device));
449
- Object.assign(device, { mtu: 247, requestMTU: requestMtu });
451
+ Object.assign(device, { mtu: stage === 'mtu' ? 23 : 247, requestMTU: requestMtu });
450
452
  device.isConnected.mockResolvedValue(true);
451
453
  if (stage === 'connect') device.isConnected.mockResolvedValueOnce(false);
452
454
  if (stage === 'mtu') requestMtu.mockImplementationOnce(() => nativeOperation.promise);
@@ -608,6 +610,19 @@ describe('BLE connect timeout', () => {
608
610
  expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(UUID);
609
611
  });
610
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
+
611
626
  test('a successful GATT retry clears the timeout budget before an abandoned call settles', async () => {
612
627
  const { transport, device, bleManager } = createHarness(() => Promise.resolve());
613
628
  let resolveAbandonedDiscovery: (() => void) | undefined;
@@ -640,4 +655,73 @@ describe('BLE connect timeout', () => {
640
655
  expect(bleManager.cancelDeviceConnection).toHaveBeenCalledTimes(1);
641
656
  expect((transport as any).connectionSetupTimeoutCounts.has(UUID)).toBe(false);
642
657
  });
658
+
659
+ test('holds an unusable link past the idle timer', async () => {
660
+ Object.assign(Platform, { OS: 'android' });
661
+ const { transport, device, bleManager } = createHarness(() => Promise.resolve(device));
662
+ device.isConnected.mockResolvedValue(true);
663
+ Object.assign(device, { mtu: 23, requestMTU: jest.fn(() => new Promise(() => {})) });
664
+ let settled: Error | undefined;
665
+ const acquire = transport.acquire({ uuid: UUID, expectedProtocol: 'V1' }).catch(error => {
666
+ settled = error;
667
+ });
668
+ await flush();
669
+ await flush();
670
+ expect(device.requestMTU).toHaveBeenCalledTimes(1);
671
+
672
+ jest.advanceTimersByTime(ANDROID_MTU_EXCHANGE_TIMEOUT_MS);
673
+ await flush();
674
+ await flush();
675
+ expect(bleManager.cancelDeviceConnection).toHaveBeenCalledWith(UUID);
676
+
677
+ jest.advanceTimersByTime(4000);
678
+ await flush();
679
+ await flush();
680
+ expect(settled).toBeUndefined();
681
+
682
+ await advanceUntil(() => !!settled, ANDROID_LINK_DROP_QUIET_MS);
683
+ await acquire;
684
+ expect(settled).toMatchObject({ errorCode: HardwareErrorCode.BleConnectedError });
685
+ expect(device.discoverAllServicesAndCharacteristics).not.toHaveBeenCalled();
686
+ });
687
+
688
+ test('a slow but successful MTU exchange completes inside the bound', async () => {
689
+ Object.assign(Platform, { OS: 'android' });
690
+ const { transport, device } = createHarness(() => Promise.resolve(device));
691
+ device.isConnected.mockResolvedValue(true);
692
+ const negotiated = { ...device, mtu: 247 };
693
+ Object.assign(device, {
694
+ mtu: 23,
695
+ // A cold cache makes the stack discover first; the exchange then completes late.
696
+ requestMTU: jest.fn(
697
+ () =>
698
+ new Promise(resolve => {
699
+ setTimeout(() => resolve(negotiated), 10_000);
700
+ })
701
+ ),
702
+ });
703
+ const [, notifyCharacteristic] = await device.characteristicsForService();
704
+ Object.assign(notifyCharacteristic, { monitor: jest.fn(() => ({ remove: jest.fn() })) });
705
+ let result: unknown;
706
+ let failure: Error | undefined;
707
+ const acquire = transport.acquire({ uuid: UUID, expectedProtocol: 'V1' }).then(
708
+ value => {
709
+ result = value;
710
+ },
711
+ error => {
712
+ failure = error;
713
+ }
714
+ );
715
+ await flush();
716
+ await flush();
717
+ expect(device.discoverAllServicesAndCharacteristics).not.toHaveBeenCalled();
718
+
719
+ jest.advanceTimersByTime(10_000);
720
+ await advanceUntil(() => result !== undefined || failure !== undefined, 5000);
721
+ await acquire;
722
+ expect(failure).toBeUndefined();
723
+ expect(result).toEqual({ uuid: UUID, protocolType: 'V1' });
724
+ expect(device.discoverAllServicesAndCharacteristics).toHaveBeenCalledTimes(1);
725
+ await transport.release(UUID, true);
726
+ });
643
727
  });