@onekeyfe/hd-transport-react-native 1.2.2-alpha.115 → 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 CHANGED
@@ -74,6 +74,16 @@ declare function getProtocolV2BleTuning(): {
74
74
  iosPacketLength: number;
75
75
  androidPacketLength: number;
76
76
  };
77
+ /**
78
+ * With no cached GATT table the stack runs its own discovery (up to ~8s) before the MTU
79
+ * exchange, so the bound sits above that; a stuck exchange never completes.
80
+ */
81
+ declare const ANDROID_MTU_EXCHANGE_TIMEOUT_MS = 12000;
82
+ /**
83
+ * Android keeps an LE link, with per-link ATT state such as a pending MTU exchange, for its
84
+ * 4s GATT link idle timer after the last client closes; a reconnect inside it reuses the link.
85
+ */
86
+ declare const ANDROID_LINK_DROP_QUIET_MS = 5000;
77
87
  /**
78
88
  * JS backstop for connect. The native adapter applies its own 3s budget, but it
79
89
  * schedules that timeout on its serial queue, so a busy queue (e.g. right after a
@@ -135,15 +145,10 @@ declare class ReactNativeBleTransport {
135
145
  private confirmedProtocolV2;
136
146
  /** Consecutive detections that failed while trusting sessionProtocols. */
137
147
  private protocolReprobeFailures;
138
- /** Endpoints whose last detection got no answer on any protocol. */
148
+ /** Endpoints whose last detection got no answer; 'woken' once their Initialize wake is spent. */
139
149
  private silentDetections;
140
- /**
141
- * Endpoints already sent a Protocol V1 wake. The wake starts a fresh wallet session
142
- * on the device, and a failed detection tears the link down and reconnects on every
143
- * poll, so neither set is cleared on teardown: one wake is spent per endpoint until a
144
- * detection succeeds, which re-arms it for the next time the device sleeps.
145
- */
146
- private protocolWakeAttempts;
150
+ /** Android endpoints whose cached GATT table is suspect; the next connect refreshes it. */
151
+ private androidGattCacheRefreshes;
147
152
  /**
148
153
  * Native encryption/pairing failures seen before Protocol V2 probe starts.
149
154
  * Pro2/Neo GATT connect can succeed on a stale iOS bond; the CCCD write then
@@ -203,6 +208,13 @@ declare class ReactNativeBleTransport {
203
208
  private runBestEffortNativeOperation;
204
209
  private runLifecycleOperation;
205
210
  cancel(): Promise<void>;
211
+ /**
212
+ * Android: request the MTU with nothing queued ahead and never close the client while it is
213
+ * outstanding; a link that times out or stays at MTU 23 is dropped.
214
+ */
215
+ private negotiateAndroidMtu;
216
+ /** Close the client and wait out the link idle timer so the next connect gets a fresh link. */
217
+ private dropAndroidLink;
206
218
  /** Run a native connect under the JS backstop budget. */
207
219
  private connectWithTimeout;
208
220
  /** Resolve the complete GATT shape under a budget so acquire() always settles. */
