@onekeyfe/hd-transport-react-native 1.2.8-alpha.12 → 1.2.8-alpha.120

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as transport from '@onekeyfe/hd-transport';
2
- import transport__default, { ProtocolType, OneKeyDeviceInfoBase, TransportCallOptions } from '@onekeyfe/hd-transport';
2
+ import transport__default, { ProtocolType, OneKeyDeviceInfoBase, OneKeyMobileDeviceInfo, TransportCallOptions } from '@onekeyfe/hd-transport';
3
3
  import { Device, Characteristic, Subscription, BleManager } from 'react-native-ble-plx';
4
4
  import { Deferred } from '@onekeyfe/hd-shared';
5
5
  import EventEmitter from 'events';
@@ -67,12 +67,24 @@ declare const BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
67
67
  type ProtocolV2BleTuning = {
68
68
  iosPacketLength?: number;
69
69
  androidPacketLength?: number;
70
+ /**
71
+ * Write each multi-packet high-throughput frame with one native call when the native
72
+ * BLE module supports it. Defaults to true; false keeps the per-packet JS write loop.
73
+ */
74
+ nativeFrameWrite?: boolean;
75
+ /**
76
+ * Android CONNECTION_PRIORITY_HIGH around Protocol V2 high-throughput calls. 'auto' (the
77
+ * default) requests it below Android 17 only; true or false forces it on every version.
78
+ */
79
+ androidHighConnectionPriority?: boolean | 'auto';
70
80
  };
71
81
  declare function configureProtocolV2BleTuning(tuning?: ProtocolV2BleTuning): void;
72
82
  declare function resetProtocolV2BleTuning(): void;
73
83
  declare function getProtocolV2BleTuning(): {
74
84
  iosPacketLength: number;
75
85
  androidPacketLength: number;
86
+ nativeFrameWrite: boolean;
87
+ androidHighConnectionPriority: boolean | "auto";
76
88
  };
77
89
  /**
78
90
  * With no cached GATT table the stack runs its own discovery (up to ~8s) before the MTU
@@ -110,7 +122,7 @@ declare const PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = 3;
110
122
  /** BLE setup timeouts since the last successful setup before the manager is recreated. */
111
123
  declare const BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = 2;
112
124
  declare const BLE_SETUP_WEDGED_MESSAGE = "BLE setup wedged repeatedly";
