@onekeyfe/hd-transport-react-native 1.2.8-alpha.119 → 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 +35 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +315 -18
- package/package.json +5 -5
- package/src/__tests__/nativeFrameWrite.test.ts +910 -0
- package/src/__tests__/protocolV2Link.test.ts +96 -0
- package/src/index.ts +450 -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,101 @@ 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
|
+
const createAndroidHarness = (apiLevel: number) => {
|
|
2111
|
+
setPlatformOS('android');
|
|
2112
|
+
setPlatformVersion(apiLevel);
|
|
2113
|
+
const harness = createHarness();
|
|
2114
|
+
harness.device.mtu = 517;
|
|
2115
|
+
return harness;
|
|
2116
|
+
};
|
|
2117
|
+
|
|
2118
|
+
test('leaves the priority to the peripheral on Android 17 by default', async () => {
|
|
2119
|
+
const harness = createAndroidHarness(37);
|
|
2120
|
+
|
|
2121
|
+
await runHighVolumeCalls(harness);
|
|
2122
|
+
await harness.transport.release(harness.uuid, true);
|
|
2123
|
+
|
|
2124
|
+
expect(harness.device.requestConnectionPriority).not.toHaveBeenCalled();
|
|
2125
|
+
expect(
|
|
2126
|
+
harness.logger.debug.mock.calls.filter(
|
|
2127
|
+
([message]) =>
|
|
2128
|
+
message ===
|
|
2129
|
+
'[ReactNativeBleTransport] Android BLE connection priority left to peripheral'
|
|
2130
|
+
)
|
|
2131
|
+
).toHaveLength(1);
|
|
2132
|
+
});
|
|
2133
|
+
|
|
2134
|
+
test('keeps requesting HIGH below Android 17 by default', async () => {
|
|
2135
|
+
const harness = createAndroidHarness(36);
|
|
2136
|
+
|
|
2137
|
+
await runHighVolumeCalls(harness);
|
|
2138
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledTimes(1);
|
|
2139
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledWith(1);
|
|
2140
|
+
|
|
2141
|
+
await harness.transport.release(harness.uuid, true);
|
|
2142
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenLastCalledWith(0);
|
|
2143
|
+
});
|
|
2144
|
+
|
|
2145
|
+
test.each([
|
|
2146
|
+
[37, true],
|
|
2147
|
+
[36, false],
|
|
2148
|
+
] as const)('applies the tuning switch on API %s when set to %s', async (apiLevel, setting) => {
|
|
2149
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: setting });
|
|
2150
|
+
const harness = createAndroidHarness(apiLevel);
|
|
2151
|
+
|
|
2152
|
+
await runHighVolumeCalls(harness);
|
|
2153
|
+
|
|
2154
|
+
if (setting) {
|
|
2155
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledWith(1);
|
|
2156
|
+
} else {
|
|
2157
|
+
expect(harness.device.requestConnectionPriority).not.toHaveBeenCalled();
|
|
2158
|
+
}
|
|
2159
|
+
await harness.transport.release(harness.uuid, true);
|
|
2160
|
+
});
|
|
2161
|
+
|
|
2162
|
+
test('keeps the switch across unrelated tuning and ignores invalid values', () => {
|
|
2163
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe('auto');
|
|
2164
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: false });
|
|
2165
|
+
configureProtocolV2BleTuning({ androidPacketLength: 200 });
|
|
2166
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe(false);
|
|
2167
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: 'on' as never });
|
|
2168
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe(false);
|
|
2169
|
+
configureProtocolV2BleTuning({ androidHighConnectionPriority: 'auto' });
|
|
2170
|
+
expect(getProtocolV2BleTuning().androidHighConnectionPriority).toBe('auto');
|
|
2171
|
+
});
|
|
2172
|
+
|
|
2173
|
+
test('requests HIGH again on the next link after a manual disconnect', async () => {
|
|
2174
|
+
const harness = createAndroidHarness(36);
|
|
2175
|
+
|
|
2176
|
+
await runHighVolumeCalls(harness);
|
|
2177
|
+
expect(harness.device.requestConnectionPriority).toHaveBeenCalledTimes(1);
|
|
2178
|
+
|
|
2179
|
+
await harness.transport.disconnect(harness.uuid);
|
|
2180
|
+
await runHighVolumeCalls(harness);
|
|
2181
|
+
|
|
2182
|
+
expect(
|
|
2183
|
+
harness.device.requestConnectionPriority.mock.calls.filter(([priority]) => priority === 1)
|
|
2184
|
+
).toHaveLength(2);
|
|
2185
|
+
await harness.transport.release(harness.uuid, true);
|
|
2186
|
+
});
|
|
2187
|
+
});
|
|
2188
|
+
|
|
2093
2189
|
test('uses withResponse for an iOS Protocol V2 firmware file write when requested', async () => {
|
|
2094
2190
|
const { transport, uuid, writeCharacteristic } = createHarness();
|
|
2095
2191
|
|