@onekeyfe/hd-transport-react-native 1.2.8-alpha.116 → 1.2.8-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 +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -0
- package/package.json +5 -5
- package/src/__tests__/protocolV2Link.test.ts +103 -0
- package/src/index.ts +46 -0
package/dist/index.d.ts
CHANGED
|
@@ -72,6 +72,11 @@ type ProtocolV2BleTuning = {
|
|
|
72
72
|
* BLE module supports it. Defaults to true; false keeps the per-packet JS write loop.
|
|
73
73
|
*/
|
|
74
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';
|
|
75
80
|
};
|
|
76
81
|
declare function configureProtocolV2BleTuning(tuning?: ProtocolV2BleTuning): void;
|
|
77
82
|
declare function resetProtocolV2BleTuning(): void;
|
|
@@ -79,6 +84,7 @@ declare function getProtocolV2BleTuning(): {
|
|
|
79
84
|
iosPacketLength: number;
|
|
80
85
|
androidPacketLength: number;
|
|
81
86
|
nativeFrameWrite: boolean;
|
|
87
|
+
androidHighConnectionPriority: boolean | "auto";
|
|
82
88
|
};
|
|
83
89
|
/**
|
|
84
90
|
* With no cached GATT table the stack runs its own discovery (up to ~8s) before the MTU
|
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,oBAAo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6 +401,7 @@ const DEFAULT_PROTOCOL_V2_BLE_TUNING = {
|
|
|
401
401
|
iosPacketLength: IOS_PROTOCOL_V2_PACKET_LENGTH,
|
|
402
402
|
androidPacketLength: ANDROID_PROTOCOL_V2_PACKET_LENGTH,
|
|
403
403
|
nativeFrameWrite: true,
|
|
404
|
+
androidHighConnectionPriority: 'auto',
|
|
404
405
|
};
|
|
405
406
|
let protocolV2BleTuning = Object.assign({}, DEFAULT_PROTOCOL_V2_BLE_TUNING);
|
|
406
407
|
const normalizePositiveInteger = (value, fallback) => {
|
|
@@ -416,6 +417,10 @@ function configureProtocolV2BleTuning(tuning = {}) {
|
|
|
416
417
|
nativeFrameWrite: typeof tuning.nativeFrameWrite === 'boolean'
|
|
417
418
|
? tuning.nativeFrameWrite
|
|
418
419
|
: protocolV2BleTuning.nativeFrameWrite,
|
|
420
|
+
androidHighConnectionPriority: typeof tuning.androidHighConnectionPriority === 'boolean' ||
|
|
421
|
+
tuning.androidHighConnectionPriority === 'auto'
|
|
422
|
+
? tuning.androidHighConnectionPriority
|
|
423
|
+
: protocolV2BleTuning.androidHighConnectionPriority,
|
|
419
424
|
};
|
|
420
425
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE tuning configured', protocolV2BleTuning);
|
|
421
426
|
}
|
|
@@ -517,6 +522,16 @@ function getDeviceDisplayName(device) {
|
|
|
517
522
|
const IOS_REQUEST_MTU = 247;
|
|
518
523
|
const ANDROID_REQUEST_MTU = 517;
|
|
519
524
|
const ANDROID_HIGH_PRIORITY_IDLE_MS = 1000;
|
|
525
|
+
const ANDROID_HIGH_PRIORITY_PERIPHERAL_LATENCY_API_LEVEL = 37;
|
|
526
|
+
const shouldRequestAndroidHighConnectionPriority = () => {
|
|
527
|
+
if (reactNative.Platform.OS !== 'android')
|
|
528
|
+
return false;
|
|
529
|
+
const { androidHighConnectionPriority } = protocolV2BleTuning;
|
|
530
|
+
if (typeof androidHighConnectionPriority === 'boolean')
|
|
531
|
+
return androidHighConnectionPriority;
|
|
532
|
+
const apiLevel = Number(reactNative.Platform.Version);
|
|
533
|
+
return !(Number.isFinite(apiLevel) && apiLevel >= ANDROID_HIGH_PRIORITY_PERIPHERAL_LATENCY_API_LEVEL);
|
|
534
|
+
};
|
|
520
535
|
const getRequestedBleMtu = () => reactNative.Platform.OS === 'android' ? ANDROID_REQUEST_MTU : IOS_REQUEST_MTU;
|
|
521
536
|
const BLE_NATIVE_CONNECT_TIMEOUT_MS = 3000;
|
|
522
537
|
const BLE_MTU_REQUEST_TIMEOUT_MS = BLE_NATIVE_CONNECT_TIMEOUT_MS;
|
|
@@ -1845,6 +1860,8 @@ class ReactNativeBleTransport {
|
|
|
1845
1860
|
disconnectUnlocked(session) {
|
|
1846
1861
|
var _a, _b, _c;
|
|
1847
1862
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1863
|
+
this.clearAndroidPriorityResetTimer(session);
|
|
1864
|
+
this.androidHighPriorityDevices.delete(session);
|
|
1848
1865
|
this.cancelProtocolV2FrameWrite(session, new Error('React Native BLE transport disconnected'));
|
|
1849
1866
|
yield this.protocolV2Links.invalidateLink(session, 'React Native BLE transport disconnected');
|
|
1850
1867
|
const transport = transportCache[session];
|
|
@@ -2902,12 +2919,25 @@ class ReactNativeBleTransport {
|
|
|
2902
2919
|
}
|
|
2903
2920
|
}
|
|
2904
2921
|
enableAndroidHighConnectionPriority(uuid) {
|
|
2922
|
+
var _a;
|
|
2905
2923
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2906
2924
|
if (reactNative.Platform.OS !== 'android')
|
|
2907
2925
|
return;
|
|
2908
2926
|
this.clearAndroidPriorityResetTimer(uuid);
|
|
2909
2927
|
if (this.androidHighPriorityDevices.has(uuid))
|
|
2910
2928
|
return;
|
|
2929
|
+
if (!shouldRequestAndroidHighConnectionPriority()) {
|
|
2930
|
+
const loggedSignatures = (_a = this.protocolV2HighVolumeLogSignatures.get(uuid)) !== null && _a !== void 0 ? _a : new Set();
|
|
2931
|
+
if (!loggedSignatures.has('androidPriority:peripheral')) {
|
|
2932
|
+
loggedSignatures.add('androidPriority:peripheral');
|
|
2933
|
+
this.protocolV2HighVolumeLogSignatures.set(uuid, loggedSignatures);
|
|
2934
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] Android BLE connection priority left to peripheral', {
|
|
2935
|
+
apiLevel: reactNative.Platform.Version,
|
|
2936
|
+
setting: protocolV2BleTuning.androidHighConnectionPriority,
|
|
2937
|
+
});
|
|
2938
|
+
}
|
|
2939
|
+
return;
|
|
2940
|
+
}
|
|
2911
2941
|
const transport = transportCache[uuid];
|
|
2912
2942
|
if (!transport)
|
|
2913
2943
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.8-alpha.
|
|
3
|
+
"version": "1.2.8-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.8-alpha.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.8-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.8-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.8-alpha.117",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.8-alpha.117",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.8-alpha.117",
|
|
26
26
|
"@onekeyfe/react-native-ble-utils": "0.1.9",
|
|
27
27
|
"react-native-ble-plx": "3.5.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "610f1a979c682817acf9b4d195365dc5ed806138"
|
|
30
30
|
}
|
|
@@ -12,6 +12,7 @@ import ReactNativeBleTransport, {
|
|
|
12
12
|
BLE_WRITE_PACKET_TIMEOUT_MS,
|
|
13
13
|
configureProtocolV2BleTuning,
|
|
14
14
|
getFirmwareUploadWriteRetryType,
|
|
15
|
+
getProtocolV2BleTuning,
|
|
15
16
|
resetProtocolV2BleTuning,
|
|
16
17
|
} from '../index';
|
|
17
18
|
|
|
@@ -2090,6 +2091,108 @@ describe('ReactNativeBleTransport Protocol V2 link lifecycle', () => {
|
|
|
2090
2091
|
expect(device.requestConnectionPriority).toHaveBeenLastCalledWith(0);
|
|
2091
2092
|
});
|
|
2092
2093
|
|
|
2094
|
+
describe('Android connection priority by API level', () => {
|
|
2095
|
+
const setPlatformVersion = (version: number | undefined) => {
|
|
2096
|
+
const reactNative: { Platform: { Version?: number } } = jest.requireMock('react-native');
|
|
2097
|
+
reactNative.Platform.Version = version;
|
|
2098
|
+
};
|
|
2099
|
+
|
|
2100
|
+
afterEach(() => {
|
|
2101
|
+
setPlatformVersion(undefined);
|
|
2102
|
+
});
|
|
2103
|
+
|
|
2104
|
+
const runHighVolumeCalls = async (harness: ReturnType<typeof createHarness>) => {
|
|
2105
|
+
await harness.transport.acquire({ uuid: harness.uuid, expectedProtocol: 'V2' });
|
|
2106
|
+
await harness.transport.call(harness.uuid, 'FileWrite', {});
|
|
2107
|
+
await harness.transport.call(harness.uuid, 'FileWrite', {});
|
|
2108
|
+
};
|
|
2109
|
+
|
|
2110
|
+
test('leaves the priority to the peripheral on Android 17 by default', async () => {
|
|
2111
|
+
setPlatformOS('android');
|
|
2112
|
+
setPlatformVersion(37);
|
|
2113
|
+
const harness = createHarness();
|
|
2114
|
+
harness.device.mtu = 517;
|
|
2115
|
+
|
|
2116
|
+
await runHighVolumeCalls(harness);
|
|
2117
|
+
await harness.transport.release(harness.uuid, true);
|
|
2118
|
+
|
|
2119
|
+
expect(harness.device.requestConnectionPriority).not.toHaveBeenCalled();
|
|
2120
|
+
expect(
|
|
2121
|
+
harness.logger.debug.mock.calls.filter(
|
|
2122
|
+
([message]) =>
|
|
2123
|
+
message ===
|
|
2124
|
+
'[ReactNativeBleTransport] Android BLE connection priority left to peripheral'
|
|
2125
|
+
)
|
|
2126
|
+
).toHaveLength(1);
|
|
2127
|
+
});
|
|
2128
|
+
|
|
2129
|
+
test('keeps requesting HIGH below Android 17 by default', async () => {
|
|
2130
|
+
setPlatformOS('android');
|
|
2131
|
+
setPlatformVersion(36);
|
|
2132
|
+
const harness = createHarness();
|
|
2133
|
+
harness.device.mtu = 517;
|
|
2134
|
+
|
|
2135
|
+
await runHighVolumeCalls(harness);
|
|
2136
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledTimes(1);
|
|
2137
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledWith(1);
|
|
2138
|
+
|
|
2139
|
+
await harness.transport.release(harness.uuid, true);
|
|
2140
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenLastCalledWith(0);
|
|
2141
|
+
});
|
|
2142
|
+
|
|
2143
|
+
test.each([
|
|
2144
|
+
[37, true, true],
|
|
2145
|
+
[36, false, false],
|
|
2146
|
+
] as const)(
|
|
2147
|
+
'applies the tuning switch on API %s when set to %s',
|
|
2148
|
+
async (apiLevel, setting, expectHigh) => {
|
|
2149
|
+
setPlatformOS('android');
|
|
2150
|
+
setPlatformVersion(apiLevel);
|
|
2151
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: setting });
|
|
2152
|
+
const harness = createHarness();
|
|
2153
|
+
harness.device.mtu = 517;
|
|
2154
|
+
|
|
2155
|
+
await runHighVolumeCalls(harness);
|
|
2156
|
+
|
|
2157
|
+
if (expectHigh) {
|
|
2158
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledWith(1);
|
|
2159
|
+
} else {
|
|
2160
|
+
expect(harness.device.requestConnectionPriority).not.toHaveBeenCalled();
|
|
2161
|
+
}
|
|
2162
|
+
await harness.transport.release(harness.uuid, true);
|
|
2163
|
+
}
|
|
2164
|
+
);
|
|
2165
|
+
|
|
2166
|
+
test('keeps the switch across unrelated tuning and ignores invalid values', () => {
|
|
2167
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe('auto');
|
|
2168
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: false });
|
|
2169
|
+
configureProtocolV2BleTuning({ androidPacketLength: 200 });
|
|
2170
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe(false);
|
|
2171
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: 'on' as never });
|
|
2172
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe(false);
|
|
2173
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: 'auto' });
|
|
2174
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe('auto');
|
|
2175
|
+
});
|
|
2176
|
+
|
|
2177
|
+
test('requests HIGH again on the next link after a manual disconnect', async () => {
|
|
2178
|
+
setPlatformOS('android');
|
|
2179
|
+
setPlatformVersion(36);
|
|
2180
|
+
const harness = createHarness();
|
|
2181
|
+
harness.device.mtu = 517;
|
|
2182
|
+
|
|
2183
|
+
await runHighVolumeCalls(harness);
|
|
2184
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledTimes(1);
|
|
2185
|
+
|
|
2186
|
+
await harness.transport.disconnect(harness.uuid);
|
|
2187
|
+
await runHighVolumeCalls(harness);
|
|
2188
|
+
|
|
2189
|
+
expect(
|
|
2190
|
+
harness.device.requestConnectionPriority.mock.calls.filter(([priority]) => priority === 1)
|
|
2191
|
+
).toHaveLength(2);
|
|
2192
|
+
await harness.transport.release(harness.uuid, true);
|
|
2193
|
+
});
|
|
2194
|
+
});
|
|
2195
|
+
|
|
2093
2196
|
test('uses withResponse for an iOS Protocol V2 firmware file write when requested', async () => {
|
|
2094
2197
|
const { transport, uuid, writeCharacteristic } = createHarness();
|
|
2095
2198
|
|
package/src/index.ts
CHANGED
|
@@ -195,6 +195,11 @@ export type ProtocolV2BleTuning = {
|
|
|
195
195
|
* BLE module supports it. Defaults to true; false keeps the per-packet JS write loop.
|
|
196
196
|
*/
|
|
197
197
|
nativeFrameWrite?: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Android CONNECTION_PRIORITY_HIGH around Protocol V2 high-throughput calls. 'auto' (the
|
|
200
|
+
* default) requests it below Android 17 only; true or false forces it on every version.
|
|
201
|
+
*/
|
|
202
|
+
androidHighConnectionPriority?: boolean | 'auto';
|
|
198
203
|
};
|
|
199
204
|
|
|
200
205
|
type ResolvedProtocolV2BleTuning = Required<ProtocolV2BleTuning>;
|
|
@@ -203,6 +208,7 @@ const DEFAULT_PROTOCOL_V2_BLE_TUNING: ResolvedProtocolV2BleTuning = {
|
|
|
203
208
|
iosPacketLength: IOS_PROTOCOL_V2_PACKET_LENGTH,
|
|
204
209
|
androidPacketLength: ANDROID_PROTOCOL_V2_PACKET_LENGTH,
|
|
205
210
|
nativeFrameWrite: true,
|
|
211
|
+
androidHighConnectionPriority: 'auto',
|
|
206
212
|
};
|
|
207
213
|
|
|
208
214
|
let protocolV2BleTuning: ResolvedProtocolV2BleTuning = { ...DEFAULT_PROTOCOL_V2_BLE_TUNING };
|
|
@@ -227,6 +233,11 @@ export function configureProtocolV2BleTuning(tuning: ProtocolV2BleTuning = {}) {
|
|
|
227
233
|
typeof tuning.nativeFrameWrite === 'boolean'
|
|
228
234
|
? tuning.nativeFrameWrite
|
|
229
235
|
: protocolV2BleTuning.nativeFrameWrite,
|
|
236
|
+
androidHighConnectionPriority:
|
|
237
|
+
typeof tuning.androidHighConnectionPriority === 'boolean' ||
|
|
238
|
+
tuning.androidHighConnectionPriority === 'auto'
|
|
239
|
+
? tuning.androidHighConnectionPriority
|
|
240
|
+
: protocolV2BleTuning.androidHighConnectionPriority,
|
|
230
241
|
};
|
|
231
242
|
Log?.debug('[ReactNativeBleTransport] BLE tuning configured', protocolV2BleTuning);
|
|
232
243
|
}
|
|
@@ -379,6 +390,24 @@ function getDeviceDisplayName(device?: Device | null) {
|
|
|
379
390
|
const IOS_REQUEST_MTU = 247;
|
|
380
391
|
const ANDROID_REQUEST_MTU = 517;
|
|
381
392
|
const ANDROID_HIGH_PRIORITY_IDLE_MS = 1000;
|
|
393
|
+
/**
|
|
394
|
+
* Android 17 maps CONNECTION_PRIORITY_HIGH to 11.25-15 ms with peripheral latency 1. OneKey BLE
|
|
395
|
+
* firmware accepts any latency at its 15 ms interval, and latency 1 roughly halves Protocol V2
|
|
396
|
+
* FileWrite throughput. BLE 1.0.23 requests 15 ms with latency 0 by itself; older BLE firmware
|
|
397
|
+
* asks for 15-30 ms or nothing and has not been measured on Android 17 without HIGH.
|
|
398
|
+
*/
|
|
399
|
+
const ANDROID_HIGH_PRIORITY_PERIPHERAL_LATENCY_API_LEVEL = 37;
|
|
400
|
+
|
|
401
|
+
const shouldRequestAndroidHighConnectionPriority = () => {
|
|
402
|
+
if (Platform.OS !== 'android') return false;
|
|
403
|
+
const { androidHighConnectionPriority } = protocolV2BleTuning;
|
|
404
|
+
if (typeof androidHighConnectionPriority === 'boolean') return androidHighConnectionPriority;
|
|
405
|
+
const apiLevel = Number(Platform.Version);
|
|
406
|
+
// Unknown versions keep the long-standing HIGH request.
|
|
407
|
+
return !(
|
|
408
|
+
Number.isFinite(apiLevel) && apiLevel >= ANDROID_HIGH_PRIORITY_PERIPHERAL_LATENCY_API_LEVEL
|
|
409
|
+
);
|
|
410
|
+
};
|
|
382
411
|
|
|
383
412
|
const getRequestedBleMtu = () =>
|
|
384
413
|
Platform.OS === 'android' ? ANDROID_REQUEST_MTU : IOS_REQUEST_MTU;
|
|
@@ -2105,6 +2134,10 @@ export default class ReactNativeBleTransport {
|
|
|
2105
2134
|
}
|
|
2106
2135
|
|
|
2107
2136
|
private async disconnectUnlocked(session: string) {
|
|
2137
|
+
// The next link starts at the stack's default priority; a cached HIGH or a pending
|
|
2138
|
+
// Balanced restore from this link must not carry over to it.
|
|
2139
|
+
this.clearAndroidPriorityResetTimer(session);
|
|
2140
|
+
this.androidHighPriorityDevices.delete(session);
|
|
2108
2141
|
this.cancelProtocolV2FrameWrite(session, new Error('React Native BLE transport disconnected'));
|
|
2109
2142
|
await this.protocolV2Links.invalidateLink(session, 'React Native BLE transport disconnected');
|
|
2110
2143
|
const transport = transportCache[session];
|
|
@@ -3453,6 +3486,19 @@ export default class ReactNativeBleTransport {
|
|
|
3453
3486
|
|
|
3454
3487
|
this.clearAndroidPriorityResetTimer(uuid);
|
|
3455
3488
|
if (this.androidHighPriorityDevices.has(uuid)) return;
|
|
3489
|
+
if (!shouldRequestAndroidHighConnectionPriority()) {
|
|
3490
|
+
const loggedSignatures =
|
|
3491
|
+
this.protocolV2HighVolumeLogSignatures.get(uuid) ?? new Set<string>();
|
|
3492
|
+
if (!loggedSignatures.has('androidPriority:peripheral')) {
|
|
3493
|
+
loggedSignatures.add('androidPriority:peripheral');
|
|
3494
|
+
this.protocolV2HighVolumeLogSignatures.set(uuid, loggedSignatures);
|
|
3495
|
+
Log?.debug('[ReactNativeBleTransport] Android BLE connection priority left to peripheral', {
|
|
3496
|
+
apiLevel: Platform.Version,
|
|
3497
|
+
setting: protocolV2BleTuning.androidHighConnectionPriority,
|
|
3498
|
+
});
|
|
3499
|
+
}
|
|
3500
|
+
return;
|
|
3501
|
+
}
|
|
3456
3502
|
|
|
3457
3503
|
const transport = transportCache[uuid];
|
|
3458
3504
|
if (!transport) return;
|