113
- type IOneKeyDevice = OneKeyDeviceInfoBase & Device;
125
+ type IOneKeyDevice = OneKeyDeviceInfoBase & Device & Pick<OneKeyMobileDeviceInfo, 'bleColorCode'>;
114
126
  declare class ReactNativeBleTransport {
115
127
  blePlxManager: BleManager | undefined;
116
128
  _messages: ReturnType<typeof transport__default.parseConfigure> | undefined;
@@ -158,6 +170,10 @@ declare class ReactNativeBleTransport {
158
170
  private protocolV2HighVolumeLogSignatures;
159
171
  private androidHighPriorityDevices;
160
172
  private androidPriorityResetTimers;
173
+ /** In-flight native frame write per device; Protocol V2 writes are serialized per device. */
174
+ private protocolV2FrameWrites;
175
+ private protocolV2FrameWriteCounter;
176
+ private protocolV2FileWritePerfs;
161
177
  private nextMonitorToken;
162
178
  /** Serializes transport lifecycle changes for the same physical device. */
163
179
  private lifecycleOperations;
@@ -259,6 +275,25 @@ declare class ReactNativeBleTransport {
259
275
  private readProtocolV2Frame;
260
276
  private writeProtocolV2Packet;
261
277
  private writeProtocolV2Frame;
278
+ /**
279
+ * The native frame write only replaces the per-packet loop where its JS<->native round trips
280
+ * dominate: multi-packet (checked by the caller) high-throughput frames written without response.
281
+ */
282
+ private resolveProtocolV2NativeFrameWriter;
283
+ /**
284
+ * Writes one frame with a single native call that sends its packets in order without response.
285
+ * Nothing here retries it: a resend could duplicate bytes the device already received. The
286
+ * native transaction is cancelled on abort, watchdog expiry and link teardown so the native
287
+ * side stops writing a frame nobody waits for any more; a generation change detected after
288
+ * the frame completes still fails the write.
289
+ */
290
+ private writeProtocolV2NativeFrame;
291
+ /** Stops the native frame write in flight on `uuid`, optionally only one of `generation`. */
292
+ private cancelProtocolV2FrameWrite;
293
+ private cancelNativeTransaction;
294
+ private getProtocolV2FileWritePerf;
295
+ /** Returns true the first time `signature` is seen for `uuid` on this link. */
296
+ private markProtocolV2LogSignature;
262
297
  private callProtocolV2;
263
298
  private ensureProtocolV2HighThroughputMtu;
264
299
  private clearAndroidPriorityResetTimer;
@@ -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;AA2BhC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEjE,KAAK,8BAA8B,GAAG,eAAe,GAAG;IAMtD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAkBF,KAAK,4BAA4B,GAAG,WAAW,CAAC;AAChD,KAAK,0BAA0B,GAAG;IAChC,mBAAmB,EAAE,cAAc,CAAC;IACpC,oBAAoB,EAAE,cAAc,CAAC;CACtC,CAAC;AAkCF,eAAO,MAAM,+BAA+B,UACnC,OAAO,KACb,4BAA4B,GAAG,IAsBjC,CAAC;AAcF,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAClD,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AAuBpD,eAAO,MAAM,yCAAyC,IAAI,CAAC;AAI3D,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAiBF,wBAAgB,4BAA4B,CA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C,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;YAShB,mBAAmB;YAiBnB,qBAAqB;YA8DrB,oBAAoB;IA2DlC,OAAO,CAAC,kCAAkC;YA2B5B,0BAA0B;IA+FxC,OAAO,CAAC,0BAA0B;IAMlC,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,0BAA0B;IAOlC,OAAO,CAAC,0BAA0B;YAQpB,cAAc;YAmHd,iCAAiC;IAsB/C,OAAO,CAAC,8BAA8B;YAQxB,mCAAmC;IA+BjD,OAAO,CAAC,yCAAyC;YAanC,gCAAgC;IAoB9C,OAAO,CAAC,uBAAuB;IAwD/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.js CHANGED
@@ -383,6 +383,7 @@ const WEDGED_WRITE_MESSAGE = 'BLE write timeout after';
383
383
  const isWedgedWriteError = (error) => (error === null || error === void 0 ? void 0 : error.errorCode) === hdShared.HardwareErrorCode.BleWriteCharacteristicError &&
384
384
  typeof (error === null || error === void 0 ? void 0 : error.message) === 'string' &&
385
385
  error.message.startsWith(WEDGED_WRITE_MESSAGE);
386
+ const createWedgedWriteError = () => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError, `${WEDGED_WRITE_MESSAGE} ${BLE_WRITE_PACKET_TIMEOUT_MS}ms`);
386
387
  const shouldRethrowProtocolProbeError = (error) => {
387
388
  const code = error === null || error === void 0 ? void 0 : error.errorCode;
388
389
  return (isNativeBleDisconnectError(error) ||
@@ -400,6 +401,8 @@ const ANDROID_NOTIFY_READY_DELAY_MS = 300;
400
401
  const DEFAULT_PROTOCOL_V2_BLE_TUNING = {
401
402
  iosPacketLength: IOS_PROTOCOL_V2_PACKET_LENGTH,
402
403
  androidPacketLength: ANDROID_PROTOCOL_V2_PACKET_LENGTH,
404
+ nativeFrameWrite: true,
405
+ androidHighConnectionPriority: 'auto',
403
406
  };
404
407
  let protocolV2BleTuning = Object.assign({}, DEFAULT_PROTOCOL_V2_BLE_TUNING);
405
408
  const normalizePositiveInteger = (value, fallback) => {
@@ -412,6 +415,13 @@ function configureProtocolV2BleTuning(tuning = {}) {
412
415
  protocolV2BleTuning = {
413
416
  iosPacketLength: normalizePositiveInteger(tuning.iosPacketLength, protocolV2BleTuning.iosPacketLength),
414
417
  androidPacketLength: normalizePositiveInteger(tuning.androidPacketLength, protocolV2BleTuning.androidPacketLength),
418
+ nativeFrameWrite: typeof tuning.nativeFrameWrite === 'boolean'
419
+ ? tuning.nativeFrameWrite
420
+ : protocolV2BleTuning.nativeFrameWrite,
421
+ androidHighConnectionPriority: typeof tuning.androidHighConnectionPriority === 'boolean' ||
422
+ tuning.androidHighConnectionPriority === 'auto'
423
+ ? tuning.androidHighConnectionPriority
424
+ : protocolV2BleTuning.androidHighConnectionPriority,
415
425
  };
416
426
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE tuning configured', protocolV2BleTuning);
417
427
  }
@@ -422,12 +432,128 @@ function resetProtocolV2BleTuning() {
422
432
  function getProtocolV2BleTuning() {
423
433
  return Object.assign({}, protocolV2BleTuning);
424
434
  }
435
+ const getProtocolV2NativeFrameWriter = (manager) => {
436
+ var _a;
437
+ const candidate = manager;
438
+ if (!candidate || typeof candidate.writeCharacteristicWithoutResponseFrame !== 'function') {
439
+ return undefined;
440
+ }
441
+ try {
442
+ return ((_a = candidate.isWriteCharacteristicWithoutResponseFrameSupported) === null || _a === void 0 ? void 0 : _a.call(candidate)) === true
443
+ ? candidate
444
+ : undefined;
445
+ }
446
+ catch (_b) {
447
+ return undefined;
448
+ }
449
+ };
450
+ const getNativeBleErrorReason = (error) => {
451
+ const { reason, message } = (error !== null && error !== void 0 ? error : {});
452
+ if (typeof reason === 'string' && reason)
453
+ return reason;
454
+ return typeof message === 'string' && message ? message : undefined;
455
+ };
456
+ const nowMs = () => typeof performance !== 'undefined' && typeof performance.now === 'function'
457
+ ? performance.now()
458
+ : Date.now();
459
+ const roundMs = (ms) => Math.round(ms * 10) / 10;
460
+ const FILE_WRITE_PACKET_HISTOGRAM_BOUNDS_MS = [1, 2, 3, 5, 8];
461
+ const createDurationStats = () => {
462
+ let total = 0;
463
+ let count = 0;
464
+ let max = 0;
465
+ return {
466
+ add(ms) {
467
+ total += ms;
468
+ count += 1;
469
+ max = Math.max(max, ms);
470
+ },
471
+ summarize: () => ({
472
+ total: roundMs(total),
473
+ avg: count ? roundMs(total / count) : 0,
474
+ max: roundMs(max),
475
+ }),
476
+ };
477
+ };
478
+ const createProtocolV2FileWritePerf = () => {
479
+ const startedAt = nowMs();
480
+ let nativeFrames = 0;
481
+ let frames = 0;
482
+ let packets = 0;
483
+ let frameBytes = 0;
484
+ const write = createDurationStats();
485
+ const readWait = createDurationStats();
486
+ const packet = createDurationStats();
487
+ const packetHistogram = Array.from({ length: FILE_WRITE_PACKET_HISTOGRAM_BOUNDS_MS.length + 1 }, () => 0);
488
+ return {
489
+ startFrame(mode) {
490
+ if (mode === 'native-frame')
491
+ nativeFrames += 1;
492
+ },
493
+ recordFrame(bytes, framePackets, elapsedMs) {
494
+ frames += 1;
495
+ packets += framePackets;
496
+ frameBytes += bytes;
497
+ write.add(elapsedMs);
498
+ },
499
+ recordPacket(elapsedMs) {
500
+ packet.add(elapsedMs);
501
+ const bucket = FILE_WRITE_PACKET_HISTOGRAM_BOUNDS_MS.findIndex(bound => elapsedMs < bound);
502
+ packetHistogram[bucket < 0 ? packetHistogram.length - 1 : bucket] += 1;
503
+ },
504
+ recordReadWait(elapsedMs) {
505
+ readWait.add(elapsedMs);
506
+ },
507
+ summarize(ok) {
508
+ const mode = nativeFrames > 0 ? 'native-frame' : 'per-packet';
509
+ const packetStats = packet.summarize();
510
+ return Object.assign({ platform: reactNative.Platform.OS, mode,
511
+ ok,
512
+ frames,
513
+ packets,
514
+ frameBytes, elapsedMs: roundMs(nowMs() - startedAt), writeMs: write.summarize(), readWaitMs: readWait.summarize() }, (mode === 'per-packet'
515
+ ? { packetMs: { avg: packetStats.avg, max: packetStats.max, hist: [...packetHistogram] } }
516
+ : {}));
517
+ },
518
+ };
519
+ };
425
520
  function getDeviceDisplayName(device) {
426
521
  return (device === null || device === void 0 ? void 0 : device.name) || (device === null || device === void 0 ? void 0 : device.localName) || null;
427
522
  }
523
+ const bleColorCodesById = new Map();
524
+ function getManufacturerDataLength(device) {
525
+ return (device === null || device === void 0 ? void 0 : device.manufacturerData) ? buffer.Buffer.from(device.manufacturerData, 'base64').length : 0;
526
+ }
527
+ function rememberBleColorCode(device) {
528
+ if (!(device === null || device === void 0 ? void 0 : device.id) || !device.manufacturerData)
529
+ return;
530
+ const colorCode = hdShared.parseOnekeyBleColorCode(buffer.Buffer.from(device.manufacturerData, 'base64'));
531
+ const key = device.id.toLowerCase();
532
+ if (colorCode && bleColorCodesById.get(key) !== colorCode) {
533
+ bleColorCodesById.set(key, colorCode);
534
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE color code', {
535
+ deviceId: device.id,
536
+ bleColorCode: colorCode,
537
+ });
538
+ }
539
+ }
540
+ function withBleColorCode(device) {
541
+ const bleColorCode = bleColorCodesById.get(device.id.toLowerCase());
542
+ return bleColorCode ? Object.assign(Object.assign({}, device), { bleColorCode }) : device;
543
+ }
428
544
  const IOS_REQUEST_MTU = 247;
429
545
  const ANDROID_REQUEST_MTU = 517;
430
546
  const ANDROID_HIGH_PRIORITY_IDLE_MS = 1000;
547
+ const ANDROID_HIGH_PRIORITY_PERIPHERAL_LATENCY_API_LEVEL = 37;
548
+ const shouldRequestAndroidHighConnectionPriority = () => {
549
+ if (reactNative.Platform.OS !== 'android')
550
+ return false;
551
+ const { androidHighConnectionPriority } = protocolV2BleTuning;
552
+ if (typeof androidHighConnectionPriority === 'boolean')
553
+ return androidHighConnectionPriority;
554
+ const apiLevel = Number(reactNative.Platform.Version);
555
+ return (!Number.isFinite(apiLevel) || apiLevel < ANDROID_HIGH_PRIORITY_PERIPHERAL_LATENCY_API_LEVEL);
556
+ };
431
557
  const getRequestedBleMtu = () => reactNative.Platform.OS === 'android' ? ANDROID_REQUEST_MTU : IOS_REQUEST_MTU;
432
558
  const BLE_NATIVE_CONNECT_TIMEOUT_MS = 3000;
433
559
  const BLE_MTU_REQUEST_TIMEOUT_MS = BLE_NATIVE_CONNECT_TIMEOUT_MS;
@@ -620,6 +746,9 @@ class ReactNativeBleTransport {
620
746
  this.protocolV2HighVolumeLogSignatures = new Map();
621
747
  this.androidHighPriorityDevices = new Set();
622
748
  this.androidPriorityResetTimers = new Map();
749
+ this.protocolV2FrameWrites = new Map();
750
+ this.protocolV2FrameWriteCounter = 0;
751
+ this.protocolV2FileWritePerfs = new Map();
623
752
  this.nextMonitorToken = 1;
624
753
  this.lifecycleOperations = new Map();
625
754
  this.scanCleanups = new Set();
@@ -881,7 +1010,7 @@ class ReactNativeBleTransport {
881
1010
  if (error)
882
1011
  reject(error);
883
1012
  else
884
- resolve(deviceList);
1013
+ resolve(deviceList.map(withBleColorCode));
885
1014
  });
886
1015
  return scanCleanup;
887
1016
  };
@@ -921,6 +1050,7 @@ class ReactNativeBleTransport {
921
1050
  }
922
1051
  return;
923
1052
  }
1053
+ rememberBleColorCode(device);
924
1054
  const displayName = getDeviceDisplayName(device);
925
1055
  const isUnnamedIOSPeripheral = reactNative.Platform.OS === 'ios' && !(displayName === null || displayName === void 0 ? void 0 : displayName.trim());
926
1056
  const isOneKey = !isUnnamedIOSPeripheral &&
@@ -970,6 +1100,8 @@ class ReactNativeBleTransport {
970
1100
  deviceId: device.id,
971
1101
  name: displayName,
972
1102
  serviceUUIDs: device.serviceUUIDs,
1103
+ manufacturerDataLength: getManufacturerDataLength(device),
1104
+ bleColorCode: bleColorCodesById.get(device.id.toLowerCase()),
973
1105
  });
974
1106
  }
