@onekeyfe/hd-core 1.2.0-alpha.167 → 1.2.0-alpha.169

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.js CHANGED
@@ -42471,6 +42471,18 @@ const PRO2_WALLPAPER_WIDTH = 604;
42471
42471
  const PRO2_WALLPAPER_HEIGHT = 1024;
42472
42472
  const COLOR_FORMAT_RGB565 = 0x12;
42473
42473
  const COLOR_FORMAT_RGB565A8 = 0x14;
42474
+ const COLOR_FORMAT_I8 = 0x0a;
42475
+ const IMAGE_FLAG_COMPRESSED = 0x0008;
42476
+ const IMAGE_COMPRESSION_LZ4 = 0x00000002;
42477
+ const I8_PALETTE_SIZE = 256 * 4;
42478
+ const I8_RED_LEVELS = 6;
42479
+ const I8_GREEN_LEVELS = 7;
42480
+ const I8_BLUE_LEVELS = 6;
42481
+ const LZ4_MIN_MATCH = 4;
42482
+ const LZ4_LAST_LITERALS = 5;
42483
+ const LZ4_MATCH_FIND_LIMIT = 12;
42484
+ const LZ4_HASH_BITS = 16;
42485
+ const LZ4_HASH_MULTIPLIER = -1640531535;
42474
42486
  const RED_THRESHOLD = [
42475
42487
  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,
42476
42488
  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,
@@ -42492,6 +42504,149 @@ function asBytes(rgba) {
42492
42504
  function align(value, boundary) {
42493
42505
  return Math.ceil(value / boundary) * boundary;
42494
42506
  }
42507
+ function writeLz4Length(output, offset, length) {
42508
+ let cursor = offset;
42509
+ let remaining = length;
42510
+ while (remaining >= 0xff) {
42511
+ output[cursor] = 0xff;
42512
+ cursor += 1;
42513
+ remaining -= 0xff;
42514
+ }
42515
+ output[cursor] = remaining;
42516
+ return cursor + 1;
42517
+ }
42518
+ function readUint32LittleEndian(data, offset) {
42519
+ return (data[offset] | (data[offset + 1] << 8) | (data[offset + 2] << 16) | (data[offset + 3] << 24));
42520
+ }
42521
+ function getLz4Hash(sequence) {
42522
+ return (Math.imul(sequence, LZ4_HASH_MULTIPLIER) >>> (32 - LZ4_HASH_BITS)) & 0xffff;
42523
+ }
42524
+ function compressLz4Block(input) {
42525
+ const output = new Uint8Array(input.byteLength + Math.floor(input.byteLength / 0xff) + 16);
42526
+ const hashTable = new Int32Array(1 << LZ4_HASH_BITS);
42527
+ hashTable.fill(-1);
42528
+ let anchor = 0;
42529
+ let inputOffset = 0;
42530
+ let outputOffset = 0;
42531
+ const matchFindEnd = input.byteLength - LZ4_MATCH_FIND_LIMIT;
42532
+ const matchCopyEnd = input.byteLength - LZ4_LAST_LITERALS;
42533
+ while (inputOffset <= matchFindEnd) {
42534
+ const sequence = readUint32LittleEndian(input, inputOffset);
42535
+ const hash = getLz4Hash(sequence);
42536
+ const reference = hashTable[hash];
42537
+ hashTable[hash] = inputOffset;
42538
+ const matchOffset = inputOffset - reference;
42539
+ const hasMatch = reference >= 0 &&
42540
+ matchOffset <= 0xffff &&
42541
+ readUint32LittleEndian(input, reference) === sequence;
42542
+ if (hasMatch) {
42543
+ let matchLength = LZ4_MIN_MATCH;
42544
+ while (inputOffset + matchLength < matchCopyEnd &&
42545
+ input[reference + matchLength] === input[inputOffset + matchLength]) {
42546
+ matchLength += 1;
42547
+ }
42548
+ const literalLength = inputOffset - anchor;
42549
+ const encodedMatchLength = matchLength - LZ4_MIN_MATCH;
42550
+ const tokenOffset = outputOffset;
42551
+ outputOffset += 1;
42552
+ output[tokenOffset] =
42553
+ (Math.min(literalLength, 0x0f) << 4) | Math.min(encodedMatchLength, 0x0f);
42554
+ if (literalLength >= 0x0f) {
42555
+ outputOffset = writeLz4Length(output, outputOffset, literalLength - 0x0f);
42556
+ }
42557
+ output.set(input.subarray(anchor, inputOffset), outputOffset);
42558
+ outputOffset += literalLength;
42559
+ output[outputOffset] = matchOffset & 0xff;
42560
+ output[outputOffset + 1] = matchOffset >> 8;
42561
+ outputOffset += 2;
42562
+ if (encodedMatchLength >= 0x0f) {
42563
+ outputOffset = writeLz4Length(output, outputOffset, encodedMatchLength - 0x0f);
42564
+ }
42565
+ const matchStart = inputOffset;
42566
+ inputOffset += matchLength;
42567
+ anchor = inputOffset;
42568
+ for (let cursor = Math.max(matchStart + 1, inputOffset - 2); cursor < inputOffset; cursor += 1) {
42569
+ if (cursor <= matchFindEnd) {
42570
+ hashTable[getLz4Hash(readUint32LittleEndian(input, cursor))] = cursor;
42571
+ }
42572
+ }
42573
+ }
42574
+ else {
42575
+ inputOffset += 1;
42576
+ }
42577
+ }
42578
+ const literalLength = input.byteLength - anchor;
42579
+ const tokenOffset = outputOffset;
42580
+ outputOffset += 1;
42581
+ output[tokenOffset] = Math.min(literalLength, 0x0f) << 4;
42582
+ if (literalLength >= 0x0f) {
42583
+ outputOffset = writeLz4Length(output, outputOffset, literalLength - 0x0f);
42584
+ }
42585
+ output.set(input.subarray(anchor), outputOffset);
42586
+ outputOffset += literalLength;
42587
+ return output.slice(0, outputOffset);
42588
+ }
42589
+ function quantizeChannel(value, levels) {
42590
+ return Math.floor((value * (levels - 1) + 0x7f) / 0xff);
42591
+ }
42592
+ function expandChannel(value, levels) {
42593
+ return Math.floor((value * 0xff + Math.floor((levels - 1) / 2)) / (levels - 1));
42594
+ }
42595
+ function encodePro2I8Lz4(options) {
42596
+ const { width, height } = options;
42597
+ if (!Number.isInteger(width) || width <= 0 || width > 0xffff) {
42598
+ throw invalidParameter$2('Wallpaper width must be an integer between 1 and 65535.');
42599
+ }
42600
+ if (!Number.isInteger(height) || height <= 0 || height > 0xffff) {
42601
+ throw invalidParameter$2('Wallpaper height must be an integer between 1 and 65535.');
42602
+ }
42603
+ const rgba = asBytes(options.rgba);
42604
+ const expectedLength = width * height * 4;
42605
+ if (rgba.byteLength !== expectedLength) {
42606
+ throw invalidParameter$2(`Wallpaper RGBA data length must be ${expectedLength} bytes, received ${rgba.byteLength}.`);
42607
+ }
42608
+ const stride = width;
42609
+ const rawData = new Uint8Array(I8_PALETTE_SIZE + stride * height);
42610
+ for (let red = 0; red < I8_RED_LEVELS; red += 1) {
42611
+ for (let green = 0; green < I8_GREEN_LEVELS; green += 1) {
42612
+ for (let blue = 0; blue < I8_BLUE_LEVELS; blue += 1) {
42613
+ const paletteIndex = (red * I8_GREEN_LEVELS + green) * I8_BLUE_LEVELS + blue;
42614
+ const paletteOffset = paletteIndex * 4;
42615
+ rawData[paletteOffset] = expandChannel(blue, I8_BLUE_LEVELS);
42616
+ rawData[paletteOffset + 1] = expandChannel(green, I8_GREEN_LEVELS);
42617
+ rawData[paletteOffset + 2] = expandChannel(red, I8_RED_LEVELS);
42618
+ rawData[paletteOffset + 3] = 0xff;
42619
+ }
42620
+ }
42621
+ }
42622
+ for (let pixel = 0; pixel < width * height; pixel += 1) {
42623
+ const sourceOffset = pixel * 4;
42624
+ const alpha = rgba[sourceOffset + 3];
42625
+ const red = Math.round((rgba[sourceOffset] * alpha) / 0xff);
42626
+ const green = Math.round((rgba[sourceOffset + 1] * alpha) / 0xff);
42627
+ const blue = Math.round((rgba[sourceOffset + 2] * alpha) / 0xff);
42628
+ const paletteIndex = (quantizeChannel(red, I8_RED_LEVELS) * I8_GREEN_LEVELS +
42629
+ quantizeChannel(green, I8_GREEN_LEVELS)) *
42630
+ I8_BLUE_LEVELS +
42631
+ quantizeChannel(blue, I8_BLUE_LEVELS);
42632
+ rawData[I8_PALETTE_SIZE + pixel] = paletteIndex;
42633
+ }
42634
+ const compressed = compressLz4Block(rawData);
42635
+ const data = new Uint8Array(24 + compressed.byteLength);
42636
+ const view = new DataView(data.buffer);
42637
+ data[0] = 0x19;
42638
+ data[1] = COLOR_FORMAT_I8;
42639
+ view.setUint16(2, IMAGE_FLAG_COMPRESSED, true);
42640
+ view.setUint16(4, width, true);
42641
+ view.setUint16(6, height, true);
42642
+ view.setUint16(8, stride, true);
42643
+ view.setUint16(10, 0, true);
42644
+ view.setUint32(12, IMAGE_COMPRESSION_LZ4, true);
42645
+ view.setUint32(16, compressed.byteLength, true);
42646
+ view.setUint32(20, rawData.byteLength, true);
42647
+ data.set(compressed, 24);
42648
+ return { data, colorFormat: 'I8' };
42649
+ }
42495
42650
  function encodePro2Image(options) {
42496
42651
  var _a;
42497
42652
  const { width, height } = options;
@@ -42559,6 +42714,9 @@ function encodePro2Image(options) {
42559
42714
  return { data, colorFormat };
42560
42715
  }
42561
42716
  function encodePro2Wallpaper(options) {
42717
+ if (options.encoding === 'i8-lz4') {
42718
+ return encodePro2I8Lz4(options);
42719
+ }
42562
42720
  return encodePro2Image(options);
42563
42721
  }
42564
42722
 
@@ -51875,6 +52033,15 @@ const isProtocolV2TerminalInstallStatusError = (error) => {
51875
52033
  const isProtocolV2TargetStatusFinished = (status) => normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_FINISHED;
51876
52034
  const isProtocolV2TargetStatusInProgress = (status) => normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_PENDING ||
51877
52035
  normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS;
52036
+ const getProtocolV2FirmwareStatusFingerprint = (statusTargets) => JSON.stringify(statusTargets.map(target => {
52037
+ var _a, _b, _c, _d, _e;
52038
+ return ({
52039
+ targetId: (_a = normalizeProtocolV2TargetId(target.target_id)) !== null && _a !== void 0 ? _a : target.target_id,
52040
+ status: (_c = (_b = normalizeProtocolV2TargetStatus(target.status)) !== null && _b !== void 0 ? _b : target.status) !== null && _c !== void 0 ? _c : null,
52041
+ payloadVersion: (_d = target.payload_version) !== null && _d !== void 0 ? _d : null,
52042
+ path: (_e = target.path) !== null && _e !== void 0 ? _e : null,
52043
+ });
52044
+ }));
51878
52045
  const isProtocolV2TargetStatusFailed = (status) => {
51879
52046
  const normalizedStatus = normalizeProtocolV2TargetStatus(status);
51880
52047
  return (typeof normalizedStatus === 'number' && normalizedStatus >= PROTOCOL_V2_TARGET_STATUS_FAILED_MIN);
@@ -51977,6 +52144,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
51977
52144
  this.protocolV2CompletedTargetVersions = new Map();
51978
52145
  this.protocolV2CompletedTargetIds = new Set();
51979
52146
  this.protocolV2InstallBaselineVersions = new Map();
52147
+ this.protocolV2InstallNeedsBleReconnect = false;
51980
52148
  this.protocolV2LastTransferProgressAt = 0;
51981
52149
  }
51982
52150
  getSupportedProtocols() {
@@ -53371,18 +53539,29 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53371
53539
  return __awaiter(this, void 0, void 0, function* () {
53372
53540
  const expectedTargetIds = new Set(targets.map(target => target.target_id));
53373
53541
  const expectedPaths = new Map(targets.map(target => [target.target_id, target.path]));
53374
- const startTime = Date.now();
53542
+ const confirmationStartedAt = Date.now();
53543
+ let installStartedAt = requireCurrentInstallStatus ? undefined : confirmationStartedAt;
53544
+ const effectiveBaselineStatusTargets = this.protocolV2InstallStatusBaseline;
53545
+ const baselineStatusFingerprint = effectiveBaselineStatusTargets
53546
+ ? getProtocolV2FirmwareStatusFingerprint(effectiveBaselineStatusTargets)
53547
+ : undefined;
53375
53548
  let lastError;
53376
- let shouldReconnect = false;
53549
+ let shouldReconnect = this.protocolV2InstallNeedsBleReconnect;
53550
+ this.protocolV2InstallNeedsBleReconnect = false;
53377
53551
  let deviceInfo;
53552
+ let bleInstallLinkReady = false;
53378
53553
  let installEvidenceObserved = false;
53379
53554
  let currentInstallStatusObserved = false;
53380
- while (Date.now() - startTime < PROTOCOL_V2_INSTALL_TIMEOUT) {
53555
+ while (Date.now() - (installStartedAt !== null && installStartedAt !== void 0 ? installStartedAt : confirmationStartedAt) < PROTOCOL_V2_INSTALL_TIMEOUT) {
53381
53556
  this.throwIfAborted();
53382
53557
  try {
53383
53558
  if (shouldReconnect) {
53384
- yield this.reconnectProtocolV2Device();
53385
- deviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
53559
+ const isBleInstallReconnect = this.isBleReconnect();
53560
+ yield this.reconnectProtocolV2Device({ skipBleProtocolProbe: isBleInstallReconnect });
53561
+ bleInstallLinkReady = isBleInstallReconnect;
53562
+ deviceInfo = isBleInstallReconnect
53563
+ ? undefined
53564
+ : yield this.verifyProtocolV2ReconnectIdentity();
53386
53565
  shouldReconnect = false;
53387
53566
  }
53388
53567
  const currentDeviceInfo = deviceInfo;
@@ -53401,14 +53580,27 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53401
53580
  const statusTargets = statusResponse.type === 'DeviceFirmwareUpdateStatus'
53402
53581
  ? ((_a = statusResponse.message.records) !== null && _a !== void 0 ? _a : [])
53403
53582
  : [];
53404
- const hasInProgressTarget = statusTargets.some(target => {
53583
+ const hasPendingOrInProgressTarget = statusTargets.some(target => {
53405
53584
  const targetId = normalizeProtocolV2TargetId(target.target_id);
53406
53585
  return (targetId !== undefined &&
53407
53586
  expectedTargetIds.has(targetId) &&
53408
53587
  isProtocolV2TargetStatusInProgress(target.status));
53409
53588
  });
53410
- if (hasInProgressTarget) {
53589
+ const isExpectedStatusSnapshot = statusTargets.length === targets.length &&
53590
+ targets.every((expectedTarget, index) => {
53591
+ const statusTarget = statusTargets[index];
53592
+ return (statusTarget !== undefined &&
53593
+ normalizeProtocolV2TargetId(statusTarget.target_id) === expectedTarget.target_id &&
53594
+ statusTarget.path === expectedTarget.path);
53595
+ });
53596
+ const statusFingerprint = getProtocolV2FirmwareStatusFingerprint(statusTargets);
53597
+ const hasCurrentInstallTransition = baselineStatusFingerprint !== undefined
53598
+ ? isExpectedStatusSnapshot && statusFingerprint !== baselineStatusFingerprint
53599
+ : hasPendingOrInProgressTarget;
53600
+ if (!currentInstallStatusObserved && hasCurrentInstallTransition) {
53411
53601
  currentInstallStatusObserved = true;
53602
+ installStartedAt = Date.now();
53603
+ Log$7.log('[FirmwareUpdateV4] current firmware install records observed');
53412
53604
  }
53413
53605
  const hasMatchingTargetStatus = statusTargets.some(target => {
53414
53606
  const targetId = normalizeProtocolV2TargetId(target.target_id);
@@ -53465,9 +53657,16 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53465
53657
  }
53466
53658
  if (isProtocolV2FirmwareStatusEndpointUnavailable(error)) {
53467
53659
  if (!currentDeviceInfo) {
53660
+ if (!bleInstallLinkReady) {
53661
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device identity is unavailable during install polling');
53662
+ }
53663
+ deviceInfo = yield this.verifyProtocolV2ReconnectIdentity();
53664
+ }
53665
+ const reconnectDeviceInfo = currentDeviceInfo !== null && currentDeviceInfo !== void 0 ? currentDeviceInfo : deviceInfo;
53666
+ if (!reconnectDeviceInfo) {
53468
53667
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device identity is unavailable during install polling');
53469
53668
  }
53470
- const isNormalMode = yield this.probeProtocolV2NormalMode(currentDeviceInfo);
53669
+ const isNormalMode = yield this.probeProtocolV2NormalMode(reconnectDeviceInfo);
53471
53670
  if (isNormalMode &&
53472
53671
  (installEvidenceObserved ||
53473
53672
  this.hasProtocolV2InstallVersionChanged(expectedTargetIds))) {
@@ -53486,6 +53685,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53486
53685
  else {
53487
53686
  shouldReconnect = true;
53488
53687
  deviceInfo = undefined;
53688
+ bleInstallLinkReady = false;
53489
53689
  lastError = error;
53490
53690
  Log$7.log('[FirmwareUpdateV4] DeviceFirmwareUpdateStatusGet unavailable during install: ', error);
53491
53691
  }
@@ -53505,6 +53705,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53505
53705
  }
53506
53706
  shouldReconnect = true;
53507
53707
  deviceInfo = undefined;
53708
+ bleInstallLinkReady = false;
53508
53709
  Log$7.log('Protocol V2 firmware install device readiness probe failed: ', error);
53509
53710
  }
53510
53711
  yield hdShared.wait(1000);
@@ -53612,11 +53813,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53612
53813
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Protocol V2 final features not ready within ${timeout / 1000}s: ${this.normalizeErrorMessage(lastError)}`);
53613
53814
  });
53614
53815
  }
53615
- reconnectProtocolV2Device() {
53816
+ reconnectProtocolV2Device(options) {
53616
53817
  var _a, _b, _c, _d, _e, _f;
53617
53818
  return __awaiter(this, void 0, void 0, function* () {
53618
53819
  if (this.isBleReconnect()) {
53619
- yield this.acquireProtocolV2BleDevice();
53820
+ yield this.acquireProtocolV2BleDevice(options === null || options === void 0 ? void 0 : options.skipBleProtocolProbe);
53620
53821
  return;
53621
53822
  }
53622
53823
  const deviceDiff = yield ((_a = this.device.deviceConnector) === null || _a === void 0 ? void 0 : _a.enumerate());
@@ -53711,21 +53912,65 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53711
53912
  yield hdShared.wait(2000);
53712
53913
  });
53713
53914
  }
53714
- acquireProtocolV2BleDevice() {
53915
+ acquireProtocolV2BleDevice(skipProtocolProbe = false) {
53715
53916
  var _a;
53716
53917
  return __awaiter(this, void 0, void 0, function* () {
53717
- yield ((_a = this.device.deviceConnector) === null || _a === void 0 ? void 0 : _a.acquire(this.device.originalDescriptor.id, null, true, PROTOCOL_V2_CONNECT_PROTOCOL));
53918
+ const connector = this.device.deviceConnector;
53919
+ const expectedId = this.device.originalDescriptor.id;
53920
+ if (!skipProtocolProbe) {
53921
+ yield (connector === null || connector === void 0 ? void 0 : connector.acquire(expectedId, null, true, PROTOCOL_V2_CONNECT_PROTOCOL));
53922
+ return;
53923
+ }
53924
+ const deviceDiff = yield (connector === null || connector === void 0 ? void 0 : connector.enumerate());
53925
+ const reconnectDescriptor = (_a = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) === null || _a === void 0 ? void 0 : _a.find(descriptor => descriptor.id === expectedId);
53926
+ if (!reconnectDescriptor) {
53927
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
53928
+ }
53929
+ yield (connector === null || connector === void 0 ? void 0 : connector.acquire(reconnectDescriptor.id, null, true, PROTOCOL_V2_CONNECT_PROTOCOL, undefined, undefined, skipProtocolProbe));
53930
+ this.device.commands.disposed = false;
53931
+ this.device.getCommands().mainId = reconnectDescriptor.id;
53718
53932
  });
53719
53933
  }
53720
53934
  protocolV2StartFirmwareUpdate({ targets, }) {
53935
+ var _a;
53721
53936
  return __awaiter(this, void 0, void 0, function* () {
53722
53937
  this.protocolV2LastRuntimeProbeFeatures = undefined;
53938
+ this.protocolV2InstallStatusBaseline = undefined;
53939
+ this.protocolV2InstallNeedsBleReconnect = false;
53723
53940
  const commands = this.device.getCommands();
53724
53941
  yield commands.typedCall('DeviceFirmwareUpdateStage', 'Success', { targets });
53942
+ try {
53943
+ const baselineStatusResponse = yield commands.typedCall('DeviceFirmwareUpdateStatusGet', ['DeviceFirmwareUpdateStatus', 'Success'], {
53944
+ fields: {
53945
+ status: true,
53946
+ payload_version: true,
53947
+ path: true,
53948
+ },
53949
+ }, { timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT });
53950
+ this.protocolV2InstallStatusBaseline =
53951
+ baselineStatusResponse.type === 'DeviceFirmwareUpdateStatus'
53952
+ ? ((_a = baselineStatusResponse.message.records) !== null && _a !== void 0 ? _a : [])
53953
+ : [];
53954
+ }
53955
+ catch (error) {
53956
+ Log$7.log('[FirmwareUpdateV4] unable to capture pre-install firmware status: ', error);
53957
+ }
53725
53958
  this.device.setCancelableAction(() => commands.cancelDevice());
53726
53959
  const interaction = this.device.createProtocolV2UiPhaseMetadata('button', 'start');
53727
53960
  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 } : {}))));
53728
- yield commands.call('DeviceFirmwareUpdateRequest', {}, { returnAfterWrite: true });
53961
+ try {
53962
+ yield commands.call('DeviceFirmwareUpdateRequest', {});
53963
+ }
53964
+ catch (error) {
53965
+ this.throwIfAborted();
53966
+ if (!isProtocolV2DeviceDisconnectedError(error)) {
53967
+ throw error;
53968
+ }
53969
+ Log$7.log('[FirmwareUpdateV4] BLE transport released after install request; continue status polling');
53970
+ if (this.isBleReconnect()) {
53971
+ this.protocolV2InstallNeedsBleReconnect = true;
53972
+ }
53973
+ }
53729
53974
  });
53730
53975
  }
53731
53976
  protocolV2Reboot(rebootType) {
@@ -54213,10 +54458,15 @@ class DeviceUploadWallpaper extends BaseMethod {
54213
54458
  return ['V2'];
54214
54459
  }
54215
54460
  init() {
54216
- const { jpegBase64, fileName, chunkSize } = this.payload;
54461
+ const { jpegBase64, fileName, chunkSize, encoding } = this.payload;
54217
54462
  if (chunkSize !== undefined && (!Number.isInteger(chunkSize) || chunkSize <= 0)) {
54218
54463
  throw invalidParameter$1('Parameter [chunkSize] must be a positive integer.');
54219
54464
  }
54465
+ if (encoding !== undefined && encoding !== 'rgb565' && encoding !== 'i8-lz4') {
54466
+ throw invalidParameter$1('Parameter [encoding] must be either rgb565 or i8-lz4.');
54467
+ }
54468
+ const env = DataManager.getSettings('env');
54469
+ const resolvedEncoding = encoding !== null && encoding !== void 0 ? encoding : (env && DataManager.isBleConnect(env) ? 'i8-lz4' : 'rgb565');
54220
54470
  const decoded = decodeJpegBase64ToRgba({
54221
54471
  jpegBase64,
54222
54472
  parameterName: 'jpegBase64',
@@ -54227,9 +54477,10 @@ class DeviceUploadWallpaper extends BaseMethod {
54227
54477
  width: PRO2_WALLPAPER_WIDTH,
54228
54478
  height: PRO2_WALLPAPER_HEIGHT,
54229
54479
  rgba: decoded.data,
54480
+ encoding: resolvedEncoding,
54230
54481
  });
54231
54482
  this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
54232
- this.params = { jpegBase64, fileName, chunkSize };
54483
+ this.params = { jpegBase64, fileName, chunkSize, encoding: resolvedEncoding };
54233
54484
  this.unlockPolicy = 'unlock-before-run';
54234
54485
  this.protocolV2PreUnlockPinType = hdTransport.DeviceSessionPinType.Any;
54235
54486
  this.skipForceUpdateCheck = true;
@@ -64538,7 +64789,7 @@ class DeviceConnector {
64538
64789
  stop() {
64539
64790
  this.listening = false;
64540
64791
  }
64541
- acquire(path, session, forceCleanRunPromise, expectedProtocol, protocolHint, forceProtocolDetection) {
64792
+ acquire(path, session, forceCleanRunPromise, expectedProtocol, protocolHint, forceProtocolDetection, skipProtocolProbe) {
64542
64793
  return __awaiter(this, void 0, void 0, function* () {
64543
64794
  Log$2.debug('acquire', path, session, expectedProtocol, protocolHint);
64544
64795
  const env = DataManager.getSettings('env');
@@ -64546,13 +64797,15 @@ class DeviceConnector {
64546
64797
  const transport = this.getActiveTransport();
64547
64798
  let res;
64548
64799
  if (DataManager.isBleConnect(env)) {
64549
- res = yield transport.acquire({
64800
+ const acquireInput = {
64550
64801
  uuid: path,
64551
64802
  forceCleanRunPromise,
64552
64803
  expectedProtocol,
64553
64804
  protocolHint,
64554
64805
  forceProtocolDetection,
64555
- });
64806
+ skipProtocolProbe,
64807
+ };
64808
+ res = yield transport.acquire(acquireInput);
64556
64809
  }
64557
64810
  else {
64558
64811
  res = yield transport.acquire({
@@ -65068,8 +65321,6 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
65068
65321
  if ((_g = method.payload) === null || _g === void 0 ? void 0 : _g.onlyConnectBleDevice) {
65069
65322
  preWarmCallbackTask === null || preWarmCallbackTask === void 0 ? void 0 : preWarmCallbackTask.resolve();
65070
65323
  Log.debug('Call API - only connect ble device: ', device === null || device === void 0 ? void 0 : device.mainId);
65071
- completeMethodRequestContext(method);
65072
- requestQueue.releaseTask(method.responseID);
65073
65324
  return createResponseMessage(method.responseID, true, null);
65074
65325
  }
65075
65326
  Log.debug('Call API - setDevice: ', device.mainId);
@@ -65445,31 +65696,7 @@ function isMissingDetectedProtocolV2Error(method, error) {
65445
65696
  typeof typedError.message === 'string' &&
65446
65697
  typedError.message.includes('Device protocol has not been detected'));
65447
65698
  }
65448
- const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
65449
- function raceBleAcquire(acquirePromise, abortSignal) {
65450
- return new Promise((resolve, reject) => {
65451
- let settled = false;
65452
- const settle = (fn) => {
65453
- if (settled)
65454
- return;
65455
- settled = true;
65456
- clearTimeout(deadline);
65457
- abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', onAbort);
65458
- fn();
65459
- };
65460
- const onAbort = () => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled)));
65461
- const deadline = setTimeout(() => settle(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, `BLE acquire exceeded ${BLE_ACQUIRE_DEADLINE_MS}ms deadline`))), BLE_ACQUIRE_DEADLINE_MS);
65462
- acquirePromise.then(value => settle(() => resolve(value)), error => settle(() => reject(error)));
65463
- if (abortSignal) {
65464
- if (abortSignal.aborted) {
65465
- onAbort();
65466
- return;
65467
- }
65468
- abortSignal.addEventListener('abort', onAbort);
65469
- }
65470
- });
65471
- }
65472
- function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
65699
+ function connectDeviceForBle(method, device, retryCount = 0) {
65473
65700
  var _a;
65474
65701
  return __awaiter(this, void 0, void 0, function* () {
65475
65702
  try {
@@ -65484,31 +65711,9 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
65484
65711
  !device.commands ||
65485
65712
  device.commands.disposed;
65486
65713
  if (shouldAcquire) {
65487
- const useAcquireGuards = DataManager.getSettings('env') === 'desktop-web-ble';
65488
- if (useAcquireGuards && (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
65489
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
65490
- }
65491
- if (!useAcquireGuards) {
65492
- yield device.acquire(method.payload.connectProtocol, {
65493
- forceProtocolDetection: method.payload.forceProtocolDetection,
65494
- });
65495
- }
65496
- else {
65497
- try {
65498
- yield raceBleAcquire(device.acquire(method.payload.connectProtocol, {
65499
- forceProtocolDetection: method.payload.forceProtocolDetection,
65500
- }), abortSignal);
65501
- }
65502
- catch (err) {
65503
- if (err.errorCode === hdShared.HardwareErrorCode.BleTimeoutError &&
65504
- device.mainId &&
65505
- device.deviceConnector) {
65506
- yield device.deviceConnector.disconnect(device.mainId).catch(() => undefined);
65507
- device.markTransportDisconnected();
65508
- }
65509
- throw err;
65510
- }
65511
- }
65714
+ yield device.acquire(method.payload.connectProtocol, {
65715
+ forceProtocolDetection: method.payload.forceProtocolDetection,
65716
+ });
65512
65717
  }
65513
65718
  if ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.onlyConnectBleDevice) {
65514
65719
  if (shouldAcquire) {
@@ -65539,7 +65744,7 @@ function connectDeviceForBle(method, device, abortSignal, retryCount = 0) {
65539
65744
  const nextRetry = retryCount + 1;
65540
65745
  Log.debug(`Bluetooth connection will retry, retry count: ${nextRetry}`);
65541
65746
  yield wait(3000);
65542
- yield connectDeviceForBle(method, device, abortSignal, nextRetry);
65747
+ yield connectDeviceForBle(method, device, nextRetry);
65543
65748
  }
65544
65749
  else {
65545
65750
  throw err;
@@ -65624,7 +65829,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
65624
65829
  if (tryCount === 1) {
65625
65830
  device.beginConnectionAttempt();
65626
65831
  }
65627
- yield connectDeviceForBle(method, device, abortSignal);
65832
+ yield connectDeviceForBle(method, device);
65628
65833
  }
65629
65834
  resolve(device);
65630
65835
  return;
@@ -1,6 +1,7 @@
1
1
  export declare const PRO2_WALLPAPER_WIDTH = 604;
2
2
  export declare const PRO2_WALLPAPER_HEIGHT = 1024;
3
- export type Pro2WallpaperColorFormat = 'RGB565' | 'RGB565A8';
3
+ export type Pro2WallpaperColorFormat = 'RGB565' | 'RGB565A8' | 'I8';
4
+ export type Pro2WallpaperEncoding = 'rgb565' | 'i8-lz4';
4
5
  export type Pro2ImageAlphaMode = 'preserve' | 'black-background';
5
6
  export declare function encodePro2Image(options: {
6
7
  width: number;
@@ -15,6 +16,7 @@ export declare function encodePro2Wallpaper(options: {
15
16
  width: number;
16
17
  height: number;
17
18
  rgba: Uint8Array | ArrayBuffer;
19
+ encoding?: Pro2WallpaperEncoding;
18
20
  }): {
19
21
  data: Uint8Array;
20
22
  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,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"}
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,GAAG,IAAI,CAAC;AAEpE,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,kBAAkB,CAAC;AA4NjE,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;IAC/B,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAClC,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,wBAAwB,CAAA;CAAE,CAK9D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.167",
3
+ "version": "1.2.0-alpha.169",
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.167",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.167",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.169",
29
+ "@onekeyfe/hd-transport": "1.2.0-alpha.169",
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": "aa450044aaef7519d647a1857a38ac3d4e306475"
49
+ "gitHead": "79c2f32cf0d21d9f1ff3d4d8728b8c83bf48c0e9"
50
50
  }