@onekeyfe/hd-core 1.2.2-alpha.6 → 1.2.2-alpha.8
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/__tests__/device-lifecycle-events.test.ts +14 -0
- package/__tests__/open-wallet-session.test.ts +43 -6
- package/__tests__/pro2HostAssetPackage.test.ts +108 -1
- package/__tests__/protocol-v2.test.ts +129 -19
- package/__tests__/protocolV2FileWrite.test.ts +40 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +1 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/index.js +111 -44
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/utils/pro2HostAssetPackage.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +33 -6
- package/src/api/helpers/protocolV2FileWrite.ts +11 -5
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +8 -2
- package/src/core/index.ts +19 -8
- package/src/protocols/protocol-v2/walletSession.ts +6 -4
- package/src/utils/pro2HostAssetPackage.ts +73 -27
package/dist/index.js
CHANGED
|
@@ -41981,7 +41981,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41981
41981
|
standardWalletSelected = true;
|
|
41982
41982
|
}
|
|
41983
41983
|
});
|
|
41984
|
-
const selectStandardWallet = () => __awaiter(this, void 0, void 0, function* () {
|
|
41984
|
+
const selectStandardWallet = (forceMainPin = false) => __awaiter(this, void 0, void 0, function* () {
|
|
41985
41985
|
var _q;
|
|
41986
41986
|
if (((_q = device.features) === null || _q === void 0 ? void 0 : _q.passphraseProtection) === true) {
|
|
41987
41987
|
yield selectMainPin();
|
|
@@ -41992,7 +41992,8 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
41992
41992
|
standardWalletSelected = true;
|
|
41993
41993
|
}
|
|
41994
41994
|
else if (!standardWalletSelected) {
|
|
41995
|
-
yield selectMainPin(
|
|
41995
|
+
yield selectMainPin(forceMainPin);
|
|
41996
|
+
standardWalletSelected = true;
|
|
41996
41997
|
}
|
|
41997
41998
|
});
|
|
41998
41999
|
if (readCurrentAttachPinSession) {
|
|
@@ -42091,7 +42092,7 @@ function getProtocolV2WalletSession(device, options) {
|
|
|
42091
42092
|
}
|
|
42092
42093
|
if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
|
|
42093
42094
|
(_h = device.clearStandardInternalState) === null || _h === void 0 ? void 0 : _h.call(device);
|
|
42094
|
-
yield selectStandardWallet();
|
|
42095
|
+
yield selectStandardWallet(true);
|
|
42095
42096
|
response = yield getDeviceSession(device, sessionGetRequest());
|
|
42096
42097
|
}
|
|
42097
42098
|
else {
|
|
@@ -52094,11 +52095,15 @@ function isProtocolV2ResponseTimeout(error) {
|
|
|
52094
52095
|
code === 'response-timeout' ||
|
|
52095
52096
|
/(?:BLE|Lowlevel|Protocol V2) response timeout/i.test((_b = candidate.message) !== null && _b !== void 0 ? _b : ''));
|
|
52096
52097
|
}
|
|
52097
|
-
function getProtocolV2FileChunkLimit() {
|
|
52098
|
+
function getProtocolV2FileChunkLimit(bleChunkSizeLimit) {
|
|
52098
52099
|
const env = DataManager.getSettings('env');
|
|
52099
|
-
|
|
52100
|
-
|
|
52101
|
-
|
|
52100
|
+
if (env && DataManager.isBleConnect(env)) {
|
|
52101
|
+
const configuredLimit = Number(bleChunkSizeLimit);
|
|
52102
|
+
return Number.isFinite(configuredLimit) && configuredLimit > 0
|
|
52103
|
+
? Math.floor(configuredLimit)
|
|
52104
|
+
: hdTransport.PROTOCOL_V2_BLE_FILE_CHUNK_SIZE;
|
|
52105
|
+
}
|
|
52106
|
+
return hdTransport.PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
52102
52107
|
}
|
|
52103
52108
|
function dataToUint8Array(data) {
|
|
52104
52109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -52153,7 +52158,7 @@ function writeProtocolV2File(options) {
|
|
|
52153
52158
|
if (totalSize < startOffset + dataLength) {
|
|
52154
52159
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `FilesystemFileWrite totalSize ${totalSize} is smaller than offset + data length ${startOffset + dataLength}`);
|
|
52155
52160
|
}
|
|
52156
|
-
const defaultChunkSizeLimit = getProtocolV2FileChunkLimit();
|
|
52161
|
+
const defaultChunkSizeLimit = getProtocolV2FileChunkLimit(options.bleChunkSizeLimit);
|
|
52157
52162
|
const configuredChunkSizeLimit = Number(options.chunkSizeLimit);
|
|
52158
52163
|
const chunkSizeLimit = Number.isFinite(configuredChunkSizeLimit) && configuredChunkSizeLimit > 0
|
|
52159
52164
|
? Math.floor(configuredChunkSizeLimit)
|
|
@@ -52504,6 +52509,13 @@ const isProtocolV2InstallResponseTimeout = (error) => {
|
|
|
52504
52509
|
return (code === 'response-timeout' ||
|
|
52505
52510
|
/\bresponse timeout\b/i.test(getProtocolV2UnknownErrorText(error)));
|
|
52506
52511
|
};
|
|
52512
|
+
const getProtocolV2ErrorCode = (error) => {
|
|
52513
|
+
if (!error || typeof error !== 'object')
|
|
52514
|
+
return undefined;
|
|
52515
|
+
const { errorCode, code } = error;
|
|
52516
|
+
const causeCode = errorCode !== null && errorCode !== void 0 ? errorCode : code;
|
|
52517
|
+
return typeof causeCode === 'number' || typeof causeCode === 'string' ? causeCode : undefined;
|
|
52518
|
+
};
|
|
52507
52519
|
const isProtocolV2TerminalInstallStatusError = (error) => {
|
|
52508
52520
|
var _a;
|
|
52509
52521
|
return hdShared.isBleStaleBondHardwareError(error) ||
|
|
@@ -53796,6 +53808,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53796
53808
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.StartTransferData);
|
|
53797
53809
|
this.protocolV2LastTransferProgress = undefined;
|
|
53798
53810
|
this.protocolV2LastTransferProgressAt = 0;
|
|
53811
|
+
const transferStartedAt = Date.now();
|
|
53799
53812
|
let processedSize = 0;
|
|
53800
53813
|
for (const resource of resourcesToSync) {
|
|
53801
53814
|
const writePath = resource.devicePath;
|
|
@@ -53804,6 +53817,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53804
53817
|
filePath: writePath,
|
|
53805
53818
|
processedSize,
|
|
53806
53819
|
totalSize,
|
|
53820
|
+
transferStartedAt,
|
|
53807
53821
|
});
|
|
53808
53822
|
yield this.verifyProtocolV2StagedFile(writePath, resource.source.size);
|
|
53809
53823
|
if (isProtocolV2BootResourcePackagePath(resource.devicePath)) {
|
|
@@ -53818,6 +53832,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53818
53832
|
filePath,
|
|
53819
53833
|
processedSize,
|
|
53820
53834
|
totalSize,
|
|
53835
|
+
transferStartedAt,
|
|
53821
53836
|
});
|
|
53822
53837
|
yield this.verifyProtocolV2StagedFile(filePath, item.source.size);
|
|
53823
53838
|
stagedInstallTargets.push({
|
|
@@ -53826,7 +53841,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53826
53841
|
});
|
|
53827
53842
|
}
|
|
53828
53843
|
if (totalSize > 0) {
|
|
53829
|
-
|
|
53844
|
+
const elapsedMs = Math.max(Date.now() - transferStartedAt, 0);
|
|
53845
|
+
this.postProgressMessage(100, 'transferData', {
|
|
53846
|
+
transferredBytes: totalSize,
|
|
53847
|
+
totalBytes: totalSize,
|
|
53848
|
+
rateBytesPerSecond: elapsedMs > 0 ? Math.round((totalSize / elapsedMs) * 1000) : undefined,
|
|
53849
|
+
elapsedMs,
|
|
53850
|
+
});
|
|
53830
53851
|
}
|
|
53831
53852
|
if (stagedInstallTargets.length === 0) {
|
|
53832
53853
|
return;
|
|
@@ -53846,16 +53867,17 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53846
53867
|
}
|
|
53847
53868
|
});
|
|
53848
53869
|
}
|
|
53849
|
-
protocolV2SourceUpdateProcess({ source, filePath, processedSize, totalSize, }) {
|
|
53870
|
+
protocolV2SourceUpdateProcess({ source, filePath, processedSize, totalSize, transferStartedAt = Date.now(), }) {
|
|
53850
53871
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53851
53872
|
let lastError;
|
|
53852
53873
|
for (let attempt = 1; attempt <= PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT; attempt += 1) {
|
|
53874
|
+
this.throwIfAborted();
|
|
53853
53875
|
try {
|
|
53854
|
-
const transferStartedAt = Date.now();
|
|
53855
53876
|
yield writeFirmwareByteSource({
|
|
53856
53877
|
source,
|
|
53857
53878
|
chunkSize: this.getProtocolV2FirmwareChunkSize('write', filePath),
|
|
53858
53879
|
write: ({ data, sourceOffset, length, first }) => __awaiter(this, void 0, void 0, function* () {
|
|
53880
|
+
this.throwIfAborted();
|
|
53859
53881
|
const chunkEnd = sourceOffset + length;
|
|
53860
53882
|
const deviceProgress = getProtocolV2DeviceTransferProgress(processedSize + sourceOffset, processedSize + chunkEnd, totalSize);
|
|
53861
53883
|
const response = yield this.fileWriteChunk(filePath, source.size, sourceOffset, data, first, deviceProgress);
|
|
@@ -53878,7 +53900,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53878
53900
|
this.postProgressMessage(progress, 'transferData', {
|
|
53879
53901
|
transferredBytes,
|
|
53880
53902
|
totalBytes: totalSize,
|
|
53881
|
-
rateBytesPerSecond: elapsedMs > 0 ? Math.round((
|
|
53903
|
+
rateBytesPerSecond: elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
|
|
53882
53904
|
elapsedMs,
|
|
53883
53905
|
});
|
|
53884
53906
|
}
|
|
@@ -53888,16 +53910,19 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53888
53910
|
return processedSize + source.size;
|
|
53889
53911
|
}
|
|
53890
53912
|
catch (error) {
|
|
53913
|
+
this.throwIfAborted();
|
|
53891
53914
|
if (hdShared.isBleStaleBondHardwareError(error)) {
|
|
53892
53915
|
throw error;
|
|
53893
53916
|
}
|
|
53894
53917
|
lastError = error;
|
|
53895
53918
|
if (attempt < PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT) {
|
|
53896
53919
|
yield this.recoverProtocolV2FileTransfer();
|
|
53920
|
+
this.throwIfAborted();
|
|
53897
53921
|
}
|
|
53898
53922
|
}
|
|
53899
53923
|
}
|
|
53900
|
-
|
|
53924
|
+
const causeCode = getProtocolV2ErrorCode(lastError);
|
|
53925
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.EmmcFileWriteFirmwareError, `transfer data error: ${getProtocolV2UnknownErrorText(lastError)}`, causeCode === undefined ? undefined : { causeCode });
|
|
53901
53926
|
});
|
|
53902
53927
|
}
|
|
53903
53928
|
getProtocolV2InstallItemStagingPath(item) {
|
|
@@ -54244,7 +54269,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54244
54269
|
return;
|
|
54245
54270
|
}
|
|
54246
54271
|
if (!hasCurrentInstallEvidence) {
|
|
54247
|
-
this.device.setCancelableAction(() =>
|
|
54272
|
+
this.device.setCancelableAction(() => Promise.resolve());
|
|
54248
54273
|
}
|
|
54249
54274
|
if (requireCurrentInstallStatus &&
|
|
54250
54275
|
!hasCurrentInstallEvidence &&
|
|
@@ -54590,7 +54615,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54590
54615
|
this.protocolV2InstallTerminalSuccessObserved = false;
|
|
54591
54616
|
const commands = this.device.getCommands();
|
|
54592
54617
|
yield commands.typedCall('DeviceFirmwareUpdateStage', 'Success', { targets });
|
|
54593
|
-
this.device.setCancelableAction(() =>
|
|
54618
|
+
this.device.setCancelableAction(() => Promise.resolve());
|
|
54594
54619
|
const interaction = this.device.createProtocolV2UiPhaseMetadata('button', 'start');
|
|
54595
54620
|
this.postMessage(createUiMessage(UI_REQUEST.REQUEST_BUTTON, Object.assign({ device: this.device.toMessageObject(), source: 'method-lifecycle', reason: 'firmware-update', completion: 'operation-completed', deviceOnly: true, operation: this.name }, (interaction ? { interaction } : {}))));
|
|
54596
54621
|
try {
|
|
@@ -54824,7 +54849,9 @@ const ARCHIVE_ENTRY_SIZE = 296;
|
|
|
54824
54849
|
const ARCHIVE_ENTRY_NAME_MAX_LENGTH = 255;
|
|
54825
54850
|
const ARCHIVE_COMPRESS_LZ4_BLOCKED = 1;
|
|
54826
54851
|
const ARCHIVE_ALIGNMENT = 4;
|
|
54827
|
-
const
|
|
54852
|
+
const LZ4_PREFERRED_BLOCK_SIZE_LOG2 = 14;
|
|
54853
|
+
const LZ4_FALLBACK_BLOCK_SIZE_LOG2 = 13;
|
|
54854
|
+
const LZ4_COMPRESSED_BLOCK_SIZE_MAX = 1 << 14;
|
|
54828
54855
|
function supportsPro2HostAssetPackage(firmwareVersion) {
|
|
54829
54856
|
return Boolean(firmwareVersion &&
|
|
54830
54857
|
semver__default["default"].valid(firmwareVersion) &&
|
|
@@ -54846,7 +54873,7 @@ const LZ4_MAX_OFFSET = 0xffff;
|
|
|
54846
54873
|
const LZ4_LENGTH_MASK = 15;
|
|
54847
54874
|
const LZ4_HASH_LOG = 16;
|
|
54848
54875
|
const LZ4_HASH_MULTIPLIER = 2654435761;
|
|
54849
|
-
const
|
|
54876
|
+
const LZ4_MAX_SEARCH_DEPTH = 64;
|
|
54850
54877
|
function writeExtendedLength(output, offset, length) {
|
|
54851
54878
|
let remaining = length;
|
|
54852
54879
|
let nextOffset = offset;
|
|
@@ -54899,7 +54926,7 @@ function emitLastLiterals(output, outputOffset, input, anchor, literalLength) {
|
|
|
54899
54926
|
}
|
|
54900
54927
|
return copyBytes(output, nextOffset, input, anchor, literalLength);
|
|
54901
54928
|
}
|
|
54902
|
-
function compressRawLz4Block(input, hashTable) {
|
|
54929
|
+
function compressRawLz4Block(input, hashTable, matchChain) {
|
|
54903
54930
|
const output = new Uint8Array(input.byteLength + Math.floor(input.byteLength / 255) + 16);
|
|
54904
54931
|
const inputView = new DataView(input.buffer, input.byteOffset, input.byteLength);
|
|
54905
54932
|
const matchFindLimit = input.byteLength - LZ4_MATCH_FIND_LIMIT;
|
|
@@ -54907,52 +54934,82 @@ function compressRawLz4Block(input, hashTable) {
|
|
|
54907
54934
|
let anchor = 0;
|
|
54908
54935
|
let inputOffset = 0;
|
|
54909
54936
|
let outputOffset = 0;
|
|
54910
|
-
let searchMatchCount = 1 << LZ4_SKIP_TRIGGER;
|
|
54911
54937
|
hashTable.fill(0);
|
|
54912
54938
|
while (inputOffset < matchFindLimit) {
|
|
54913
54939
|
const sequence = inputView.getUint32(inputOffset, true);
|
|
54914
54940
|
const hash = Math.imul(sequence, LZ4_HASH_MULTIPLIER) >>> (32 - LZ4_HASH_LOG);
|
|
54915
|
-
|
|
54941
|
+
let candidate = hashTable[hash] - 1;
|
|
54942
|
+
matchChain[inputOffset] = candidate;
|
|
54916
54943
|
hashTable[hash] = inputOffset + 1;
|
|
54917
|
-
|
|
54918
|
-
|
|
54919
|
-
|
|
54920
|
-
|
|
54921
|
-
inputOffset
|
|
54922
|
-
|
|
54944
|
+
let bestCandidate = -1;
|
|
54945
|
+
let bestMatchEnd = inputOffset;
|
|
54946
|
+
let searchDepth = 0;
|
|
54947
|
+
while (candidate >= 0 &&
|
|
54948
|
+
inputOffset - candidate <= LZ4_MAX_OFFSET &&
|
|
54949
|
+
searchDepth < LZ4_MAX_SEARCH_DEPTH) {
|
|
54950
|
+
if (inputView.getUint32(candidate, true) === sequence) {
|
|
54951
|
+
let matchEnd = inputOffset + LZ4_MIN_MATCH;
|
|
54952
|
+
let reference = candidate + LZ4_MIN_MATCH;
|
|
54953
|
+
while (matchEnd < matchExtendLimit && input[matchEnd] === input[reference]) {
|
|
54954
|
+
matchEnd += 1;
|
|
54955
|
+
reference += 1;
|
|
54956
|
+
}
|
|
54957
|
+
if (matchEnd > bestMatchEnd) {
|
|
54958
|
+
bestCandidate = candidate;
|
|
54959
|
+
bestMatchEnd = matchEnd;
|
|
54960
|
+
}
|
|
54961
|
+
}
|
|
54962
|
+
candidate = matchChain[candidate];
|
|
54963
|
+
searchDepth += 1;
|
|
54964
|
+
}
|
|
54965
|
+
if (bestCandidate < 0) {
|
|
54966
|
+
inputOffset += 1;
|
|
54923
54967
|
}
|
|
54924
54968
|
else {
|
|
54925
|
-
|
|
54926
|
-
|
|
54927
|
-
|
|
54928
|
-
while (matchEnd < matchExtendLimit && input[matchEnd] === input[reference]) {
|
|
54929
|
-
matchEnd += 1;
|
|
54930
|
-
reference += 1;
|
|
54931
|
-
}
|
|
54932
|
-
outputOffset = emitSequence(output, outputOffset, input, anchor, inputOffset - anchor, inputOffset - candidate, matchEnd - inputOffset - LZ4_MIN_MATCH);
|
|
54933
|
-
inputOffset = matchEnd;
|
|
54969
|
+
const matchStart = inputOffset;
|
|
54970
|
+
outputOffset = emitSequence(output, outputOffset, input, anchor, inputOffset - anchor, inputOffset - bestCandidate, bestMatchEnd - inputOffset - LZ4_MIN_MATCH);
|
|
54971
|
+
inputOffset = bestMatchEnd;
|
|
54934
54972
|
anchor = inputOffset;
|
|
54973
|
+
for (let skippedOffset = matchStart + 1; skippedOffset < inputOffset && skippedOffset < matchFindLimit; skippedOffset += 1) {
|
|
54974
|
+
const skippedSequence = inputView.getUint32(skippedOffset, true);
|
|
54975
|
+
const skippedHash = Math.imul(skippedSequence, LZ4_HASH_MULTIPLIER) >>> (32 - LZ4_HASH_LOG);
|
|
54976
|
+
matchChain[skippedOffset] = hashTable[skippedHash] - 1;
|
|
54977
|
+
hashTable[skippedHash] = skippedOffset + 1;
|
|
54978
|
+
}
|
|
54935
54979
|
}
|
|
54936
54980
|
}
|
|
54937
54981
|
outputOffset = emitLastLiterals(output, outputOffset, input, anchor, input.byteLength - anchor);
|
|
54938
54982
|
return output.slice(0, outputOffset);
|
|
54939
54983
|
}
|
|
54940
|
-
function
|
|
54941
|
-
const blockSize = 1 <<
|
|
54984
|
+
function encodeLz4BlockedWithBlockSize(data, blockSizeLog2) {
|
|
54985
|
+
const blockSize = 1 << blockSizeLog2;
|
|
54942
54986
|
const blockCount = Math.ceil(data.byteLength / blockSize);
|
|
54943
54987
|
const hashTable = new Uint32Array(1 << LZ4_HASH_LOG);
|
|
54988
|
+
const matchChain = new Int32Array(blockSize);
|
|
54944
54989
|
const blocks = [];
|
|
54945
54990
|
const header = new Uint8Array(8 + blockCount * 4);
|
|
54946
54991
|
const headerView = new DataView(header.buffer);
|
|
54947
54992
|
headerView.setUint16(0, blockCount, true);
|
|
54948
|
-
headerView.setUint16(2,
|
|
54993
|
+
headerView.setUint16(2, blockSizeLog2, true);
|
|
54949
54994
|
for (let index = 0; index < blockCount; index += 1) {
|
|
54950
|
-
const block = compressRawLz4Block(data.subarray(index * blockSize, Math.min((index + 1) * blockSize, data.byteLength)), hashTable);
|
|
54995
|
+
const block = compressRawLz4Block(data.subarray(index * blockSize, Math.min((index + 1) * blockSize, data.byteLength)), hashTable, matchChain);
|
|
54996
|
+
if (block.byteLength > LZ4_COMPRESSED_BLOCK_SIZE_MAX)
|
|
54997
|
+
return undefined;
|
|
54951
54998
|
headerView.setUint32(8 + index * 4, block.byteLength, true);
|
|
54952
54999
|
blocks.push(block);
|
|
54953
55000
|
}
|
|
54954
55001
|
return concatBytes([header, ...blocks]);
|
|
54955
55002
|
}
|
|
55003
|
+
function encodeLz4Blocked(data) {
|
|
55004
|
+
const preferred = encodeLz4BlockedWithBlockSize(data, LZ4_PREFERRED_BLOCK_SIZE_LOG2);
|
|
55005
|
+
if (preferred)
|
|
55006
|
+
return preferred;
|
|
55007
|
+
const fallback = encodeLz4BlockedWithBlockSize(data, LZ4_FALLBACK_BLOCK_SIZE_LOG2);
|
|
55008
|
+
if (!fallback) {
|
|
55009
|
+
throw new Error('Pro2 host asset package LZ4 block exceeds the firmware buffer limit.');
|
|
55010
|
+
}
|
|
55011
|
+
return fallback;
|
|
55012
|
+
}
|
|
54956
55013
|
const CRC32_TABLE = (() => {
|
|
54957
55014
|
const table = new Uint32Array(256);
|
|
54958
55015
|
for (let index = 0; index < table.length; index += 1) {
|
|
@@ -55039,6 +55096,7 @@ const SAFE_FILE_NAME = /^[A-Za-z0-9_-]+(?:\.bin)?$/;
|
|
|
55039
55096
|
const DEVICE_SETTINGS_SET_MESSAGE_TYPE = 60412;
|
|
55040
55097
|
const FILESYSTEM_FILE_WRITE_MESSAGE_TYPE$2 = 60805;
|
|
55041
55098
|
const FILESYSTEM_DIR_MAKE_MESSAGE_TYPE = 60809;
|
|
55099
|
+
const WALLPAPER_PACKAGE_BLE_CHUNK_SIZE = 1960;
|
|
55042
55100
|
const Log$4 = getLogger(exports.LoggerNames.Method);
|
|
55043
55101
|
function normalizeFileName(fileName, data) {
|
|
55044
55102
|
if (fileName !== undefined && (!fileName || !SAFE_FILE_NAME.test(fileName))) {
|
|
@@ -55110,7 +55168,7 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
55110
55168
|
this.directoryReady = true;
|
|
55111
55169
|
});
|
|
55112
55170
|
}
|
|
55113
|
-
upload(path, data) {
|
|
55171
|
+
upload(path, data, bleChunkSizeLimit) {
|
|
55114
55172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55115
55173
|
if (this.uploaded)
|
|
55116
55174
|
return;
|
|
@@ -55120,6 +55178,7 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
55120
55178
|
data,
|
|
55121
55179
|
totalSize: data.byteLength,
|
|
55122
55180
|
chunkSize: this.params.chunkSize,
|
|
55181
|
+
bleChunkSizeLimit,
|
|
55123
55182
|
maxChunkRetries: 3,
|
|
55124
55183
|
overwrite: true,
|
|
55125
55184
|
append: false,
|
|
@@ -55147,7 +55206,7 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
55147
55206
|
: encoded.data;
|
|
55148
55207
|
if (useHostAssetPackage)
|
|
55149
55208
|
this.path = WALLPAPER_PACKAGE_PATH;
|
|
55150
|
-
yield this.upload(this.path, data);
|
|
55209
|
+
yield this.upload(this.path, data, useHostAssetPackage ? WALLPAPER_PACKAGE_BLE_CHUNK_SIZE : undefined);
|
|
55151
55210
|
const response = yield this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
55152
55211
|
settings: { wallpaper_path: this.path },
|
|
55153
55212
|
});
|
|
@@ -66366,18 +66425,19 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
66366
66425
|
!device.commands ||
|
|
66367
66426
|
device.commands.disposed;
|
|
66368
66427
|
if (shouldAcquire) {
|
|
66428
|
+
const connectProtocol = resolveBleConnectProtocol(method);
|
|
66369
66429
|
const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
|
|
66370
66430
|
if (useAcquireGuards && (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
66371
66431
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
66372
66432
|
}
|
|
66373
66433
|
if (!useAcquireGuards) {
|
|
66374
|
-
yield device.acquire(
|
|
66434
|
+
yield device.acquire(connectProtocol, {
|
|
66375
66435
|
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
66376
66436
|
});
|
|
66377
66437
|
}
|
|
66378
66438
|
else {
|
|
66379
66439
|
try {
|
|
66380
|
-
yield raceBleAcquire(device.acquire(
|
|
66440
|
+
yield raceBleAcquire(device.acquire(connectProtocol, {
|
|
66381
66441
|
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
66382
66442
|
}), abortSignal);
|
|
66383
66443
|
}
|
|
@@ -66429,6 +66489,13 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
|
66429
66489
|
}
|
|
66430
66490
|
});
|
|
66431
66491
|
}
|
|
66492
|
+
function resolveBleConnectProtocol(method) {
|
|
66493
|
+
if (method.payload.connectProtocol === 'V1' || method.payload.connectProtocol === 'V2') {
|
|
66494
|
+
return method.payload.connectProtocol;
|
|
66495
|
+
}
|
|
66496
|
+
const supportedProtocols = method.getSupportedProtocols();
|
|
66497
|
+
return supportedProtocols.length === 1 && supportedProtocols[0] === 'V2' ? 'V2' : undefined;
|
|
66498
|
+
}
|
|
66432
66499
|
const ensureConnected = (_context, method, connectId, pollingId, abortSignal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66433
66500
|
let tryCount = 0;
|
|
66434
66501
|
const MAX_RETRY_COUNT = method.payload && typeof method.payload.retryCount === 'number' ? method.payload.retryCount : 5;
|
|
@@ -66584,7 +66651,7 @@ const cancel = (context, connectId) => {
|
|
|
66584
66651
|
requestQueue.cancelCallbackTasks(connectId);
|
|
66585
66652
|
const requestIds = requestQueue.getRequestTasksId();
|
|
66586
66653
|
Log.debug(`Cancel Api connect requestQueues: length:${requestIds.length} requestIds:${requestIds.join(',')}`);
|
|
66587
|
-
requestQueue.
|
|
66654
|
+
requestQueue.abortAllRequests();
|
|
66588
66655
|
const canceledDevices = [];
|
|
66589
66656
|
const interruptDevice = (device, deviceConnectId) => {
|
|
66590
66657
|
if (!device || canceledDevices.includes(device)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/walletSession.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuBlD,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,0DAGjE;AAED,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,qCAGjE;AAED,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,MAAM,oBAgBzE;AA8JD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;;;;;;
|
|
1
|
+
{"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/walletSession.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuBlD,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,0DAGjE;AAED,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,qCAGjE;AAED,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,MAAM,oBAgBzE;AA8JD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;;;;;;GAyXF;AAED,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,uBAAuB,EAAE,MAAM,EAC/B,aAAa,CAAC,EAAE,OAAO;;;;;;GAOxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pro2HostAssetPackage.d.ts","sourceRoot":"","sources":["../../src/utils/pro2HostAssetPackage.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,mCAAmC,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"pro2HostAssetPackage.d.ts","sourceRoot":"","sources":["../../src/utils/pro2HostAssetPackage.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,mCAAmC,UAAU,CAAC;AA0B3D,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC;AAQF,wBAAgB,4BAA4B,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAMzF;AAuTD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,yBAAyB,EAAE,GAAG,UAAU,CA4B1F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.2-alpha.
|
|
3
|
+
"version": "1.2.2-alpha.8",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.2-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.2-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.2-alpha.8",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.2-alpha.8",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"buffer": "^6.0.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/w3c-web-usb": "^1.0.10",
|
|
47
47
|
"@types/web-bluetooth": "^0.0.21"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "7a5d129ea1db0b3eb230e309ab29ed3e9e7f141e"
|
|
50
50
|
}
|
|
@@ -383,6 +383,13 @@ const isProtocolV2InstallResponseTimeout = (error: unknown) => {
|
|
|
383
383
|
);
|
|
384
384
|
};
|
|
385
385
|
|
|
386
|
+
const getProtocolV2ErrorCode = (error: unknown): number | string | undefined => {
|
|
387
|
+
if (!error || typeof error !== 'object') return undefined;
|
|
388
|
+
const { errorCode, code } = error as { errorCode?: unknown; code?: unknown };
|
|
389
|
+
const causeCode = errorCode ?? code;
|
|
390
|
+
return typeof causeCode === 'number' || typeof causeCode === 'string' ? causeCode : undefined;
|
|
391
|
+
};
|
|
392
|
+
|
|
386
393
|
const isProtocolV2TerminalInstallStatusError = (error: unknown) =>
|
|
387
394
|
isBleStaleBondHardwareError(error) ||
|
|
388
395
|
(error instanceof HardwareError &&
|
|
@@ -2114,6 +2121,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2114
2121
|
this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
|
|
2115
2122
|
this.protocolV2LastTransferProgress = undefined;
|
|
2116
2123
|
this.protocolV2LastTransferProgressAt = 0;
|
|
2124
|
+
const transferStartedAt = Date.now();
|
|
2117
2125
|
let processedSize = 0;
|
|
2118
2126
|
for (const resource of resourcesToSync) {
|
|
2119
2127
|
// The bootloader keeps its live resource package mounted. FatFs rejects
|
|
@@ -2124,6 +2132,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2124
2132
|
filePath: writePath,
|
|
2125
2133
|
processedSize,
|
|
2126
2134
|
totalSize,
|
|
2135
|
+
transferStartedAt,
|
|
2127
2136
|
});
|
|
2128
2137
|
await this.verifyProtocolV2StagedFile(writePath, resource.source.size);
|
|
2129
2138
|
if (isProtocolV2BootResourcePackagePath(resource.devicePath)) {
|
|
@@ -2139,6 +2148,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2139
2148
|
filePath,
|
|
2140
2149
|
processedSize,
|
|
2141
2150
|
totalSize,
|
|
2151
|
+
transferStartedAt,
|
|
2142
2152
|
});
|
|
2143
2153
|
await this.verifyProtocolV2StagedFile(filePath, item.source.size);
|
|
2144
2154
|
stagedInstallTargets.push({
|
|
@@ -2148,7 +2158,13 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2148
2158
|
}
|
|
2149
2159
|
|
|
2150
2160
|
if (totalSize > 0) {
|
|
2151
|
-
|
|
2161
|
+
const elapsedMs = Math.max(Date.now() - transferStartedAt, 0);
|
|
2162
|
+
this.postProgressMessage(100, 'transferData', {
|
|
2163
|
+
transferredBytes: totalSize,
|
|
2164
|
+
totalBytes: totalSize,
|
|
2165
|
+
rateBytesPerSecond: elapsedMs > 0 ? Math.round((totalSize / elapsedMs) * 1000) : undefined,
|
|
2166
|
+
elapsedMs,
|
|
2167
|
+
});
|
|
2152
2168
|
}
|
|
2153
2169
|
if (stagedInstallTargets.length === 0) {
|
|
2154
2170
|
return;
|
|
@@ -2173,20 +2189,23 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2173
2189
|
filePath,
|
|
2174
2190
|
processedSize,
|
|
2175
2191
|
totalSize,
|
|
2192
|
+
transferStartedAt = Date.now(),
|
|
2176
2193
|
}: {
|
|
2177
2194
|
source: FirmwareByteSource;
|
|
2178
2195
|
filePath: string;
|
|
2179
2196
|
processedSize: number;
|
|
2180
2197
|
totalSize: number;
|
|
2198
|
+
transferStartedAt?: number;
|
|
2181
2199
|
}) {
|
|
2182
2200
|
let lastError: unknown;
|
|
2183
2201
|
for (let attempt = 1; attempt <= PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT; attempt += 1) {
|
|
2202
|
+
this.throwIfAborted();
|
|
2184
2203
|
try {
|
|
2185
|
-
const transferStartedAt = Date.now();
|
|
2186
2204
|
await writeFirmwareByteSource({
|
|
2187
2205
|
source,
|
|
2188
2206
|
chunkSize: this.getProtocolV2FirmwareChunkSize('write', filePath),
|
|
2189
2207
|
write: async ({ data, sourceOffset, length, first }) => {
|
|
2208
|
+
this.throwIfAborted();
|
|
2190
2209
|
const chunkEnd = sourceOffset + length;
|
|
2191
2210
|
const deviceProgress = getProtocolV2DeviceTransferProgress(
|
|
2192
2211
|
processedSize + sourceOffset,
|
|
@@ -2225,7 +2244,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2225
2244
|
transferredBytes,
|
|
2226
2245
|
totalBytes: totalSize,
|
|
2227
2246
|
rateBytesPerSecond:
|
|
2228
|
-
elapsedMs > 0 ? Math.round((
|
|
2247
|
+
elapsedMs > 0 ? Math.round((transferredBytes / elapsedMs) * 1000) : undefined,
|
|
2229
2248
|
elapsedMs,
|
|
2230
2249
|
});
|
|
2231
2250
|
}
|
|
@@ -2234,18 +2253,22 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2234
2253
|
});
|
|
2235
2254
|
return processedSize + source.size;
|
|
2236
2255
|
} catch (error) {
|
|
2256
|
+
this.throwIfAborted();
|
|
2237
2257
|
if (isBleStaleBondHardwareError(error)) {
|
|
2238
2258
|
throw error;
|
|
2239
2259
|
}
|
|
2240
2260
|
lastError = error;
|
|
2241
2261
|
if (attempt < PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT) {
|
|
2242
2262
|
await this.recoverProtocolV2FileTransfer();
|
|
2263
|
+
this.throwIfAborted();
|
|
2243
2264
|
}
|
|
2244
2265
|
}
|
|
2245
2266
|
}
|
|
2267
|
+
const causeCode = getProtocolV2ErrorCode(lastError);
|
|
2246
2268
|
throw ERRORS.TypedError(
|
|
2247
2269
|
HardwareErrorCode.EmmcFileWriteFirmwareError,
|
|
2248
|
-
`transfer data error: ${getProtocolV2UnknownErrorText(lastError)}
|
|
2270
|
+
`transfer data error: ${getProtocolV2UnknownErrorText(lastError)}`,
|
|
2271
|
+
causeCode === undefined ? undefined : { causeCode }
|
|
2249
2272
|
);
|
|
2250
2273
|
}
|
|
2251
2274
|
|
|
@@ -2705,7 +2728,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2705
2728
|
if (!hasCurrentInstallEvidence) {
|
|
2706
2729
|
// A successful status poll clears DeviceCommands' cancel action. Keep cancellation
|
|
2707
2730
|
// available while UpdateRequest is still waiting for confirmation on the device.
|
|
2708
|
-
|
|
2731
|
+
// Bootloader does not register the protocol Cancel message. Keep the
|
|
2732
|
+
// operation locally cancellable; interruptionFromUser() disposes the link.
|
|
2733
|
+
this.device.setCancelableAction(() => Promise.resolve());
|
|
2709
2734
|
}
|
|
2710
2735
|
|
|
2711
2736
|
if (
|
|
@@ -3174,7 +3199,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
3174
3199
|
this.protocolV2InstallTerminalSuccessObserved = false;
|
|
3175
3200
|
const commands = this.device.getCommands();
|
|
3176
3201
|
await commands.typedCall('DeviceFirmwareUpdateStage', 'Success', { targets });
|
|
3177
|
-
|
|
3202
|
+
// Bootloader does not register the protocol Cancel message. Keep the
|
|
3203
|
+
// operation locally cancellable; interruptionFromUser() disposes the link.
|
|
3204
|
+
this.device.setCancelableAction(() => Promise.resolve());
|
|
3178
3205
|
const interaction = this.device.createProtocolV2UiPhaseMetadata('button', 'start');
|
|
3179
3206
|
this.postMessage(
|
|
3180
3207
|
createUiMessage(UI_REQUEST.REQUEST_BUTTON, {
|
|
@@ -36,6 +36,8 @@ export type ProtocolV2FileWriteOptions = {
|
|
|
36
36
|
chunkSize?: number;
|
|
37
37
|
chunkLen?: number;
|
|
38
38
|
chunkSizeLimit?: number;
|
|
39
|
+
/** BLE-only limit for a caller whose fixed short path has a verified larger frame budget. */
|
|
40
|
+
bleChunkSizeLimit?: number;
|
|
39
41
|
overwrite?: boolean;
|
|
40
42
|
append?: boolean;
|
|
41
43
|
uiPercentage?: number;
|
|
@@ -114,11 +116,15 @@ export function isProtocolV2ResponseTimeout(error: unknown) {
|
|
|
114
116
|
);
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
function getProtocolV2FileChunkLimit() {
|
|
119
|
+
function getProtocolV2FileChunkLimit(bleChunkSizeLimit?: number) {
|
|
118
120
|
const env = DataManager.getSettings('env');
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
if (env && DataManager.isBleConnect(env)) {
|
|
122
|
+
const configuredLimit = Number(bleChunkSizeLimit);
|
|
123
|
+
return Number.isFinite(configuredLimit) && configuredLimit > 0
|
|
124
|
+
? Math.floor(configuredLimit)
|
|
125
|
+
: PROTOCOL_V2_BLE_FILE_CHUNK_SIZE;
|
|
126
|
+
}
|
|
127
|
+
return PROTOCOL_V2_WEBUSB_FILE_CHUNK_SIZE;
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
async function dataToUint8Array(data: ProtocolV2FileWriteData): Promise<Uint8Array> {
|
|
@@ -178,7 +184,7 @@ export async function writeProtocolV2File(options: ProtocolV2FileWriteOptions) {
|
|
|
178
184
|
);
|
|
179
185
|
}
|
|
180
186
|
|
|
181
|
-
const defaultChunkSizeLimit = getProtocolV2FileChunkLimit();
|
|
187
|
+
const defaultChunkSizeLimit = getProtocolV2FileChunkLimit(options.bleChunkSizeLimit);
|
|
182
188
|
const configuredChunkSizeLimit = Number(options.chunkSizeLimit);
|
|
183
189
|
const chunkSizeLimit =
|
|
184
190
|
Number.isFinite(configuredChunkSizeLimit) && configuredChunkSizeLimit > 0
|
|
@@ -49,6 +49,7 @@ const SAFE_FILE_NAME = /^[A-Za-z0-9_-]+(?:\.bin)?$/;
|
|
|
49
49
|
const DEVICE_SETTINGS_SET_MESSAGE_TYPE = 60412;
|
|
50
50
|
const FILESYSTEM_FILE_WRITE_MESSAGE_TYPE = 60805;
|
|
51
51
|
const FILESYSTEM_DIR_MAKE_MESSAGE_TYPE = 60809;
|
|
52
|
+
const WALLPAPER_PACKAGE_BLE_CHUNK_SIZE = 1960;
|
|
52
53
|
const Log = getLogger(LoggerNames.Method);
|
|
53
54
|
|
|
54
55
|
function normalizeFileName(fileName: string | undefined, data: Uint8Array): string {
|
|
@@ -130,7 +131,7 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
|
|
|
130
131
|
this.directoryReady = true;
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
private async upload(path: string, data: Uint8Array) {
|
|
134
|
+
private async upload(path: string, data: Uint8Array, bleChunkSizeLimit?: number) {
|
|
134
135
|
if (this.uploaded) return;
|
|
135
136
|
|
|
136
137
|
await writeProtocolV2File({
|
|
@@ -139,6 +140,7 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
|
|
|
139
140
|
data,
|
|
140
141
|
totalSize: data.byteLength,
|
|
141
142
|
chunkSize: this.params.chunkSize,
|
|
143
|
+
bleChunkSizeLimit,
|
|
142
144
|
maxChunkRetries: 3,
|
|
143
145
|
overwrite: true,
|
|
144
146
|
append: false,
|
|
@@ -164,7 +166,11 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
|
|
|
164
166
|
? buildPro2HostAssetPackage([{ name: WALLPAPER_PACKAGE_ENTRY, data: encoded.data }])
|
|
165
167
|
: encoded.data;
|
|
166
168
|
if (useHostAssetPackage) this.path = WALLPAPER_PACKAGE_PATH;
|
|
167
|
-
await this.upload(
|
|
169
|
+
await this.upload(
|
|
170
|
+
this.path,
|
|
171
|
+
data,
|
|
172
|
+
useHostAssetPackage ? WALLPAPER_PACKAGE_BLE_CHUNK_SIZE : undefined
|
|
173
|
+
);
|
|
168
174
|
const response = await this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
169
175
|
settings: { wallpaper_path: this.path },
|
|
170
176
|
});
|