975
1107
  };
@@ -1418,13 +1550,16 @@ class ReactNativeBleTransport {
1418
1550
  }
1419
1551
  releaseUnlocked(uuid, onclose = false) {
1420
1552
  return __awaiter(this, void 0, void 0, function* () {
1421
- yield this.protocolV2Links.invalidateLink(uuid, 'React Native BLE transport released');
1553
+ const reason = 'React Native BLE transport released';
1554
+ this.cancelProtocolV2FrameWrite(uuid, new Error(reason));
1555
+ yield this.protocolV2Links.invalidateLink(uuid, reason);
1422
1556
  return this.releaseNative(uuid, onclose);
1423
1557
  });
1424
1558
  }
1425
1559
  releaseNative(uuid, onclose = false) {
1426
1560
  var _a, _b, _c, _d, _e;
1427
1561
  return __awaiter(this, void 0, void 0, function* () {
1562
+ this.cancelProtocolV2FrameWrite(uuid, new Error('React Native BLE transport released'));
1428
1563
  const transport = transportCache[uuid];
1429
1564
  const manager = this.blePlxManager;
1430
1565
  if (this.runPromise && this.runPromiseDeviceId === uuid) {
@@ -1751,7 +1886,11 @@ class ReactNativeBleTransport {
1751
1886
  disconnectUnlocked(session) {
1752
1887
  var _a, _b, _c;
1753
1888
  return __awaiter(this, void 0, void 0, function* () {
1754
- yield this.protocolV2Links.invalidateLink(session, 'React Native BLE transport disconnected');
1889
+ this.clearAndroidPriorityResetTimer(session);
1890
+ this.androidHighPriorityDevices.delete(session);
1891
+ const reason = 'React Native BLE transport disconnected';
1892
+ this.cancelProtocolV2FrameWrite(session, new Error(reason));
1893
+ yield this.protocolV2Links.invalidateLink(session, reason);
1755
1894
  const transport = transportCache[session];
1756
1895
  const manager = this.blePlxManager;
1757
1896
  const monitorToken = (_a = transport === null || transport === void 0 ? void 0 : transport.monitorToken) !== null && _a !== void 0 ? _a : this.monitorTokens.get(session);
@@ -2090,7 +2229,7 @@ class ReactNativeBleTransport {
2090
2229
  new Promise((_, reject) => {
2091
2230
  timer = setTimeout(() => {
2092
2231
  timedOut = true;
2093
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError, `BLE write timeout after ${BLE_WRITE_PACKET_TIMEOUT_MS}ms`));
2232
+ reject(createWedgedWriteError());
2094
2233
  }, BLE_WRITE_PACKET_TIMEOUT_MS);
2095
2234
  }),
2096
2235
  ]);
@@ -2120,6 +2259,7 @@ class ReactNativeBleTransport {
2120
2259
  Log === null || Log === void 0 ? void 0 : Log.error('[ReactNativeBleTransport] BLE write timed out, tearing down link:', uuid, {
2121
2260
  consecutiveWriteTimeouts: timeouts,
2122
2261
  });
2262
+ this.cancelProtocolV2FrameWrite(uuid, createWedgedWriteError());
2123
2263
  const wedged = transportCache[uuid];
2124
2264
  this.disconnect(uuid).catch(error => {
2125
2265
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] wedged link teardown failed (ignored):', error);
@@ -2143,6 +2283,7 @@ class ReactNativeBleTransport {
2143
2283
  const manager = this.blePlxManager;
2144
2284
  this.blePlxManager = undefined;
2145
2285
  const reason = 'React Native BLE manager reset';
2286
+ this.protocolV2FrameWrites.forEach(active => active.cancel(new Error(reason)));
2146
2287
  Object.entries(transportCache).forEach(([uuid, cachedTransport]) => {
2147
2288
  var _a, _b, _c, _d;
2148
2289
  try {
@@ -2196,10 +2337,12 @@ class ReactNativeBleTransport {
2196
2337
  });
2197
2338
  }
2198
2339
  createProtocolMismatchError(expected) {
2199
- return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
2340
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportProtocolProbeFailed, undefined, {
2341
+ expectedProtocol: expected,
2342
+ });
2200
2343
  }
2201
2344
  createProtocolDetectionError() {
2202
- return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'Unable to detect BLE protocol: device did not respond to Protocol V1 GetFeatures or Protocol V2 Ping');
2345
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportProtocolProbeFailed);
2203
2346
  }
2204
2347
  clearProbeProtocol(uuid, protocol) {
2205
2348
  if (this.probingProtocols.get(uuid) === protocol) {
@@ -2530,19 +2673,162 @@ class ReactNativeBleTransport {
2530
2673
  androidPacketLength: tuning.androidPacketLength,
2531
2674
  mtu: transport$1.mtuSize,
2532
2675
  });
2533
- yield transport.writeProtocolV2BleFrame({
2534
- frame,
2535
- packetCapacity,
2536
- assertActive: assertCurrentGeneration,
2537
- signal: context.signal,
2538
- abortMessage: `Protocol V2 BLE write aborted for ${context.messageName}`,
2539
- wait: delay,
2540
- writePacket: packet => this.writeProtocolV2Packet(uuid, transport$1, buffer.Buffer.from(packet).toString('base64'), context, assertCurrentGeneration),
2676
+ const perf = this.getProtocolV2FileWritePerf(uuid, context);
2677
+ const startedAt = perf ? nowMs() : 0;
2678
+ const nativeFrameWriter = frame.length > packetCapacity
2679
+ ? this.resolveProtocolV2NativeFrameWriter(transport$1, context, tuning.nativeFrameWrite)
2680
+ : undefined;
2681
+ perf === null || perf === void 0 ? void 0 : perf.startFrame(nativeFrameWriter ? 'native-frame' : 'per-packet');
2682
+ if (nativeFrameWriter) {
2683
+ yield this.writeProtocolV2NativeFrame(uuid, transport$1, nativeFrameWriter, frame, packetCapacity, context, assertCurrentGeneration);
2684
+ }
2685
+ else {
2686
+ yield transport.writeProtocolV2BleFrame({
2687
+ frame,
2688
+ packetCapacity,
2689
+ assertActive: assertCurrentGeneration,
2690
+ signal: context.signal,
2691
+ abortMessage: `Protocol V2 BLE write aborted for ${context.messageName}`,
2692
+ wait: delay,
2693
+ writePacket: (packet) => __awaiter(this, void 0, void 0, function* () {
2694
+ const packetStartedAt = perf ? nowMs() : 0;
2695
+ yield this.writeProtocolV2Packet(uuid, transport$1, buffer.Buffer.from(packet).toString('base64'), context, assertCurrentGeneration);
2696
+ perf === null || perf === void 0 ? void 0 : perf.recordPacket(nowMs() - packetStartedAt);
2697
+ }),
2698
+ });
2699
+ }
2700
+ perf === null || perf === void 0 ? void 0 : perf.recordFrame(frame.length, Math.ceil(frame.length / packetCapacity), nowMs() - startedAt);
2701
+ });
2702
+ }
2703
+ resolveProtocolV2NativeFrameWriter(transport, context, nativeFrameWrite) {
2704
+ if (!context.highThroughput || !nativeFrameWrite)
2705
+ return undefined;
2706
+ if (shouldWriteProtocolV2WithResponse({
2707
+ platform: reactNative.Platform.OS,
2708
+ highThroughput: context.highThroughput,
2709
+ requestedWithResponse: context.writeWithResponse,
2710
+ characteristic: transport.writeCharacteristic,
2711
+ })) {
2712
+ return undefined;
2713
+ }
2714
+ if (typeof transport.writeCharacteristic.id !== 'number')
2715
+ return undefined;
2716
+ return getProtocolV2NativeFrameWriter(this.blePlxManager);
2717
+ }
2718
+ writeProtocolV2NativeFrame(uuid, transport, manager, frame, packetCapacity, context, assertCurrentGeneration) {
2719
+ return __awaiter(this, void 0, void 0, function* () {
2720
+ const abortMessage = `Protocol V2 BLE write aborted for ${context.messageName}`;
2721
+ assertCurrentGeneration();
2722
+ if (context.signal.aborted) {
2723
+ throw new Error(abortMessage);
2724
+ }
2725
+ this.protocolV2FrameWriteCounter += 1;
2726
+ const transactionId = `${uuid}:v2frame:${context.generation}:${this.protocolV2FrameWriteCounter}`;
2727
+ let cancelError;
2728
+ let rejectCancelled = () => undefined;
2729
+ const cancelled = new Promise((_, reject) => {
2730
+ rejectCancelled = reject;
2541
2731
  });
2732
+ const active = {
2733
+ generation: context.generation,
2734
+ cancel: error => {
2735
+ if (cancelError)
2736
+ return;
2737
+ cancelError = error;
2738
+ if (this.protocolV2FrameWrites.get(uuid) === active) {
2739
+ this.protocolV2FrameWrites.delete(uuid);
2740
+ }
2741
+ rejectCancelled(error);
2742
+ this.cancelNativeTransaction(manager, transactionId);
2743
+ },
2744
+ };
2745
+ const isCurrentOwner = () => {
2746
+ try {
2747
+ assertCurrentGeneration();
2748
+ return !context.signal.aborted;
2749
+ }
2750
+ catch (_a) {
2751
+ return false;
2752
+ }
2753
+ };
2754
+ const onAbort = () => active.cancel(new Error(abortMessage));
2755
+ let timer;
2756
+ try {
2757
+ const nativeWrite = Promise.resolve(manager.writeCharacteristicWithoutResponseFrame(transport.writeCharacteristic.id, buffer.Buffer.from(frame).toString('base64'), packetCapacity, transactionId));
2758
+ nativeWrite.catch(() => undefined);
2759
+ this.protocolV2FrameWrites.set(uuid, active);
2760
+ context.signal.addEventListener('abort', onAbort);
2761
+ timer = setTimeout(() => {
2762
+ const owner = isCurrentOwner();
2763
+ active.cancel(createWedgedWriteError());
2764
+ if (owner) {
2765
+ this.tearDownWedgedLink(uuid);
2766
+ }
2767
+ else {
2768
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] stale BLE frame write timed out, link kept');
2769
+ }
2770
+ }, BLE_WRITE_PACKET_TIMEOUT_MS);
2771
+ yield Promise.race([nativeWrite, cancelled]);
2772
+ }
2773
+ catch (error) {
2774
+ if (cancelError)
2775
+ throw cancelError;
2776
+ if (isNativeBleDisconnectError(error)) {
2777
+ throw toBleDisconnectHardwareError(error);
2778
+ }
2779
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError, getNativeBleErrorReason(error));
2780
+ }
2781
+ finally {
2782
+ if (timer)
2783
+ clearTimeout(timer);
2784
+ context.signal.removeEventListener('abort', onAbort);
2785
+ if (this.protocolV2FrameWrites.get(uuid) === active) {
2786
+ this.protocolV2FrameWrites.delete(uuid);
2787
+ }
2788
+ }
2789
+ this.writeTimeoutCounts.delete(uuid);
2790
+ try {
2791
+ assertCurrentGeneration();
2792
+ }
2793
+ catch (error) {
2794
+ active.cancel(error instanceof Error ? error : new Error(String(error)));
2795
+ }
2796
+ if (cancelError)
2797
+ throw cancelError;
2542
2798
  });
2543
2799
  }
2544
- callProtocolV2(uuid, name, data, options) {
2800
+ cancelProtocolV2FrameWrite(uuid, error, generation) {
2801
+ const active = this.protocolV2FrameWrites.get(uuid);
2802
+ if (!active || (generation !== undefined && active.generation !== generation))
2803
+ return;
2804
+ active.cancel(error);
2805
+ }
2806
+ cancelNativeTransaction(manager, transactionId) {
2807
+ const logFailure = (error) => Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 frame write cancellation failed', {
2808
+ error: error instanceof Error ? error.message : String(error),
2809
+ });
2810
+ try {
2811
+ Promise.resolve(manager.cancelTransaction(transactionId)).catch(logFailure);
2812
+ }
2813
+ catch (error) {
2814
+ logFailure(error);
2815
+ }
2816
+ }
2817
+ getProtocolV2FileWritePerf(uuid, context) {
2818
+ return context.messageName === 'FilesystemFileWrite'
2819
+ ? this.protocolV2FileWritePerfs.get(uuid)
2820
+ : undefined;
2821
+ }
2822
+ markProtocolV2LogSignature(uuid, signature) {
2545
2823
  var _a;
2824
+ const signatures = (_a = this.protocolV2HighVolumeLogSignatures.get(uuid)) !== null && _a !== void 0 ? _a : new Set();
2825
+ if (signatures.has(signature))
2826
+ return false;
2827
+ signatures.add(signature);
2828
+ this.protocolV2HighVolumeLogSignatures.set(uuid, signatures);
2829
+ return true;
2830
+ }
2831
+ callProtocolV2(uuid, name, data, options) {
2546
2832
  return __awaiter(this, void 0, void 0, function* () {
2547
2833
  if (!this._messages || !this._messagesV2) {
2548
2834
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
@@ -2568,10 +2854,7 @@ class ReactNativeBleTransport {
2568
2854
  });
2569
2855
  const writeMode = writeWithResponse ? 'withResponse' : 'withoutResponse';
2570
2856
  const logSignature = `${name}:${writeMode}:${String(currentTransport.mtuSize)}:${packetCapacity}`;
2571
- const loggedSignatures = (_a = this.protocolV2HighVolumeLogSignatures.get(uuid)) !== null && _a !== void 0 ? _a : new Set();
2572
- if (!loggedSignatures.has(logSignature)) {
2573
- loggedSignatures.add(logSignature);
2574
- this.protocolV2HighVolumeLogSignatures.set(uuid, loggedSignatures);
2857
+ if (this.markProtocolV2LogSignature(uuid, logSignature)) {
2575
2858
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 high-volume write configured', {
2576
2859
  name,
2577
2860
  writeMode,
@@ -2579,12 +2862,33 @@ class ReactNativeBleTransport {
2579
2862
  packetCapacity,
2580
2863
  });
2581
2864
  }
2865
+ const frameWriteMode = this.resolveProtocolV2NativeFrameWriter(currentTransport, { highThroughput: true, writeWithResponse: options === null || options === void 0 ? void 0 : options.writeWithResponse }, tuning.nativeFrameWrite)
2866
+ ? 'native-frame'
2867
+ : 'per-packet';
2868
+ if (this.markProtocolV2LogSignature(uuid, `frameWriteMode:${frameWriteMode}`)) {
2869
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V2 frame write mode', {
2870
+ platform: reactNative.Platform.OS,
2871
+ mode: frameWriteMode,
2872
+ nativeFrameWrite: tuning.nativeFrameWrite,
2873
+ nativeFrameWriteSupported: !!getProtocolV2NativeFrameWriter(this.blePlxManager),
2874
+ packetCapacity,
2875
+ });
2876
+ }
2582
2877
  }
2583
2878
  if (highThroughputWrite) {
2584
2879
  yield this.enableAndroidHighConnectionPriority(uuid);
2585
2880
  }
2881
+ const fileWritePerf = name === 'FilesystemFileWrite' && (options === null || options === void 0 ? void 0 : options.fileWritePipeline)
2882
+ ? createProtocolV2FileWritePerf()
2883
+ : undefined;
2884
+ if (fileWritePerf) {
2885
+ this.protocolV2FileWritePerfs.set(uuid, fileWritePerf);
2886
+ }
2887
+ let fileWriteOk = false;
2586
2888
  try {
2587
- return yield this.protocolV2Links.call(uuid, () => this.createProtocolV2Adapter(uuid), name, data, callOptions);
2889
+ const response = yield this.protocolV2Links.call(uuid, () => this.createProtocolV2Adapter(uuid), name, data, callOptions);
2890
+ fileWriteOk = response.type !== 'Failure';
2891
+ return response;
2588
2892
  }
2589
2893
  catch (e) {
2590
2894
  Log === null || Log === void 0 ? void 0 : Log.error('[ReactNativeBleTransport] Protocol V2 call error:', e);
@@ -2602,6 +2906,12 @@ class ReactNativeBleTransport {
2602
2906
  if (highThroughputWrite) {
2603
2907
  this.scheduleAndroidBalancedConnectionPriority(uuid);
2604
2908
  }
2909
+ if (fileWritePerf) {
2910
+ if (this.protocolV2FileWritePerfs.get(uuid) === fileWritePerf) {
2911
+ this.protocolV2FileWritePerfs.delete(uuid);
2912
+ }
2913
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] FileWrite perf', fileWritePerf.summarize(fileWriteOk));
2914
+ }
2605
2915
  }
2606
2916
  });
2607
2917
  }