@@ -238,20 +250,9 @@ declare class ReactNativeBleTransport {
238
250
  private getActiveProtocol;
239
251
  private detectProtocol;
240
252
  /**
241
- * Sent once before probing when the previous detection on this endpoint got no answer
242
- * at all. On Classic-family firmware that silence is also what a sleeping device looks
243
- * like: its BLE co-processor keeps serving connect, GATT and MTU while the main MCU
244
- * sits in the screensaver loop, whose host-message filter accepts only Initialize and
245
- * the *Ack messages. GetFeatures and Ping are dropped there without a reply, so no
246
- * amount of probing can bring the device back.
247
- *
248
- * Initialize is the one message that breaks that loop, but it also starts a fresh
249
- * wallet session, which is why it is not the probe itself — a bare Initialize on every
250
- * acquire would drop a hidden-wallet session before Core can restore it. Requiring a
251
- * fully silent previous detection keeps it to devices with no session left to protect.
252
- *
253
- * The firmware consumes the wake to leave its loop and does not reliably answer it, so
254
- * the result is ignored: the probes that follow are what decide the protocol.
253
+ * A sleeping Classic drops GetFeatures/Ping and only leaves its screensaver on Initialize, which
254
+ * resets the wallet session, so it is sent once after a fully silent detection. The firmware does
255
+ * not reliably answer it, so its timeout must not drop the link.
255
256
  */
256
257
  private wakeSilentProtocolV1Device;
257
258
  private resetProbeStateAfterProtocolProbe;
@@ -277,4 +278,4 @@ declare class ReactNativeBleTransport {
277
278
  getProtocolType(path: string): ProtocolType | undefined;
278
279
  }
279
280
 
280
- export { BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD, BLE_CONNECT_TIMEOUT_MS, BLE_GATT_SETUP_TIMEOUT_MS, BLE_NATIVE_TEARDOWN_TIMEOUT_MS, BLE_SETUP_WEDGED_MESSAGE, BLE_WRITE_PACKET_TIMEOUT_MS, BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD, IOneKeyDevice, PROTOCOL_REPROBE_FALLBACK_ATTEMPTS, ProtocolV2BleTuning, configureProtocolV2BleTuning, ReactNativeBleTransport as default, getFirmwareUploadWriteRetryType, getProtocolV2BleTuning, resetProtocolV2BleTuning };
281
+ export { ANDROID_LINK_DROP_QUIET_MS, ANDROID_MTU_EXCHANGE_TIMEOUT_MS, BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD, BLE_CONNECT_TIMEOUT_MS, BLE_GATT_SETUP_TIMEOUT_MS, BLE_NATIVE_TEARDOWN_TIMEOUT_MS, BLE_SETUP_WEDGED_MESSAGE, BLE_WRITE_PACKET_TIMEOUT_MS, BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD, IOneKeyDevice, PROTOCOL_REPROBE_FALLBACK_ATTEMPTS, ProtocolV2BleTuning, configureProtocolV2BleTuning, ReactNativeBleTransport as default, getFirmwareUploadWriteRetryType, getProtocolV2BleTuning, resetProtocolV2BleTuning };
@@ -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;AAgChC,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,O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qB;IAoB7B,MAAM;YAoBE,mBAAmB;YA4DnB,eAAe;YA6Bf,kBAAkB;YAkDlB,iCAAiC;IA2D/C,OAAO,CAAC,wBAAwB;IA0ChC,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,kBAAkB;YAcZ,cAAc;IA8C5B,OAAO,CAAC,kBAAkB;IA+B1B,OAAO,CAAC,eAAe;IAkEvB,OAAO,CAAC,2BAA2B;IASnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;YAIX,cAAc;YAkHd,0BAA0B;YAsB1B,iCAAiC;YAoDjC,eAAe;YAsBf,eAAe;IA4B7B,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;IAS9B,OAAO,CAAC,sBAAsB;IAQ9B,OAAO,CAAC,qBAAqB;YAOf,mBAAmB;YAiBnB,qBAAqB;YAmErB,oBAAoB;YAgCpB,cAAc;YAmFd,iCAAiC;IAsB/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
@@ -432,6 +432,29 @@ const connectOptions = {
432
432
  const fallbackConnectOptions = {
433
433
  timeout: BLE_NATIVE_CONNECT_TIMEOUT_MS,
434
434
  };
435
+ const androidRefreshGattConnectOptions = {
436
+ timeout: BLE_NATIVE_CONNECT_TIMEOUT_MS,
437
+ refreshGatt: 'OnConnected',
438
+ };
439
+ const ANDROID_MTU_EXCHANGE_TIMEOUT_MS = 12000;
440
+ const ANDROID_LINK_DROP_QUIET_MS = 5000;
441
+ const ANDROID_LINK_DROP_POLL_MS = 250;
442
+ const isKnownDefaultMtu = (mtu) => typeof mtu === 'number' && Number.isFinite(mtu) && mtu <= 23;
443
+ const isMissingGattShapeError = (error) => {
444
+ const code = error === null || error === void 0 ? void 0 : error.errorCode;
445
+ const message = error === null || error === void 0 ? void 0 : error.message;
446
+ return (code === hdShared.HardwareErrorCode.BleServiceNotFound ||
447
+ code === hdShared.HardwareErrorCode.BleCharacteristicNotFound ||
448
+ (typeof message === 'string' &&
449
+ (message.includes('BLECharacteristicNotFound') ||
450
+ message.includes('BLECharacteristicNotWritable') ||
451
+ message.includes('BLECharacteristicNotNotifiable'))));
452
+ };
453
+ const isStaleGattTableNotifyReason = (reason) => !!reason &&
454
+ (reason.includes('Cannot write client characteristic config descriptor') ||
455
+ reason.includes('Cannot find client characteristic config descriptor') ||
456
+ reason.includes('The handle is invalid') ||
457
+ reason.includes('Writing is not permitted'));
435
458
  const BLE_CONNECT_TIMEOUT_MS = BLE_NATIVE_CONNECT_TIMEOUT_MS * 2 + 2000;
436
459
  const BLE_GATT_SETUP_TIMEOUT_MS = 10000;
437
460
  const PROTOCOL_REPROBE_FALLBACK_ATTEMPTS = 3;
@@ -446,9 +469,10 @@ const isWedgedBleSetupError = (error) => (error === null || error === void 0 ? v
446
469
  error.message.startsWith(BLE_SETUP_WEDGED_MESSAGE);
447
470
  const shouldRethrowBleSetupError = (error) => isConnectTimeoutError(error) || isWedgedBleSetupError(error);
448
471
  const isNativeOperationTimeoutError = (error) => (error === null || error === void 0 ? void 0 : error.errorCode) === reactNativeBlePlx.BleErrorCode.OperationTimedOut;
449
- const isAbandonedNativeOperationError = (error) => {
472
+ const isMtuOrCancelledConnectError = (error) => {
450
473
  const errorCode = error === null || error === void 0 ? void 0 : error.errorCode;
451
- return (errorCode === reactNativeBlePlx.BleErrorCode.OperationTimedOut || errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled);
474
+ return (errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
475
+ errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled);
452
476
  };
453
477
  const tryToGetConfiguration = (device) => {
454
478
  if (!device || !device.serviceUUIDs)
@@ -463,7 +487,7 @@ const tryToGetConfiguration = (device) => {
463
487
  };
464
488
  const requestNegotiatedMtu = (device, stage, attempt, cancelTransaction) => __awaiter(void 0, void 0, void 0, function* () {
465
489
  if (reactNative.Platform.OS !== 'ios' && reactNative.Platform.OS !== 'android')
466
- return { device, abandoned: false };
490
+ return { device, timedOut: false };
467
491
  const transactionId = `${device.id}:mtu:${stage}:${attempt}:${Date.now()}`;
468
492
  let timeoutId;
469
493
  let timedOut = false;
@@ -479,7 +503,7 @@ const requestNegotiatedMtu = (device, stage, attempt, cancelTransaction) => __aw
479
503
  }, BLE_MTU_REQUEST_TIMEOUT_MS);
480
504
  }),
481
505
  ]);
482
- return { device: mtuDevice, abandoned: false };
506
+ return { device: mtuDevice, timedOut: false };
483
507
  }
