@onekeyfe/hd-core 1.2.0-alpha.171 → 1.2.0-alpha.173
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__/firmware-update/firmware-update-v4-install-poll.test.ts +32 -3
- package/__tests__/pro2Wallpaper.test.ts +0 -66
- package/__tests__/protocol-v2.test.ts +50 -35
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +1 -2
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.js +79 -197
- package/dist/utils/pro2Wallpaper.d.ts +1 -3
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +31 -35
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +2 -12
- package/src/core/index.ts +100 -6
- package/src/utils/pro2Wallpaper.ts +1 -197
package/dist/index.js
CHANGED
|
@@ -42476,18 +42476,6 @@ const PRO2_WALLPAPER_WIDTH = 604;
|
|
|
42476
42476
|
const PRO2_WALLPAPER_HEIGHT = 1024;
|
|
42477
42477
|
const COLOR_FORMAT_RGB565 = 0x12;
|
|
42478
42478
|
const COLOR_FORMAT_RGB565A8 = 0x14;
|
|
42479
|
-
const COLOR_FORMAT_I8 = 0x0a;
|
|
42480
|
-
const IMAGE_FLAG_COMPRESSED = 0x0008;
|
|
42481
|
-
const IMAGE_COMPRESSION_LZ4 = 0x00000002;
|
|
42482
|
-
const I8_PALETTE_SIZE = 256 * 4;
|
|
42483
|
-
const I8_RED_LEVELS = 6;
|
|
42484
|
-
const I8_GREEN_LEVELS = 7;
|
|
42485
|
-
const I8_BLUE_LEVELS = 6;
|
|
42486
|
-
const LZ4_MIN_MATCH = 4;
|
|
42487
|
-
const LZ4_LAST_LITERALS = 5;
|
|
42488
|
-
const LZ4_MATCH_FIND_LIMIT = 12;
|
|
42489
|
-
const LZ4_HASH_BITS = 16;
|
|
42490
|
-
const LZ4_HASH_MULTIPLIER = -1640531535;
|
|
42491
42479
|
const RED_THRESHOLD = [
|
|
42492
42480
|
1, 7, 3, 5, 0, 8, 2, 6, 7, 1, 5, 3, 8, 0, 6, 2, 3, 5, 0, 8, 2, 6, 1, 7, 5, 3, 8, 0, 6, 2, 7, 1, 0,
|
|
42493
42481
|
8, 2, 6, 1, 7, 3, 5, 8, 0, 6, 2, 7, 1, 5, 3, 2, 6, 1, 7, 3, 5, 0, 8, 6, 2, 7, 1, 5, 3, 8, 0,
|
|
@@ -42509,149 +42497,6 @@ function asBytes(rgba) {
|
|
|
42509
42497
|
function align(value, boundary) {
|
|
42510
42498
|
return Math.ceil(value / boundary) * boundary;
|
|
42511
42499
|
}
|
|
42512
|
-
function writeLz4Length(output, offset, length) {
|
|
42513
|
-
let cursor = offset;
|
|
42514
|
-
let remaining = length;
|
|
42515
|
-
while (remaining >= 0xff) {
|
|
42516
|
-
output[cursor] = 0xff;
|
|
42517
|
-
cursor += 1;
|
|
42518
|
-
remaining -= 0xff;
|
|
42519
|
-
}
|
|
42520
|
-
output[cursor] = remaining;
|
|
42521
|
-
return cursor + 1;
|
|
42522
|
-
}
|
|
42523
|
-
function readUint32LittleEndian(data, offset) {
|
|
42524
|
-
return (data[offset] | (data[offset + 1] << 8) | (data[offset + 2] << 16) | (data[offset + 3] << 24));
|
|
42525
|
-
}
|
|
42526
|
-
function getLz4Hash(sequence) {
|
|
42527
|
-
return (Math.imul(sequence, LZ4_HASH_MULTIPLIER) >>> (32 - LZ4_HASH_BITS)) & 0xffff;
|
|
42528
|
-
}
|
|
42529
|
-
function compressLz4Block(input) {
|
|
42530
|
-
const output = new Uint8Array(input.byteLength + Math.floor(input.byteLength / 0xff) + 16);
|
|
42531
|
-
const hashTable = new Int32Array(1 << LZ4_HASH_BITS);
|
|
42532
|
-
hashTable.fill(-1);
|
|
42533
|
-
let anchor = 0;
|
|
42534
|
-
let inputOffset = 0;
|
|
42535
|
-
let outputOffset = 0;
|
|
42536
|
-
const matchFindEnd = input.byteLength - LZ4_MATCH_FIND_LIMIT;
|
|
42537
|
-
const matchCopyEnd = input.byteLength - LZ4_LAST_LITERALS;
|
|
42538
|
-
while (inputOffset <= matchFindEnd) {
|
|
42539
|
-
const sequence = readUint32LittleEndian(input, inputOffset);
|
|
42540
|
-
const hash = getLz4Hash(sequence);
|
|
42541
|
-
const reference = hashTable[hash];
|
|
42542
|
-
hashTable[hash] = inputOffset;
|
|
42543
|
-
const matchOffset = inputOffset - reference;
|
|
42544
|
-
const hasMatch = reference >= 0 &&
|
|
42545
|
-
matchOffset <= 0xffff &&
|
|
42546
|
-
readUint32LittleEndian(input, reference) === sequence;
|
|
42547
|
-
if (hasMatch) {
|
|
42548
|
-
let matchLength = LZ4_MIN_MATCH;
|
|
42549
|
-
while (inputOffset + matchLength < matchCopyEnd &&
|
|
42550
|
-
input[reference + matchLength] === input[inputOffset + matchLength]) {
|
|
42551
|
-
matchLength += 1;
|
|
42552
|
-
}
|
|
42553
|
-
const literalLength = inputOffset - anchor;
|
|
42554
|
-
const encodedMatchLength = matchLength - LZ4_MIN_MATCH;
|
|
42555
|
-
const tokenOffset = outputOffset;
|
|
42556
|
-
outputOffset += 1;
|
|
42557
|
-
output[tokenOffset] =
|
|
42558
|
-
(Math.min(literalLength, 0x0f) << 4) | Math.min(encodedMatchLength, 0x0f);
|
|
42559
|
-
if (literalLength >= 0x0f) {
|
|
42560
|
-
outputOffset = writeLz4Length(output, outputOffset, literalLength - 0x0f);
|
|
42561
|
-
}
|
|
42562
|
-
output.set(input.subarray(anchor, inputOffset), outputOffset);
|
|
42563
|
-
outputOffset += literalLength;
|
|
42564
|
-
output[outputOffset] = matchOffset & 0xff;
|
|
42565
|
-
output[outputOffset + 1] = matchOffset >> 8;
|
|
42566
|
-
outputOffset += 2;
|
|
42567
|
-
if (encodedMatchLength >= 0x0f) {
|
|
42568
|
-
outputOffset = writeLz4Length(output, outputOffset, encodedMatchLength - 0x0f);
|
|
42569
|
-
}
|
|
42570
|
-
const matchStart = inputOffset;
|
|
42571
|
-
inputOffset += matchLength;
|
|
42572
|
-
anchor = inputOffset;
|
|
42573
|
-
for (let cursor = Math.max(matchStart + 1, inputOffset - 2); cursor < inputOffset; cursor += 1) {
|
|
42574
|
-
if (cursor <= matchFindEnd) {
|
|
42575
|
-
hashTable[getLz4Hash(readUint32LittleEndian(input, cursor))] = cursor;
|
|
42576
|
-
}
|
|
42577
|
-
}
|
|
42578
|
-
}
|
|
42579
|
-
else {
|
|
42580
|
-
inputOffset += 1;
|
|
42581
|
-
}
|
|
42582
|
-
}
|
|
42583
|
-
const literalLength = input.byteLength - anchor;
|
|
42584
|
-
const tokenOffset = outputOffset;
|
|
42585
|
-
outputOffset += 1;
|
|
42586
|
-
output[tokenOffset] = Math.min(literalLength, 0x0f) << 4;
|
|
42587
|
-
if (literalLength >= 0x0f) {
|
|
42588
|
-
outputOffset = writeLz4Length(output, outputOffset, literalLength - 0x0f);
|
|
42589
|
-
}
|
|
42590
|
-
output.set(input.subarray(anchor), outputOffset);
|
|
42591
|
-
outputOffset += literalLength;
|
|
42592
|
-
return output.slice(0, outputOffset);
|
|
42593
|
-
}
|
|
42594
|
-
function quantizeChannel(value, levels) {
|
|
42595
|
-
return Math.floor((value * (levels - 1) + 0x7f) / 0xff);
|
|
42596
|
-
}
|
|
42597
|
-
function expandChannel(value, levels) {
|
|
42598
|
-
return Math.floor((value * 0xff + Math.floor((levels - 1) / 2)) / (levels - 1));
|
|
42599
|
-
}
|
|
42600
|
-
function encodePro2I8Lz4(options) {
|
|
42601
|
-
const { width, height } = options;
|
|
42602
|
-
if (!Number.isInteger(width) || width <= 0 || width > 0xffff) {
|
|
42603
|
-
throw invalidParameter$2('Wallpaper width must be an integer between 1 and 65535.');
|
|
42604
|
-
}
|
|
42605
|
-
if (!Number.isInteger(height) || height <= 0 || height > 0xffff) {
|
|
42606
|
-
throw invalidParameter$2('Wallpaper height must be an integer between 1 and 65535.');
|
|
42607
|
-
}
|
|
42608
|
-
const rgba = asBytes(options.rgba);
|
|
42609
|
-
const expectedLength = width * height * 4;
|
|
42610
|
-
if (rgba.byteLength !== expectedLength) {
|
|
42611
|
-
throw invalidParameter$2(`Wallpaper RGBA data length must be ${expectedLength} bytes, received ${rgba.byteLength}.`);
|
|
42612
|
-
}
|
|
42613
|
-
const stride = width;
|
|
42614
|
-
const rawData = new Uint8Array(I8_PALETTE_SIZE + stride * height);
|
|
42615
|
-
for (let red = 0; red < I8_RED_LEVELS; red += 1) {
|
|
42616
|
-
for (let green = 0; green < I8_GREEN_LEVELS; green += 1) {
|
|
42617
|
-
for (let blue = 0; blue < I8_BLUE_LEVELS; blue += 1) {
|
|
42618
|
-
const paletteIndex = (red * I8_GREEN_LEVELS + green) * I8_BLUE_LEVELS + blue;
|
|
42619
|
-
const paletteOffset = paletteIndex * 4;
|
|
42620
|
-
rawData[paletteOffset] = expandChannel(blue, I8_BLUE_LEVELS);
|
|
42621
|
-
rawData[paletteOffset + 1] = expandChannel(green, I8_GREEN_LEVELS);
|
|
42622
|
-
rawData[paletteOffset + 2] = expandChannel(red, I8_RED_LEVELS);
|
|
42623
|
-
rawData[paletteOffset + 3] = 0xff;
|
|
42624
|
-
}
|
|
42625
|
-
}
|
|
42626
|
-
}
|
|
42627
|
-
for (let pixel = 0; pixel < width * height; pixel += 1) {
|
|
42628
|
-
const sourceOffset = pixel * 4;
|
|
42629
|
-
const alpha = rgba[sourceOffset + 3];
|
|
42630
|
-
const red = Math.round((rgba[sourceOffset] * alpha) / 0xff);
|
|
42631
|
-
const green = Math.round((rgba[sourceOffset + 1] * alpha) / 0xff);
|
|
42632
|
-
const blue = Math.round((rgba[sourceOffset + 2] * alpha) / 0xff);
|
|
42633
|
-
const paletteIndex = (quantizeChannel(red, I8_RED_LEVELS) * I8_GREEN_LEVELS +
|
|
42634
|
-
quantizeChannel(green, I8_GREEN_LEVELS)) *
|
|
42635
|
-
I8_BLUE_LEVELS +
|
|
42636
|
-
quantizeChannel(blue, I8_BLUE_LEVELS);
|
|
42637
|
-
rawData[I8_PALETTE_SIZE + pixel] = paletteIndex;
|
|
42638
|
-
}
|
|
42639
|
-
const compressed = compressLz4Block(rawData);
|
|
42640
|
-
const data = new Uint8Array(24 + compressed.byteLength);
|
|
42641
|
-
const view = new DataView(data.buffer);
|
|
42642
|
-
data[0] = 0x19;
|
|
42643
|
-
data[1] = COLOR_FORMAT_I8;
|
|
42644
|
-
view.setUint16(2, IMAGE_FLAG_COMPRESSED, true);
|
|
42645
|
-
view.setUint16(4, width, true);
|
|
42646
|
-
view.setUint16(6, height, true);
|
|
42647
|
-
view.setUint16(8, stride, true);
|
|
42648
|
-
view.setUint16(10, 0, true);
|
|
42649
|
-
view.setUint32(12, IMAGE_COMPRESSION_LZ4, true);
|
|
42650
|
-
view.setUint32(16, compressed.byteLength, true);
|
|
42651
|
-
view.setUint32(20, rawData.byteLength, true);
|
|
42652
|
-
data.set(compressed, 24);
|
|
42653
|
-
return { data, colorFormat: 'I8' };
|
|
42654
|
-
}
|
|
42655
42500
|
function encodePro2Image(options) {
|
|
42656
42501
|
var _a;
|
|
42657
42502
|
const { width, height } = options;
|
|
@@ -42719,9 +42564,6 @@ function encodePro2Image(options) {
|
|
|
42719
42564
|
return { data, colorFormat };
|
|
42720
42565
|
}
|
|
42721
42566
|
function encodePro2Wallpaper(options) {
|
|
42722
|
-
if (options.encoding === 'i8-lz4') {
|
|
42723
|
-
return encodePro2I8Lz4(options);
|
|
42724
|
-
}
|
|
42725
42567
|
return encodePro2Image(options);
|
|
42726
42568
|
}
|
|
42727
42569
|
|
|
@@ -53483,7 +53325,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53483
53325
|
}
|
|
53484
53326
|
seenTargetIds.add(targetId);
|
|
53485
53327
|
}
|
|
53486
|
-
const completedTargets = matchingTargets.filter(target =>
|
|
53328
|
+
const completedTargets = matchingTargets.filter(target => {
|
|
53329
|
+
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53330
|
+
return (isProtocolV2TargetStatusFinished(target.status) &&
|
|
53331
|
+
(!liveTargetIds || (targetId !== undefined && liveTargetIds.has(targetId))));
|
|
53332
|
+
});
|
|
53487
53333
|
const completedTargetIds = new Set();
|
|
53488
53334
|
completedTargets.forEach(target => {
|
|
53489
53335
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
@@ -53592,26 +53438,17 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53592
53438
|
}
|
|
53593
53439
|
const currentDeviceInfo = deviceInfo;
|
|
53594
53440
|
try {
|
|
53595
|
-
const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet',
|
|
53441
|
+
const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', {
|
|
53596
53442
|
fields: {
|
|
53597
53443
|
status: true,
|
|
53598
53444
|
payload_version: true,
|
|
53599
53445
|
path: true,
|
|
53600
53446
|
},
|
|
53601
53447
|
}, { timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT });
|
|
53602
|
-
if (
|
|
53603
|
-
if (this.isBleReconnect()) {
|
|
53604
|
-
Log$7.log('[FirmwareUpdateV4] BLE firmware install completed by terminal Success response');
|
|
53605
|
-
this.recordProtocolV2AuthoritativeInstallCompletion(expectedTargetIds);
|
|
53606
|
-
this.postProgressMessage(100, 'installingFirmware');
|
|
53607
|
-
return;
|
|
53608
|
-
}
|
|
53448
|
+
if (this.protocolV2InstallRequestConfirmed) {
|
|
53609
53449
|
installEvidenceObserved = true;
|
|
53610
|
-
lastError = new Error('Protocol V2 firmware install acknowledged; waiting for target status');
|
|
53611
53450
|
}
|
|
53612
|
-
const statusTargets = statusResponse.
|
|
53613
|
-
? ((_a = statusResponse.message.records) !== null && _a !== void 0 ? _a : [])
|
|
53614
|
-
: [];
|
|
53451
|
+
const statusTargets = ((_a = statusResponse.message.records) !== null && _a !== void 0 ? _a : []);
|
|
53615
53452
|
this.collectProtocolV2LiveTargetIds(statusTargets, expectedTargetIds, liveTargetIds);
|
|
53616
53453
|
if (liveTargetIds.size > 0) {
|
|
53617
53454
|
currentInstallStatusObserved = true;
|
|
@@ -53650,9 +53487,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53650
53487
|
}
|
|
53651
53488
|
}
|
|
53652
53489
|
if (statusTargets.length === 0) {
|
|
53653
|
-
|
|
53654
|
-
lastError = new Error('Protocol V2 firmware update is waiting for user confirmation or target status');
|
|
53655
|
-
}
|
|
53490
|
+
lastError = new Error('Protocol V2 firmware update is waiting for user confirmation or target status');
|
|
53656
53491
|
}
|
|
53657
53492
|
else {
|
|
53658
53493
|
const missingTargetIds = this.getProtocolV2MissingTargetIds(statusTargets, expectedTargetIds);
|
|
@@ -53947,7 +53782,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53947
53782
|
});
|
|
53948
53783
|
}
|
|
53949
53784
|
acquireProtocolV2BleDevice(skipProtocolProbe = false) {
|
|
53950
|
-
var _a;
|
|
53951
53785
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53952
53786
|
const connector = this.device.deviceConnector;
|
|
53953
53787
|
const expectedId = this.device.originalDescriptor.id;
|
|
@@ -53955,14 +53789,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53955
53789
|
yield (connector === null || connector === void 0 ? void 0 : connector.acquire(expectedId, null, true, PROTOCOL_V2_CONNECT_PROTOCOL));
|
|
53956
53790
|
return;
|
|
53957
53791
|
}
|
|
53958
|
-
|
|
53959
|
-
const reconnectDescriptor = (_a = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) === null || _a === void 0 ? void 0 : _a.find(descriptor => descriptor.id === expectedId);
|
|
53960
|
-
if (!reconnectDescriptor) {
|
|
53961
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
|
|
53962
|
-
}
|
|
53963
|
-
yield (connector === null || connector === void 0 ? void 0 : connector.acquire(reconnectDescriptor.id, null, true, PROTOCOL_V2_CONNECT_PROTOCOL, undefined, undefined, skipProtocolProbe));
|
|
53792
|
+
yield (connector === null || connector === void 0 ? void 0 : connector.acquire(expectedId, null, true, PROTOCOL_V2_CONNECT_PROTOCOL, undefined, undefined, skipProtocolProbe));
|
|
53964
53793
|
this.device.commands.disposed = false;
|
|
53965
|
-
this.device.getCommands().mainId =
|
|
53794
|
+
this.device.getCommands().mainId = expectedId;
|
|
53966
53795
|
});
|
|
53967
53796
|
}
|
|
53968
53797
|
protocolV2StartFirmwareUpdate({ targets, }) {
|
|
@@ -53977,7 +53806,18 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53977
53806
|
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 } : {}))));
|
|
53978
53807
|
if (this.isBleReconnect()) {
|
|
53979
53808
|
try {
|
|
53980
|
-
yield commands.call('DeviceFirmwareUpdateRequest', {}, {
|
|
53809
|
+
yield commands.call('DeviceFirmwareUpdateRequest', {}, {
|
|
53810
|
+
returnAfterWrite: true,
|
|
53811
|
+
expectedTypes: ['Success'],
|
|
53812
|
+
onResponseAfterWrite: response => {
|
|
53813
|
+
if (response.type !== 'Success')
|
|
53814
|
+
return;
|
|
53815
|
+
this.protocolV2InstallRequestConfirmed = true;
|
|
53816
|
+
this.device.clearCancelableAction();
|
|
53817
|
+
this.postProgressMessage(1, 'installingFirmware');
|
|
53818
|
+
Log$7.log('[FirmwareUpdateV4] BLE firmware install confirmed by device response');
|
|
53819
|
+
},
|
|
53820
|
+
});
|
|
53981
53821
|
Log$7.log('[FirmwareUpdateV4] BLE firmware install request written; continue with status polling');
|
|
53982
53822
|
}
|
|
53983
53823
|
catch (error) {
|
|
@@ -54493,15 +54333,10 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54493
54333
|
return ['V2'];
|
|
54494
54334
|
}
|
|
54495
54335
|
init() {
|
|
54496
|
-
const { jpegBase64, fileName, chunkSize
|
|
54336
|
+
const { jpegBase64, fileName, chunkSize } = this.payload;
|
|
54497
54337
|
if (chunkSize !== undefined && (!Number.isInteger(chunkSize) || chunkSize <= 0)) {
|
|
54498
54338
|
throw invalidParameter$1('Parameter [chunkSize] must be a positive integer.');
|
|
54499
54339
|
}
|
|
54500
|
-
if (encoding !== undefined && encoding !== 'rgb565' && encoding !== 'i8-lz4') {
|
|
54501
|
-
throw invalidParameter$1('Parameter [encoding] must be either rgb565 or i8-lz4.');
|
|
54502
|
-
}
|
|
54503
|
-
const env = DataManager.getSettings('env');
|
|
54504
|
-
const resolvedEncoding = encoding !== null && encoding !== void 0 ? encoding : (env && DataManager.isBleConnect(env) ? 'i8-lz4' : 'rgb565');
|
|
54505
54340
|
const decoded = decodeJpegBase64ToRgba({
|
|
54506
54341
|
jpegBase64,
|
|
54507
54342
|
parameterName: 'jpegBase64',
|
|
@@ -54512,10 +54347,9 @@ class DeviceUploadWallpaper extends BaseMethod {
|
|
|
54512
54347
|
width: PRO2_WALLPAPER_WIDTH,
|
|
54513
54348
|
height: PRO2_WALLPAPER_HEIGHT,
|
|
54514
54349
|
rgba: decoded.data,
|
|
54515
|
-
encoding: resolvedEncoding,
|
|
54516
54350
|
});
|
|
54517
54351
|
this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
|
|
54518
|
-
this.params = { jpegBase64, fileName, chunkSize
|
|
54352
|
+
this.params = { jpegBase64, fileName, chunkSize };
|
|
54519
54353
|
this.unlockPolicy = 'unlock-before-run';
|
|
54520
54354
|
this.protocolV2PreUnlockPinType = hdTransport.DeviceSessionPinType.Any;
|
|
54521
54355
|
this.skipForceUpdateCheck = true;
|
|
@@ -65357,6 +65191,8 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
|
|
|
65357
65191
|
if ((_g = method.payload) === null || _g === void 0 ? void 0 : _g.onlyConnectBleDevice) {
|
|
65358
65192
|
preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
|
|
65359
65193
|
Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
|
|
65194
|
+
completeMethodRequestContext(method);
|
|
65195
|
+
requestQueue.releaseTask(method.responseID);
|
|
65360
65196
|
return createResponseMessage(method.responseID, true, null);
|
|
65361
65197
|
}
|
|
65362
65198
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
@@ -65732,7 +65568,31 @@ function isMissingDetectedProtocolV2Error(method, error) {
|
|
|
65732
65568
|
typeof typedError.message === 'string' &&
|
|
65733
65569
|
typedError.message.includes('Device protocol has not been detected'));
|
|
65734
65570
|
}
|
|
65735
|
-
|
|
65571
|
+
const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
|
|
65572
|
+
function raceBleAcquire(acquirePromise, abortSignal) {
|
|
65573
|
+
return new Promise((resolve, reject) => {
|
|
65574
|
+
let settled = false;
|
|
65575
|
+
const settle = (fn) => {
|
|
65576
|
+
if (settled)
|
|
65577
|
+
return;
|
|
65578
|
+
settled = true;
|
|
65579
|
+
clearTimeout(deadline);
|
|
65580
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', onAbort);
|
|
65581
|
+
fn();
|
|
65582
|
+
};
|
|
65583
|
+
const onAbort = () => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled)));
|
|
65584
|
+
const deadline = setTimeout(() => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`))), BLE_ACQUIRE_DEADLINE_MS);
|
|
65585
|
+
acquirePromise.then(value => settle(() => resolve(value)), error => settle(() => reject(error)));
|
|
65586
|
+
if (abortSignal) {
|
|
65587
|
+
if (abortSignal.aborted) {
|
|
65588
|
+
onAbort();
|
|
65589
|
+
return;
|
|
65590
|
+
}
|
|
65591
|
+
abortSignal.addEventListener('abort', onAbort);
|
|
65592
|
+
}
|
|
65593
|
+
});
|
|
65594
|
+
}
|
|
65595
|
+
function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
|
|
65736
65596
|
var _a;
|
|
65737
65597
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65738
65598
|
try {
|
|
@@ -65747,9 +65607,31 @@ function connectDeviceForBle(method, device, retryCount = 0) {
|
|
|
65747
65607
|
!device.commands ||
|
|
65748
65608
|
device.commands.disposed;
|
|
65749
65609
|
if (shouldAcquire) {
|
|
65750
|
-
|
|
65751
|
-
|
|
65752
|
-
|
|
65610
|
+
const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
|
|
65611
|
+
if (useAcquireGuards && (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
65612
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
|
|
65613
|
+
}
|
|
65614
|
+
if (!useAcquireGuards) {
|
|
65615
|
+
yield device.acquire(method.payload.connectProtocol, {
|
|
65616
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
65617
|
+
});
|
|
65618
|
+
}
|
|
65619
|
+
else {
|
|
65620
|
+
try {
|
|
65621
|
+
yield raceBleAcquire(device.acquire(method.payload.connectProtocol, {
|
|
65622
|
+
forceProtocolDetection: method.payload.forceProtocolDetection,
|
|
65623
|
+
}), abortSignal);
|
|
65624
|
+
}
|
|
65625
|
+
catch (err) {
|
|
65626
|
+
if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError &&
|
|
65627
|
+
device.mainId &&
|
|
65628
|
+
device.deviceConnector) {
|
|
65629
|
+
yield device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
|
|
65630
|
+
device.markTransportDisconnected();
|
|
65631
|
+
}
|
|
65632
|
+
throw err;
|
|
65633
|
+
}
|
|
65634
|
+
}
|
|
65753
65635
|
}
|
|
65754
65636
|
if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
|
|
65755
65637
|
if (shouldAcquire) {
|
|
@@ -65780,7 +65662,7 @@ function connectDeviceForBle(method, device, retryCount = 0) {
|
|
|
65780
65662
|
const nextRetry = retryCount + 1;
|
|
65781
65663
|
Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
|
|
65782
65664
|
yield wait(3000);
|
|
65783
|
-
yield connectDeviceForBle(method, device, nextRetry);
|
|
65665
|
+
yield connectDeviceForBle(method, device, abortSignal, nextRetry);
|
|
65784
65666
|
}
|
|
65785
65667
|
else {
|
|
65786
65668
|
throw err;
|
|
@@ -65865,7 +65747,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
|
|
|
65865
65747
|
if (tryCount === 1) {
|
|
65866
65748
|
device.beginConnectionAttempt();
|
|
65867
65749
|
}
|
|
65868
|
-
yield connectDeviceForBle(method, device);
|
|
65750
|
+
yield connectDeviceForBle(method, device, abortSignal);
|
|
65869
65751
|
}
|
|
65870
65752
|
resolve(device);
|
|
65871
65753
|
return;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export declare const PRO2_WALLPAPER_WIDTH = 604;
|
|
2
2
|
export declare const PRO2_WALLPAPER_HEIGHT = 1024;
|
|
3
|
-
export type Pro2WallpaperColorFormat = 'RGB565' | 'RGB565A8'
|
|
4
|
-
export type Pro2WallpaperEncoding = 'rgb565' | 'i8-lz4';
|
|
3
|
+
export type Pro2WallpaperColorFormat = 'RGB565' | 'RGB565A8';
|
|
5
4
|
export type Pro2ImageAlphaMode = 'preserve' | 'black-background';
|
|
6
5
|
export declare function encodePro2Image(options: {
|
|
7
6
|
width: number;
|
|
@@ -16,7 +15,6 @@ export declare function encodePro2Wallpaper(options: {
|
|
|
16
15
|
width: number;
|
|
17
16
|
height: number;
|
|
18
17
|
rgba: Uint8Array | ArrayBuffer;
|
|
19
|
-
encoding?: Pro2WallpaperEncoding;
|
|
20
18
|
}): {
|
|
21
19
|
data: Uint8Array;
|
|
22
20
|
colorFormat: Pro2WallpaperColorFormat;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pro2Wallpaper.d.ts","sourceRoot":"","sources":["../../src/utils/pro2Wallpaper.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"pro2Wallpaper.d.ts","sourceRoot":"","sources":["../../src/utils/pro2Wallpaper.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE7D,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,kBAAkB,CAAC;AA8BjE,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;IAC/B,SAAS,CAAC,EAAE,kBAAkB,CAAC;CAChC,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,wBAAwB,CAAA;CAAE,CA4E9D;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;CAChC,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,wBAAwB,CAAA;CAAE,CAE9D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.173",
|
|
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.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.173",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.173",
|
|
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": "b2fa03ff17b01696a15318c2e27c923d9ba3deb0"
|
|
50
50
|
}
|
|
@@ -2316,9 +2316,13 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2316
2316
|
}
|
|
2317
2317
|
seenTargetIds.add(targetId);
|
|
2318
2318
|
}
|
|
2319
|
-
const completedTargets = matchingTargets.filter(target =>
|
|
2320
|
-
|
|
2321
|
-
|
|
2319
|
+
const completedTargets = matchingTargets.filter(target => {
|
|
2320
|
+
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
2321
|
+
return (
|
|
2322
|
+
isProtocolV2TargetStatusFinished(target.status) &&
|
|
2323
|
+
(!liveTargetIds || (targetId !== undefined && liveTargetIds.has(targetId)))
|
|
2324
|
+
);
|
|
2325
|
+
});
|
|
2322
2326
|
const completedTargetIds = new Set<number>();
|
|
2323
2327
|
completedTargets.forEach(target => {
|
|
2324
2328
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
@@ -2465,7 +2469,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2465
2469
|
try {
|
|
2466
2470
|
const statusResponse = await this.device.getCommands().typedCall(
|
|
2467
2471
|
'DeviceFirmwareUpdateStatusGet',
|
|
2468
|
-
|
|
2472
|
+
'DeviceFirmwareUpdateStatus',
|
|
2469
2473
|
{
|
|
2470
2474
|
fields: {
|
|
2471
2475
|
status: true,
|
|
@@ -2475,24 +2479,11 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2475
2479
|
},
|
|
2476
2480
|
{ timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT }
|
|
2477
2481
|
);
|
|
2478
|
-
if (
|
|
2479
|
-
if (this.isBleReconnect()) {
|
|
2480
|
-
Log.log(
|
|
2481
|
-
'[FirmwareUpdateV4] BLE firmware install completed by terminal Success response'
|
|
2482
|
-
);
|
|
2483
|
-
this.recordProtocolV2AuthoritativeInstallCompletion(expectedTargetIds);
|
|
2484
|
-
this.postProgressMessage(100, 'installingFirmware');
|
|
2485
|
-
return;
|
|
2486
|
-
}
|
|
2482
|
+
if (this.protocolV2InstallRequestConfirmed) {
|
|
2487
2483
|
installEvidenceObserved = true;
|
|
2488
|
-
lastError = new Error(
|
|
2489
|
-
'Protocol V2 firmware install acknowledged; waiting for target status'
|
|
2490
|
-
);
|
|
2491
2484
|
}
|
|
2492
|
-
const statusTargets =
|
|
2493
|
-
|
|
2494
|
-
? ((statusResponse.message.records ?? []) as ProtocolV2FirmwareUpdateStatusTarget[])
|
|
2495
|
-
: [];
|
|
2485
|
+
const statusTargets = (statusResponse.message.records ??
|
|
2486
|
+
[]) as ProtocolV2FirmwareUpdateStatusTarget[];
|
|
2496
2487
|
this.collectProtocolV2LiveTargetIds(statusTargets, expectedTargetIds, liveTargetIds);
|
|
2497
2488
|
if (liveTargetIds.size > 0) {
|
|
2498
2489
|
currentInstallStatusObserved = true;
|
|
@@ -2552,11 +2543,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2552
2543
|
}
|
|
2553
2544
|
|
|
2554
2545
|
if (statusTargets.length === 0) {
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
);
|
|
2559
|
-
}
|
|
2546
|
+
lastError = new Error(
|
|
2547
|
+
'Protocol V2 firmware update is waiting for user confirmation or target status'
|
|
2548
|
+
);
|
|
2560
2549
|
} else {
|
|
2561
2550
|
const missingTargetIds = this.getProtocolV2MissingTargetIds(
|
|
2562
2551
|
statusTargets,
|
|
@@ -2952,15 +2941,8 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2952
2941
|
await connector?.acquire(expectedId, null, true, PROTOCOL_V2_CONNECT_PROTOCOL);
|
|
2953
2942
|
return;
|
|
2954
2943
|
}
|
|
2955
|
-
const deviceDiff = await connector?.enumerate();
|
|
2956
|
-
const reconnectDescriptor = deviceDiff?.descriptors?.find(
|
|
2957
|
-
descriptor => descriptor.id === expectedId
|
|
2958
|
-
);
|
|
2959
|
-
if (!reconnectDescriptor) {
|
|
2960
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceNotFound);
|
|
2961
|
-
}
|
|
2962
2944
|
await connector?.acquire(
|
|
2963
|
-
|
|
2945
|
+
expectedId,
|
|
2964
2946
|
null,
|
|
2965
2947
|
true,
|
|
2966
2948
|
PROTOCOL_V2_CONNECT_PROTOCOL,
|
|
@@ -2969,7 +2951,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2969
2951
|
skipProtocolProbe
|
|
2970
2952
|
);
|
|
2971
2953
|
this.device.commands.disposed = false;
|
|
2972
|
-
this.device.getCommands().mainId =
|
|
2954
|
+
this.device.getCommands().mainId = expectedId;
|
|
2973
2955
|
}
|
|
2974
2956
|
|
|
2975
2957
|
private async protocolV2StartFirmwareUpdate({
|
|
@@ -2998,7 +2980,21 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2998
2980
|
|
|
2999
2981
|
if (this.isBleReconnect()) {
|
|
3000
2982
|
try {
|
|
3001
|
-
await commands.call(
|
|
2983
|
+
await commands.call(
|
|
2984
|
+
'DeviceFirmwareUpdateRequest',
|
|
2985
|
+
{},
|
|
2986
|
+
{
|
|
2987
|
+
returnAfterWrite: true,
|
|
2988
|
+
expectedTypes: ['Success'],
|
|
2989
|
+
onResponseAfterWrite: response => {
|
|
2990
|
+
if (response.type !== 'Success') return;
|
|
2991
|
+
this.protocolV2InstallRequestConfirmed = true;
|
|
2992
|
+
this.device.clearCancelableAction();
|
|
2993
|
+
this.postProgressMessage(1, 'installingFirmware');
|
|
2994
|
+
Log.log('[FirmwareUpdateV4] BLE firmware install confirmed by device response');
|
|
2995
|
+
},
|
|
2996
|
+
}
|
|
2997
|
+
);
|
|
3002
2998
|
Log.log(
|
|
3003
2999
|
'[FirmwareUpdateV4] BLE firmware install request written; continue with status polling'
|
|
3004
3000
|
);
|
|
@@ -7,7 +7,6 @@ import { BaseMethod } from '../BaseMethod';
|
|
|
7
7
|
import { decodeJpegBase64ToRgba } from '../helpers/base64Data';
|
|
8
8
|
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
9
9
|
import { writeProtocolV2File } from '../helpers/protocolV2FileWrite';
|
|
10
|
-
import { DataManager } from '../../data-manager';
|
|
11
10
|
import { UI_REQUEST, createUiMessage } from '../../events/ui-request';
|
|
12
11
|
import { supportsProtocolV2Message } from '../../protocols/protocol-v2/features';
|
|
13
12
|
import { LoggerNames, getLogger } from '../../utils';
|
|
@@ -15,7 +14,6 @@ import {
|
|
|
15
14
|
PRO2_WALLPAPER_HEIGHT,
|
|
16
15
|
PRO2_WALLPAPER_WIDTH,
|
|
17
16
|
type Pro2WallpaperColorFormat,
|
|
18
|
-
type Pro2WallpaperEncoding,
|
|
19
17
|
encodePro2Wallpaper,
|
|
20
18
|
} from '../../utils/pro2Wallpaper';
|
|
21
19
|
|
|
@@ -23,7 +21,6 @@ export type DeviceUploadWallpaperParams = {
|
|
|
23
21
|
jpegBase64: string;
|
|
24
22
|
fileName?: string;
|
|
25
23
|
chunkSize?: number;
|
|
26
|
-
encoding?: Pro2WallpaperEncoding;
|
|
27
24
|
};
|
|
28
25
|
|
|
29
26
|
export type DeviceUploadWallpaperResponse = {
|
|
@@ -64,16 +61,10 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
|
|
|
64
61
|
private path = '';
|
|
65
62
|
|
|
66
63
|
init() {
|
|
67
|
-
const { jpegBase64, fileName, chunkSize
|
|
64
|
+
const { jpegBase64, fileName, chunkSize } = this.payload;
|
|
68
65
|
if (chunkSize !== undefined && (!Number.isInteger(chunkSize) || chunkSize <= 0)) {
|
|
69
66
|
throw invalidParameter('Parameter [chunkSize] must be a positive integer.');
|
|
70
67
|
}
|
|
71
|
-
if (encoding !== undefined && encoding !== 'rgb565' && encoding !== 'i8-lz4') {
|
|
72
|
-
throw invalidParameter('Parameter [encoding] must be either rgb565 or i8-lz4.');
|
|
73
|
-
}
|
|
74
|
-
const env = DataManager.getSettings('env');
|
|
75
|
-
const resolvedEncoding: Pro2WallpaperEncoding =
|
|
76
|
-
encoding ?? (env && DataManager.isBleConnect(env) ? 'i8-lz4' : 'rgb565');
|
|
77
68
|
|
|
78
69
|
const decoded = decodeJpegBase64ToRgba({
|
|
79
70
|
jpegBase64,
|
|
@@ -85,10 +76,9 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
|
|
|
85
76
|
width: PRO2_WALLPAPER_WIDTH,
|
|
86
77
|
height: PRO2_WALLPAPER_HEIGHT,
|
|
87
78
|
rgba: decoded.data,
|
|
88
|
-
encoding: resolvedEncoding,
|
|
89
79
|
});
|
|
90
80
|
this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
|
|
91
|
-
this.params = { jpegBase64, fileName, chunkSize
|
|
81
|
+
this.params = { jpegBase64, fileName, chunkSize };
|
|
92
82
|
this.unlockPolicy = 'unlock-before-run';
|
|
93
83
|
// File writes and wallpaper apply require an unlocked device. Either PIN
|
|
94
84
|
// may authorize this device-management action.
|