@onekeyfe/hd-transport-react-native 1.2.2-alpha.114 → 1.2.2-alpha.116
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 +74 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +274 -32
- package/package.json +5 -5
- package/src/__tests__/connectTimeout.test.ts +104 -0
- package/src/__tests__/protocolV2Link.test.ts +494 -37
- package/src/index.ts +468 -43
package/dist/index.d.ts
CHANGED
|
@@ -74,6 +74,28 @@ declare function getProtocolV2BleTuning(): {
|
|
|
74
74
|
iosPacketLength: number;
|
|
75
75
|
androidPacketLength: number;
|
|
76
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Bound for the Android MTU exchange. A healthy exchange with a Pro 2 completes in ~50ms.
|
|
79
|
+
* When the phone has no cached GATT table (first connect after bonding, or a connect after
|
|
80
|
+
* an aborted discovery) the stack runs its own discovery first and only executes the MTU
|
|
81
|
+
* request after it; single passes on a Pro 2 at MTU 23 measured 1.7-4.8s and a refresh
|
|
82
|
+
* plus restart 7.7s, so the bound has to sit well above those. An exchange the stack holds
|
|
83
|
+
* as already in progress never completes, so a longer bound costs nothing on that link.
|
|
84
|
+
*/
|
|
85
|
+
declare const ANDROID_MTU_EXCHANGE_TIMEOUT_MS = 12000;
|
|
86
|
+
/**
|
|
87
|
+
* Android keeps an LE link up for its GATT link idle timer (4s) after the last client
|
|
88
|
+
* closes, and per-link ATT state such as a pending MTU exchange lives as long as the link.
|
|
89
|
+
* A reconnect inside that window attaches to the same link. The only connectivity signal
|
|
90
|
+
* reachable from here, BluetoothManager.getConnectedDevices(GATT), is built from the
|
|
91
|
+
* per-app GATT client registry rather than the LE link: it empties the moment this client
|
|
92
|
+
* closes on phones with no resident GATT server, and stays populated for the life of the
|
|
93
|
+
* link on phones that have one. So an unusable link is held for at least the quiet period
|
|
94
|
+
* (past the idle timer), and additionally until that registry no longer lists the device,
|
|
95
|
+
* within the overall bound.
|
|
96
|
+
*/
|
|
97
|
+
declare const ANDROID_LINK_DROP_QUIET_MS = 5000;
|
|
98
|
+
declare const ANDROID_LINK_DROP_TIMEOUT_MS = 8000;
|
|
77
99
|
/**
|
|
78
100
|
* JS backstop for connect. The native adapter applies its own 3s budget, but it
|
|
79
101
|
* schedules that timeout on its serial queue, so a busy queue (e.g. right after a
|
|
@@ -135,6 +157,25 @@ declare class ReactNativeBleTransport {
|
|
|
135
157
|
private confirmedProtocolV2;
|
|
136
158
|
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
137
159
|
private protocolReprobeFailures;
|
|
160
|
+
/** Endpoints whose last detection got no answer on any protocol. */
|
|
161
|
+
private silentDetections;
|
|
162
|
+
/**
|
|
163
|
+
* Android endpoints whose cached GATT table is suspect and must be rediscovered on the
|
|
164
|
+
* next connect. The cache is no longer refreshed on every connect, so a missing OneKey
|
|
165
|
+
* service or characteristic marks the endpoint instead.
|
|
166
|
+
*/
|
|
167
|
+
private androidGattCacheRefreshes;
|
|
168
|
+
/** Instance copies of the Android timing bounds so tests can shorten real-time waits. */
|
|
169
|
+
androidMtuExchangeTimeoutMs: number;
|
|
170
|
+
androidLinkDropQuietMs: number;
|
|
171
|
+
androidLinkDropTimeoutMs: number;
|
|
172
|
+
/**
|
|
173
|
+
* Endpoints already sent a Protocol V1 wake. The wake starts a fresh wallet session
|
|
174
|
+
* on the device, and a failed detection tears the link down and reconnects on every
|
|
175
|
+
* poll, so neither set is cleared on teardown: one wake is spent per endpoint until a
|
|
176
|
+
* detection succeeds, which re-arms it for the next time the device sleeps.
|
|
177
|
+
*/
|
|
178
|
+
private protocolWakeAttempts;
|
|
138
179
|
/**
|
|
139
180
|
* Native encryption/pairing failures seen before Protocol V2 probe starts.
|
|
140
181
|
* Pro2/Neo GATT connect can succeed on a stale iOS bond; the CCCD write then
|
|
@@ -194,6 +235,21 @@ declare class ReactNativeBleTransport {
|
|
|
194
235
|
private runBestEffortNativeOperation;
|
|
195
236
|
private runLifecycleOperation;
|
|
196
237
|
cancel(): Promise<void>;
|
|
238
|
+
/**
|
|
239
|
+
* Negotiate the ATT MTU as the first request on an Android GATT client, with nothing queued
|
|
240
|
+
* ahead of it, and never close the client while it is outstanding: an exchange abandoned
|
|
241
|
+
* mid-flight stays marked in progress for the whole LE link. A link that already negotiated
|
|
242
|
+
* an MTU answers at once with the recorded value.
|
|
243
|
+
*/
|
|
244
|
+
private negotiateAndroidMtu;
|
|
245
|
+
/**
|
|
246
|
+
* Abandon an Android LE link whose per-link GATT state is unusable. Closing the GATT
|
|
247
|
+
* client alone keeps the link up for the stack's idle timer, and Core's retry arrives
|
|
248
|
+
* inside that window, so this holds for at least ANDROID_LINK_DROP_QUIET_MS and until the
|
|
249
|
+
* GATT registry no longer lists the device, capped at ANDROID_LINK_DROP_TIMEOUT_MS.
|
|
250
|
+
*/
|
|
251
|
+
private dropAndroidLink;
|
|
252
|
+
private resolveCharacteristicsForAcquire;
|
|
197
253
|
/** Run a native connect under the JS backstop budget. */
|
|
198
254
|
private connectWithTimeout;
|
|
199
255
|
/** Resolve the complete GATT shape under a budget so acquire() always settles. */
|
|
@@ -228,6 +284,23 @@ declare class ReactNativeBleTransport {
|
|
|
228
284
|
/** Protocol to route a call with: confirmed if known, otherwise the one being probed. */
|
|
229
285
|
private getActiveProtocol;
|
|
230
286
|
private detectProtocol;
|
|
287
|
+
/**
|
|
288
|
+
* Sent once before probing when the previous detection on this endpoint got no answer
|
|
289
|
+
* at all. On Classic-family firmware that silence is also what a sleeping device looks
|
|
290
|
+
* like: its BLE co-processor keeps serving connect, GATT and MTU while the main MCU
|
|
291
|
+
* sits in the screensaver loop, whose host-message filter accepts only Initialize and
|
|
292
|
+
* the *Ack messages. GetFeatures and Ping are dropped there without a reply, so no
|
|
293
|
+
* amount of probing can bring the device back.
|
|
294
|
+
*
|
|
295
|
+
* Initialize is the one message that breaks that loop, but it also starts a fresh
|
|
296
|
+
* wallet session, which is why it is not the probe itself — a bare Initialize on every
|
|
297
|
+
* acquire would drop a hidden-wallet session before Core can restore it. Requiring a
|
|
298
|
+
* fully silent previous detection keeps it to devices with no session left to protect.
|
|
299
|
+
*
|
|
300
|
+
* The firmware consumes the wake to leave its loop and does not reliably answer it, so
|
|
301
|
+
* the result is ignored: the probes that follow are what decide the protocol.
|
|
302
|
+
*/
|
|
303
|
+
private wakeSilentProtocolV1Device;
|
|
231
304
|
private resetProbeStateAfterProtocolProbe;
|
|
232
305
|
private probeProtocolV1;
|
|
233
306
|
private probeProtocolV2;
|
|
@@ -251,4 +324,4 @@ declare class ReactNativeBleTransport {
|
|
|
251
324
|
getProtocolType(path: string): ProtocolType | undefined;
|
|
252
325
|
}
|
|
253
326
|
|
|
254
|
-
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 };
|
|
327
|
+
export { ANDROID_LINK_DROP_QUIET_MS, ANDROID_LINK_DROP_TIMEOUT_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 };
|
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;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,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;
|
|
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,KA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