484
508
  catch (error) {
485
509
  if (timedOut && cancelTransaction) {
@@ -507,9 +531,10 @@ const requestNegotiatedMtu = (device, stage, attempt, cancelTransaction) => __aw
507
531
  stage,
508
532
  attempt,
509
533
  actual: device.mtu,
534
+ timedOut,
510
535
  error: error instanceof Error ? error.message : String(error),
511
536
  });
512
- return { device, abandoned: timedOut };
537
+ return { device, timedOut };
513
538
  }
514
539
  finally {
515
540
  if (timeoutId)
@@ -518,7 +543,7 @@ const requestNegotiatedMtu = (device, stage, attempt, cancelTransaction) => __aw
518
543
  });
519
544
  const resolveNegotiatedMtu = (device, cancelTransaction) => shouldRefreshNegotiatedMtu(device.mtu)
520
545
  ? requestNegotiatedMtu(device, 'connected', 0, cancelTransaction)
521
- : Promise.resolve({ device, abandoned: false });
546
+ : Promise.resolve({ device, timedOut: false });
522
547
  function remapError(error) {
523
548
  var _a;
524
549
  if (error instanceof reactNativeBlePlx.BleError) {
@@ -555,8 +580,8 @@ class ReactNativeBleTransport {
555
580
  this.sessionProtocols = new Map();
556
581
  this.confirmedProtocolV2 = new Set();
557
582
  this.protocolReprobeFailures = new Map();
558
- this.silentDetections = new Set();
559
- this.protocolWakeAttempts = new Set();
583
+ this.silentDetections = new Map();
584
+ this.androidGattCacheRefreshes = new Set();
560
585
  this.staleBondErrors = new Map();
561
586
  this.acquiringProtocolV2 = new Set();
562
587
  this.protocolV2Assemblers = new Map();
@@ -1030,7 +1055,9 @@ class ReactNativeBleTransport {
1030
1055
  const isCachedDeviceConnected = yield cachedTransport.device
1031
1056
  .isConnected()
1032
1057
  .catch(() => false);
1058
+ const isCachedAndroidLinkUsable = reactNative.Platform.OS !== 'android' || !this.androidGattCacheRefreshes.has(uuid);
1033
1059
  if (isCachedDeviceConnected &&
1060
+ isCachedAndroidLinkUsable &&
1034
1061
  cachedProtocol &&
1035
1062
  (!expectedProtocol || cachedProtocol === expectedProtocol)) {
1036
1063
  if (this.stopped)
@@ -1043,7 +1070,15 @@ class ReactNativeBleTransport {
1043
1070
  }
1044
1071
  }
1045
1072
  let device = null;
1046
- let mtuHandshakeRefused = false;
1073
+ const isAndroid = reactNative.Platform.OS === 'android';
1074
+ const refreshAndroidGattCache = isAndroid && (!!skipProtocolProbe || this.androidGattCacheRefreshes.has(uuid));
1075
+ let nativeConnectOptions = connectOptions;
1076
+ if (isAndroid) {
1077
+ nativeConnectOptions = refreshAndroidGattCache
1078
+ ? androidRefreshGattConnectOptions
1079
+ : fallbackConnectOptions;
1080
+ }
1081
+ let androidRefreshConnectRan = false;
1047
1082
  if (forceCleanRunPromise && this.runPromise) {
1048
1083
  const error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleForceCleanRunPromise);
1049
1084
  this.runPromise.reject(error);
@@ -1052,6 +1087,7 @@ class ReactNativeBleTransport {
1052
1087
  Log === null || Log === void 0 ? void 0 : Log.debug('Force clean Bluetooth run promise, forceCleanRunPromise: ', forceCleanRunPromise);
1053
1088
  }
1054
1089
  const blePlxManager = yield this.getPlxManager();
1090
+ let skipPostConnectMtu = false;
1055
1091
  try {
1056
1092
  yield subscribeBleOn(blePlxManager);
1057
1093
  }
@@ -1093,18 +1129,17 @@ class ReactNativeBleTransport {
1093
1129
  if (!device) {
1094
1130
  Log === null || Log === void 0 ? void 0 : Log.debug('try to connect to device: ', uuid);
1095
1131
  try {
1096
- device = yield this.connectWithTimeout(uuid, () => blePlxManager.connectToDevice(uuid, connectOptions));
1132
+ device = yield this.connectWithTimeout(uuid, () => blePlxManager.connectToDevice(uuid, nativeConnectOptions));
1133
+ androidRefreshConnectRan = refreshAndroidGattCache;
1097
1134
  }
1098
1135
  catch (e) {
1099
1136
  Log === null || Log === void 0 ? void 0 : Log.debug('try to connect to device has error: ', e);
1100
1137
  if (shouldRethrowBleSetupError(e)) {
1101
1138
  throw e;
1102
1139
  }
1103
- if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
1104
- e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
1140
+ if (isMtuOrCancelledConnectError(e)) {
1141
+ skipPostConnectMtu = true;
1105
1142
  Log === null || Log === void 0 ? void 0 : Log.debug('first try to reconnect without params');
1106
- mtuHandshakeRefused = true;
1107
- yield this.runBestEffortNativeOperation('connect cancelled: cancel manager connection', () => blePlxManager.cancelDeviceConnection(uuid));
1108
1143
  device = yield this.connectWithTimeout(uuid, () => blePlxManager.connectToDevice(uuid, fallbackConnectOptions));
1109
1144
  }
1110
1145
  else if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceAlreadyConnected) {
@@ -1119,22 +1154,28 @@ class ReactNativeBleTransport {
1119
1154
  if (!device) {
1120
1155
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, 'unable to connect to device');
1121
1156
  }
1157
+ if (refreshAndroidGattCache &&
1158
+ !androidRefreshConnectRan &&
1159
+ (yield device.isConnected().catch(() => false))) {
1160
+ yield this.dropAndroidLink(uuid, blePlxManager, device, 'gatt cache refresh');
1161
+ if (this.stopped)
1162
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1163
+ }
1122
1164
  if (!(yield device.isConnected())) {
1123
1165
  Log === null || Log === void 0 ? void 0 : Log.debug('not connected, try to connect to device: ', uuid);
1124
1166
  const disconnectedDevice = device;
1125
1167
  try {
1126
- device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(connectOptions));
1168
+ device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(nativeConnectOptions));
1169
+ androidRefreshConnectRan = refreshAndroidGattCache;
1127
1170
  }
1128
1171
  catch (e) {
1129
1172
  Log === null || Log === void 0 ? void 0 : Log.debug('not connected, try to connect to device has error: ', e);
1130
1173
  if (shouldRethrowBleSetupError(e)) {
1131
1174
  throw e;
1132
1175
  }
1133
- if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
1134
- e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
1176
+ if (isMtuOrCancelledConnectError(e)) {
1177
+ skipPostConnectMtu = true;
1135
1178
  Log === null || Log === void 0 ? void 0 : Log.debug('second try to reconnect without params');
1136
- mtuHandshakeRefused = true;
1137
- yield this.runBestEffortNativeOperation('connect cancelled: cancel device connection', () => disconnectedDevice.cancelConnection());
1138
1179
  try {
1139
1180
  device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(fallbackConnectOptions));
1140
1181
  }
@@ -1169,26 +1210,35 @@ class ReactNativeBleTransport {
1169
1210
  }
1170
1211
  if (this.stopped)
1171
1212
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1172
- if (mtuHandshakeRefused) {
1173
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] skipping MTU refresh after cancelled MTU connect', {
1174
- connectIdSuffix: uuid.slice(-8),
1175
- actual: device.mtu,
1176
- });
1177
- }
1178
- else {
1179
- const negotiatedMtu = yield resolveNegotiatedMtu(device, transactionId => blePlxManager.cancelTransaction(transactionId));
1180
- device = negotiatedMtu.device;
1181
- if (negotiatedMtu.abandoned) {
1182
- yield this.runNativeTeardown(uuid, blePlxManager, () => __awaiter(this, void 0, void 0, function* () {
1183
- yield this.runBestEffortNativeOperation('mtu abandoned: cancel manager connection', () => blePlxManager.cancelDeviceConnection(uuid));
1184
- }));
1185
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, 'BLE MTU negotiation abandoned, reconnecting');
1213
+ let characteristics;
1214
+ if (isAndroid) {
1215
+ if (refreshAndroidGattCache) {
1216
+ characteristics = yield this.resolveCharacteristicsWithTimeout(uuid, device);
1217
+ if (androidRefreshConnectRan)
1218
+ this.androidGattCacheRefreshes.delete(uuid);
1219
+ if (this.stopped)
1220
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1221
+ }
1222
+ device = yield this.negotiateAndroidMtu(uuid, blePlxManager, device);
1223
+ }
1224
+ else if (!skipPostConnectMtu) {
1225
+ const mtuResult = yield resolveNegotiatedMtu(device, transactionId => blePlxManager.cancelTransaction(transactionId));
1226
+ device = mtuResult.device;
1227
+ if (mtuResult.timedOut) {
1228
+ if (this.stopped)
1229
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1230
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] post-connect MTU timed out, reconnecting without requesting MTU');
1231
+ const timedOutDevice = device;
1232
+ yield this.runBestEffortNativeOperation('mtu timeout: cancel device connection', () => timedOutDevice.cancelConnection());
1233
+ if (this.stopped)
1234
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1235
+ device = yield this.connectWithTimeout(uuid, () => timedOutDevice.connect(fallbackConnectOptions));
1186
1236
  }
1187
1237
  }
1188
1238
  if (this.stopped)
1189
1239
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1190
1240
  const acquiredDevice = device;
1191
- const { writeCharacteristic, notifyCharacteristic } = yield this.resolveCharacteristicsWithTimeout(uuid, acquiredDevice);
1241
+ const { writeCharacteristic, notifyCharacteristic } = characteristics !== null && characteristics !== void 0 ? characteristics : (yield this.resolveCharacteristicsWithTimeout(uuid, acquiredDevice));
1192
1242
  if (this.stopped)
1193
1243
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1194
1244
  const protocolHint = expectedProtocol
@@ -1255,7 +1305,7 @@ class ReactNativeBleTransport {
1255
1305
  let bufferLength = 0;
1256
1306
  let buffer$1 = [];
1257
1307
  const subscription = characteristic.monitor((error, c) => {
1258
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
1308
+ var _a, _b, _c, _d, _e, _f;
1259
1309
  const isCurrentMonitor = this.monitorTokens.get(uuid) === monitorToken;
1260
1310
  if (error) {
1261
1311
  Log === null || Log === void 0 ? void 0 : Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
@@ -1272,16 +1322,16 @@ class ReactNativeBleTransport {
1272
1322
  this.rememberStaleBondError(uuid, toBleStaleBondHardwareError(error));
1273
1323
  return;
1274
1324
  }
1325
+ if (reactNative.Platform.OS === 'android' && isStaleGattTableNotifyReason(error.reason)) {
1326
+ this.androidGattCacheRefreshes.add(uuid);
1327
+ }
1275
1328
  if (this.getActiveProtocol(uuid) === 'V2') {
1276
1329
  let errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
1277
1330
  if ((_a = error.reason) === null || _a === void 0 ? void 0 : _a.includes('The connection has timed out unexpectedly')) {
1278
1331
  errorCode = hdShared.HardwareErrorCode.BleTimeoutError;
1279
1332
  }
1280
- else if (((_b = error.reason) === null || _b === void 0 ? void 0 : _b.includes('Cannot write client characteristic config descriptor')) ||
1281
- ((_c = error.reason) === null || _c === void 0 ? void 0 : _c.includes('Cannot find client characteristic config descriptor')) ||
1282
- ((_d = error.reason) === null || _d === void 0 ? void 0 : _d.includes('The handle is invalid')) ||
1283
- ((_e = error.reason) === null || _e === void 0 ? void 0 : _e.includes('Writing is not permitted')) ||
1284
- ((_f = error.reason) === null || _f === void 0 ? void 0 : _f.includes('notify change failed for device'))) {
1333
+ else if (isStaleGattTableNotifyReason(error.reason) ||
1334
+ ((_b = error.reason) === null || _b === void 0 ? void 0 : _b.includes('notify change failed for device'))) {
1285
1335
  errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure;
1286
1336
  }
1287
1337
  this.rejectProtocolV2Frames(uuid, hdShared.ERRORS.TypedError(errorCode));
@@ -1289,14 +1339,11 @@ class ReactNativeBleTransport {
1289
1339
  }
1290
1340
  if (this.runPromise && this.runPromiseDeviceId === uuid) {
1291
1341
  let ERROR = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
1292
- if ((_g = error.reason) === null || _g === void 0 ? void 0 : _g.includes('The connection has timed out unexpectedly')) {
1342
+ if ((_c = error.reason) === null || _c === void 0 ? void 0 : _c.includes('The connection has timed out unexpectedly')) {
1293
1343
  ERROR = hdShared.HardwareErrorCode.BleTimeoutError;
1294
1344
  }
1295
- if (((_h = error.reason) === null || _h === void 0 ? void 0 : _h.includes('Cannot write client characteristic config descriptor')) ||
1296
- ((_j = error.reason) === null || _j === void 0 ? void 0 : _j.includes('Cannot find client characteristic config descriptor')) ||
1297
- ((_k = error.reason) === null || _k === void 0 ? void 0 : _k.includes('The handle is invalid')) ||
1298
- ((_l = error.reason) === null || _l === void 0 ? void 0 : _l.includes('Writing is not permitted')) ||
1299
- ((_m = error.reason) === null || _m === void 0 ? void 0 : _m.includes('notify change failed for device'))) {
1345
+ if (isStaleGattTableNotifyReason(error.reason) ||
1346
+ ((_d = error.reason) === null || _d === void 0 ? void 0 : _d.includes('notify change failed for device'))) {
1300
1347
  const notifyError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure);
1301
1348
  this.runPromise.reject(notifyError);
1302
1349
  Log === null || Log === void 0 ? void 0 : Log.debug(`${hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure} ${error.message} ${error.reason}`);
@@ -1338,7 +1385,7 @@ class ReactNativeBleTransport {
1338
1385
  bufferLength = 0;
1339
1386
  buffer$1 = [];
1340
1387
  if (this.runPromiseDeviceId === uuid) {
1341
- (_o = this.runPromise) === null || _o === void 0 ? void 0 : _o.resolve(value.toString('hex'));
1388
+ (_e = this.runPromise) === null || _e === void 0 ? void 0 : _e.resolve(value.toString('hex'));
1342
1389
  }
1343
1390
  }
1344
1391
  }
@@ -1349,7 +1396,7 @@ class ReactNativeBleTransport {
1349
1396
  this.rejectProtocolV2Frames(uuid, notifyError);
1350
1397
  }
1351
1398
  else if (this.runPromiseDeviceId === uuid) {
1352
- (_p = this.runPromise) === null || _p === void 0 ? void 0 : _p.reject(notifyError);
1399
+ (_f = this.runPromise) === null || _f === void 0 ? void 0 : _f.reject(notifyError);
1353
1400
  }
1354
1401
  }
1355
1402
  }, notifyTransactionId);
@@ -1625,13 +1672,14 @@ class ReactNativeBleTransport {
1625
1672
  return check.call(jsonData);
1626
1673
  }
1627
1674
  catch (e) {
1628
- if (name === 'GetFeatures' && (options === null || options === void 0 ? void 0 : options.timeoutMs) === PROTOCOL_PROBE_TIMEOUT_MS) {
1629
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V1 GetFeatures probe call failed:', e);
1675
+ const isProbeTimeout = (options === null || options === void 0 ? void 0 : options.timeoutMs) === PROTOCOL_PROBE_TIMEOUT_MS &&
1676
+ (name === 'GetFeatures' || name === 'Initialize');
1677
+ if (isProbeTimeout) {
1678
+ Log === null || Log === void 0 ? void 0 : Log.debug(`[ReactNativeBleTransport] Protocol V1 ${name} probe call failed:`, e);
1630
1679
  }
1631
1680
  else {
1632
1681
  Log === null || Log === void 0 ? void 0 : Log.error('call error: ', e);
1633
1682
  }
1634
- const isProbeTimeout = name === 'GetFeatures' && (options === null || options === void 0 ? void 0 : options.timeoutMs) === PROTOCOL_PROBE_TIMEOUT_MS;
1635
1683
  const isStaleCall = this.runPromise !== runPromise;
1636
1684
  if (!isProbeTimeout &&
1637
1685
  !isStaleCall &&
@@ -1832,6 +1880,72 @@ class ReactNativeBleTransport {
1832
1880
  }
1833
1881
  });
1834
1882
  }
1883
+ negotiateAndroidMtu(uuid, manager, device) {
1884
+ return __awaiter(this, void 0, void 0, function* () {
1885
+ if (!shouldRefreshNegotiatedMtu(device.mtu))
1886
+ return device;
1887
+ const startedAt = Date.now();
1888
+ let timer;
1889
+ let timedOut = false;
1890
+ let negotiated = device;
1891
+ let failure;
1892
+ try {
1893
+ negotiated = yield Promise.race([
1894
+ device.requestMTU(ANDROID_REQUEST_MTU, `${device.id}:mtu:connected:0:${startedAt}`),
1895
+ new Promise((_, reject) => {
1896
+ timer = setTimeout(() => {
1897
+ timedOut = true;
1898
+ reject(new Error(`BLE MTU exchange timeout after ${ANDROID_MTU_EXCHANGE_TIMEOUT_MS}ms`));
1899
+ }, ANDROID_MTU_EXCHANGE_TIMEOUT_MS);
1900
+ }),
1901
+ ]);
1902
+ }
1903
+ catch (error) {
1904
+ failure = error instanceof Error ? error.message : String(error);
1905
+ }
1906
+ finally {
1907
+ if (timer)
1908
+ clearTimeout(timer);
1909
+ }
1910
+ Log === null || Log === void 0 ? void 0 : Log.debug(`[ReactNativeBleTransport] BLE MTU exchange ${failure ? 'failed' : 'completed'}`, {
1911
+ connectIdSuffix: uuid.slice(-8),
1912
+ elapsedMs: Date.now() - startedAt,
1913
+ timedOut,
1914
+ actual: negotiated.mtu,
1915
+ error: failure,
1916
+ });
1917
+ if (this.stopped)
1918
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceDisconnected);
1919
+ if (!timedOut && !isKnownDefaultMtu(negotiated.mtu))
1920
+ return negotiated;
1921
+ const resetManager = this.abandonStalledConnection(uuid, timedOut ? 'mtu-backstop' : 'mtu-default');
1922
+ yield this.dropAndroidLink(uuid, manager, negotiated, timedOut ? 'mtu exchange timeout' : 'default mtu');
1923
+ if (resetManager)
1924
+ throw this.createWedgedBleSetupError();
1925
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, timedOut
1926
+ ? 'BLE MTU exchange did not complete, reconnecting on a fresh link'
1927
+ : `BLE link stayed at the default MTU ${negotiated.mtu}, reconnecting on a fresh link`);
1928
+ });
1929
+ }
1930
+ dropAndroidLink(uuid, manager, device, reason) {
1931
+ return __awaiter(this, void 0, void 0, function* () {
1932
+ yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
1933
+ yield Promise.all([
1934
+ this.runBestEffortNativeOperation(`${reason}: cancel manager connection`, () => manager.cancelDeviceConnection(uuid)),
1935
+ this.runBestEffortNativeOperation(`${reason}: cancel device connection`, () => device.cancelConnection()),
1936
+ ]);
1937
+ }));
1938
+ const startedAt = Date.now();
1939
+ while (!this.stopped && Date.now() - startedAt < ANDROID_LINK_DROP_QUIET_MS) {
1940
+ yield delay(ANDROID_LINK_DROP_POLL_MS);
1941
+ }
1942
+ Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Android BLE link drop', {
1943
+ connectIdSuffix: uuid.slice(-8),
1944
+ reason,
1945
+ stopped: this.stopped,
1946
+ });
1947
+ });
1948
+ }
1835
1949
  connectWithTimeout(uuid, connect) {
1836
1950
  return __awaiter(this, void 0, void 0, function* () {
1837
1951
  if (this.stopped)
@@ -1899,12 +2013,15 @@ class ReactNativeBleTransport {
1899
2013
  return result;
1900
2014
  }
1901
2015
  catch (error) {
1902
- if (timedOut || isAbandonedNativeOperationError(error)) {
2016
+ if (timedOut || isNativeOperationTimeoutError(error)) {
1903
2017
  const resetManager = this.abandonStalledConnection(uuid, timedOut ? 'gatt-backstop' : 'gatt-native');
1904
2018
  if (resetManager) {
1905
2019
  throw this.createWedgedBleSetupError();
1906
2020
  }
1907
2021
  }
2022
+ if (reactNative.Platform.OS === 'android' && isMissingGattShapeError(error)) {
2023
+ this.androidGattCacheRefreshes.add(uuid);
2024
+ }
1908
2025
  throw error;
1909
2026
  }
1910
2027
  finally {
@@ -2057,7 +2174,6 @@ class ReactNativeBleTransport {
2057
2174
  this.sessionProtocols.clear();
2058
2175
  this.protocolReprobeFailures.clear();
2059
2176
  this.silentDetections.clear();
2060
- this.protocolWakeAttempts.clear();
2061
2177
  this.writeTimeoutCounts.clear();
2062
2178
  this.connectionSetupTimeoutCounts.clear();
2063
2179
  this.monitorTokens.clear();
@@ -2152,7 +2268,6 @@ class ReactNativeBleTransport {
2152
2268
  }
2153
2269
  this.protocolReprobeFailures.delete(uuid);
2154
2270
  this.silentDetections.delete(uuid);
2155
- this.protocolWakeAttempts.delete(uuid);
2156
2271
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
2157
2272
  deviceId: uuid,
2158
2273
  protocol,
@@ -2161,7 +2276,8 @@ class ReactNativeBleTransport {
2161
2276
  return protocol;
2162
2277
  }
2163
2278
  }
2164
- this.silentDetections.add(uuid);
2279
+ if (!this.silentDetections.has(uuid))
2280
+ this.silentDetections.set(uuid, 'silent');
2165
2281
  if (trustSessionProtocol) {
2166
2282
  this.protocolReprobeFailures.set(uuid, reprobeFailures + 1);
2167
2283
  }
@@ -2175,17 +2291,12 @@ class ReactNativeBleTransport {
2175
2291
  }
2176
2292
  wakeSilentProtocolV1Device(uuid, probeOrder) {
2177
2293
  return __awaiter(this, void 0, void 0, function* () {
2178
- if (!this._messages)
2179
- return;
2180
- if (!probeOrder.includes('V1'))
2294
+ if (reactNative.Platform.OS !== 'android' ||
2295
+ !probeOrder.includes('V1') ||
2296
+ this.silentDetections.get(uuid) !== 'silent') {
2181
2297
  return;
2182
- if (!this.silentDetections.has(uuid))
2183
- return;
2184
- if (this.protocolWakeAttempts.has(uuid))
2185
- return;
2186
- if (!transportCache[uuid])
2187
- return;
2188
- this.protocolWakeAttempts.add(uuid);
2298
+ }
2299
+ this.silentDetections.set(uuid, 'woken');
2189
2300
  Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] sending Protocol V1 Initialize wake', {
2190
2301
  connectIdSuffix: uuid.slice(-8),
2191
2302
  });
@@ -2194,11 +2305,8 @@ class ReactNativeBleTransport {
2194
2305
  yield this.callProtocolV1(uuid, 'Initialize', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT_MS });
2195
2306
  }
2196
2307
  catch (error) {
2197
- if (shouldRethrowProtocolProbeError(error)) {
2198
- this.clearProbeProtocol(uuid, 'V1');
2308
+ if (shouldRethrowProtocolProbeError(error))
2199
2309
  throw error;
2200
- }
2201
- Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Protocol V1 Initialize wake did not answer:', error);
2202
2310
  }
2203
2311
  finally {
2204
2312
  this.clearProbeProtocol(uuid, 'V1');
@@ -2522,11 +2630,11 @@ class ReactNativeBleTransport {
2522
2630
  const transport = this.getCachedTransport(uuid);
2523
2631
  if (!shouldRefreshNegotiatedMtu(transport.mtuSize))
2524
2632
  return;
2525
- const { device: refreshedDevice, abandoned } = yield requestNegotiatedMtu(transport.device, 'highThroughput', 1, transactionId => { var _a; return (_a = this.blePlxManager) === null || _a === void 0 ? void 0 : _a.cancelTransaction(transactionId); });
2633
+ const { device: refreshedDevice } = yield requestNegotiatedMtu(transport.device, 'highThroughput', 1, transactionId => { var _a; return (_a = this.blePlxManager) === null || _a === void 0 ? void 0 : _a.cancelTransaction(transactionId); });
2526
2634
  transport.device = refreshedDevice;
2527
2635
  transport.mtuSize =
2528
2636
  typeof refreshedDevice.mtu === 'number' ? refreshedDevice.mtu : transport.mtuSize;
2529
- if (abandoned || shouldRefreshNegotiatedMtu(transport.mtuSize)) {
2637
+ if (shouldRefreshNegotiatedMtu(transport.mtuSize)) {
2530
2638
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, `Protocol V2 high-throughput BLE MTU unavailable: ${String(transport.mtuSize)}`);
2531
2639
  }
2532
2640
  });
@@ -2639,6 +2747,8 @@ class ReactNativeBleTransport {
2639
2747
  }
2640
2748
  }
2641
2749
 
2750
+ exports.ANDROID_LINK_DROP_QUIET_MS = ANDROID_LINK_DROP_QUIET_MS;
2751
+ exports.ANDROID_MTU_EXCHANGE_TIMEOUT_MS = ANDROID_MTU_EXCHANGE_TIMEOUT_MS;
2642
2752
  exports.BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD = BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD;
2643
2753
  exports.BLE_CONNECT_TIMEOUT_MS = BLE_CONNECT_TIMEOUT_MS;
2644
2754
  exports.BLE_GATT_SETUP_TIMEOUT_MS = BLE_GATT_SETUP_TIMEOUT_MS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "1.2.2-alpha.115",
3
+ "version": "1.2.2-alpha.117",
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.115",
24
- "@onekeyfe/hd-shared": "1.2.2-alpha.115",
25
- "@onekeyfe/hd-transport": "1.2.2-alpha.115",
23
+ "@onekeyfe/hd-core": "1.2.2-alpha.117",
24
+ "@onekeyfe/hd-shared": "1.2.2-alpha.117",
25
+ "@onekeyfe/hd-transport": "1.2.2-alpha.117",
26
26
  "@onekeyfe/react-native-ble-utils": "0.1.6",
27
27
  "react-native-ble-plx": "3.5.1"
28
28
  },
29
- "gitHead": "a115ca6998586c05c22996f278091778fd5471f1"
29
+ "gitHead": "2ebb459218ac2f15e5295dd42be1fdda9cd9bc0e"
30
30
  }