@@ -2633,6 +2943,15 @@ class ReactNativeBleTransport {
2633
2943
  this.clearAndroidPriorityResetTimer(uuid);
2634
2944
  if (this.androidHighPriorityDevices.has(uuid))
2635
2945
  return;
2946
+ if (!shouldRequestAndroidHighConnectionPriority()) {
2947
+ if (this.markProtocolV2LogSignature(uuid, 'androidPriority:peripheral')) {
2948
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Android BLE connection priority left to peripheral', {
2949
+ apiLevel: reactNative.Platform.Version,
2950
+ setting: protocolV2BleTuning.androidHighConnectionPriority,
2951
+ });
2952
+ }
2953
+ return;
2954
+ }
2636
2955
  const transport = transportCache[uuid];
2637
2956
  if (!transport)
2638
2957
  return;
@@ -2702,9 +3021,12 @@ class ReactNativeBleTransport {
2702
3021
  const currentTransport = this.getCachedTransport(uuid);
2703
3022
  yield this.writeProtocolV2Frame(uuid, currentTransport, frame, context, assertCurrentGeneration);
2704
3023
  }),
2705
- readFrame: () => __awaiter(this, void 0, void 0, function* () {
3024
+ readFrame: (context) => __awaiter(this, void 0, void 0, function* () {
2706
3025
  assertCurrentGeneration();
3026
+ const perf = this.getProtocolV2FileWritePerf(uuid, context);
3027
+ const startedAt = perf ? nowMs() : 0;
2707
3028
  const rxFrame = yield this.readProtocolV2Frame(uuid);
3029
+ perf === null || perf === void 0 ? void 0 : perf.recordReadWait(nowMs() - startedAt);
2708
3030
  if (!(rxFrame instanceof Uint8Array)) {
2709
3031
  throw new Error('Protocol V2 response is not Uint8Array');
2710
3032
  }
@@ -2712,6 +3034,7 @@ class ReactNativeBleTransport {
2712
3034
  }),
2713
3035
  reset: (reason) => {
2714
3036
  var _a;
3037
+ this.cancelProtocolV2FrameWrite(uuid, new Error(reason), generation);
2715
3038
  if (this.monitorTokens.get(uuid) !== generation)
2716
3039
  return;
2717
3040
  (_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.8-alpha.12",
3
+ "version": "1.2.8-alpha.120",
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.8-alpha.12",
24
- "@onekeyfe/hd-shared": "1.2.8-alpha.12",
25
- "@onekeyfe/hd-transport": "1.2.8-alpha.12",
23
+ "@onekeyfe/hd-core": "1.2.8-alpha.120",
24
+ "@onekeyfe/hd-shared": "1.2.8-alpha.120",
25
+ "@onekeyfe/hd-transport": "1.2.8-alpha.120",
26
26
  "@onekeyfe/react-native-ble-utils": "0.1.9",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "69c7334a3d32e0b55f1b8e57420754fdb5fcd645"
29
+ "gitHead": "55dea2982ecb17d1699b0226690b4ee3795e97a6"
30
30
  }