@onekeyfe/hd-core 1.2.0-alpha.185 → 1.2.0-alpha.186
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 +136 -83
- package/__tests__/protocol-v2.test.ts +23 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/index.js +24 -11
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +24 -16
- package/src/api/protocol-v2/helpers.ts +8 -0
|
@@ -125,7 +125,7 @@ describe('FirmwareUpdateV4 install polling', () => {
|
|
|
125
125
|
expect(setCancelableAction).toHaveBeenCalledTimes(2);
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
-
test('accepts finished USB status after the Request terminal Success arrives', async () => {
|
|
128
|
+
test('accepts path-less finished USB status after the Request terminal Success arrives', async () => {
|
|
129
129
|
const method = new FirmwareUpdateV4({
|
|
130
130
|
id: 1,
|
|
131
131
|
payload: {
|
|
@@ -144,7 +144,6 @@ describe('FirmwareUpdateV4 install polling', () => {
|
|
|
144
144
|
{
|
|
145
145
|
target_id: 4,
|
|
146
146
|
status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
|
|
147
|
-
path: 'vol0:/application_p1.bin',
|
|
148
147
|
},
|
|
149
148
|
],
|
|
150
149
|
},
|
|
@@ -336,87 +335,141 @@ describe('FirmwareUpdateV4 install polling', () => {
|
|
|
336
335
|
expect(method.postProgressMessage).toHaveBeenCalledWith(100, 'installingFirmware');
|
|
337
336
|
});
|
|
338
337
|
|
|
339
|
-
test
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
]
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
(
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
338
|
+
test('accepts stable finished BLE status after an actual install disconnect hides in-progress', async () => {
|
|
339
|
+
const method = new FirmwareUpdateV4({
|
|
340
|
+
id: 1,
|
|
341
|
+
payload: {
|
|
342
|
+
method: 'firmwareUpdateV4',
|
|
343
|
+
connectId: 'pro2-ble',
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
const targets = [{ target_id: 6, path: 'vol0:/coprocessor.bin' }];
|
|
347
|
+
const finishedStatus = {
|
|
348
|
+
type: 'DeviceFirmwareUpdateStatus',
|
|
349
|
+
message: {
|
|
350
|
+
records: [
|
|
351
|
+
{
|
|
352
|
+
target_id: 6,
|
|
353
|
+
status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
|
|
354
|
+
payload_version: 65_556,
|
|
355
|
+
path: 'vol0:/coprocessor.bin',
|
|
356
|
+
},
|
|
357
|
+
],
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
const typedCall = jest
|
|
361
|
+
.fn()
|
|
362
|
+
.mockResolvedValueOnce(finishedStatus)
|
|
363
|
+
.mockImplementationOnce(() => {
|
|
364
|
+
expect(method.postProgressMessage).not.toHaveBeenCalled();
|
|
365
|
+
throw new Error('device was disconnected');
|
|
366
|
+
})
|
|
367
|
+
.mockResolvedValueOnce(finishedStatus)
|
|
368
|
+
.mockImplementationOnce(() => {
|
|
369
|
+
expect(method.postProgressMessage).toHaveBeenCalledTimes(1);
|
|
370
|
+
expect(method.postProgressMessage).toHaveBeenCalledWith(1, 'installingFirmware');
|
|
371
|
+
return finishedStatus;
|
|
372
|
+
})
|
|
373
|
+
.mockResolvedValueOnce(finishedStatus)
|
|
374
|
+
.mockResolvedValueOnce(finishedStatus)
|
|
375
|
+
.mockRejectedValueOnce(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
|
|
376
|
+
const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
|
|
377
|
+
|
|
378
|
+
(method as any).params = {
|
|
379
|
+
expectedTargetVersions: { coprocessor: '1.0.20' },
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
method.device = {
|
|
383
|
+
getCommands: () => ({ typedCall }),
|
|
384
|
+
setCancelableAction: jest.fn(),
|
|
385
|
+
} as unknown as Device;
|
|
386
|
+
method.postProgressMessage = jest.fn();
|
|
387
|
+
|
|
388
|
+
const firmwareUpdate = method as unknown as {
|
|
389
|
+
waitForProtocolV2FirmwareUpdateComplete: (
|
|
390
|
+
value: typeof targets,
|
|
391
|
+
requireCurrentInstallStatus: boolean
|
|
392
|
+
) => Promise<void>;
|
|
393
|
+
reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
|
|
394
|
+
};
|
|
395
|
+
firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
|
|
396
|
+
(method as any).isBleReconnect = jest.fn(() => true);
|
|
397
|
+
|
|
398
|
+
await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
|
|
399
|
+
|
|
400
|
+
expect(reconnectProtocolV2Device).toHaveBeenCalledWith({ skipProtocolProbe: true });
|
|
401
|
+
expect(typedCall).toHaveBeenCalledTimes(6);
|
|
402
|
+
expect(method.postProgressMessage).toHaveBeenNthCalledWith(1, 1, 'installingFirmware');
|
|
403
|
+
expect(method.postProgressMessage).toHaveBeenNthCalledWith(2, 100, 'installingFirmware');
|
|
404
|
+
expect(method.postProgressMessage).toHaveBeenCalledTimes(2);
|
|
405
|
+
}, 10_000);
|
|
406
|
+
|
|
407
|
+
test('rejects stable stale finished BLE status after a status response timeout', async () => {
|
|
408
|
+
const method = new FirmwareUpdateV4({
|
|
409
|
+
id: 1,
|
|
410
|
+
payload: {
|
|
411
|
+
method: 'firmwareUpdateV4',
|
|
412
|
+
connectId: 'pro2-ble',
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
const targets = [{ target_id: 6, path: 'vol0:/coprocessor.bin' }];
|
|
416
|
+
const finishedStatus = {
|
|
417
|
+
type: 'DeviceFirmwareUpdateStatus',
|
|
418
|
+
message: {
|
|
419
|
+
records: [
|
|
420
|
+
{
|
|
421
|
+
target_id: 6,
|
|
422
|
+
status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
|
|
423
|
+
payload_version: 65_556,
|
|
424
|
+
path: 'vol0:/coprocessor.bin',
|
|
425
|
+
},
|
|
426
|
+
],
|
|
427
|
+
},
|
|
428
|
+
};
|
|
429
|
+
const typedCall = jest
|
|
430
|
+
.fn()
|
|
431
|
+
.mockResolvedValueOnce(finishedStatus)
|
|
432
|
+
.mockRejectedValueOnce(
|
|
433
|
+
ERRORS.TypedError(
|
|
434
|
+
HardwareErrorCode.BleTimeoutError,
|
|
435
|
+
'Lowlevel response timeout after 15000ms for DeviceFirmwareUpdateStatusGet'
|
|
436
|
+
)
|
|
437
|
+
)
|
|
438
|
+
.mockResolvedValueOnce(finishedStatus)
|
|
439
|
+
.mockResolvedValueOnce(finishedStatus)
|
|
440
|
+
.mockResolvedValueOnce(finishedStatus)
|
|
441
|
+
.mockResolvedValueOnce(finishedStatus)
|
|
442
|
+
.mockRejectedValueOnce(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
|
|
443
|
+
const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
|
|
444
|
+
|
|
445
|
+
(method as any).params = {
|
|
446
|
+
expectedTargetVersions: { coprocessor: '1.0.20' },
|
|
447
|
+
};
|
|
448
|
+
method.device = {
|
|
449
|
+
getCommands: () => ({ typedCall }),
|
|
450
|
+
setCancelableAction: jest.fn(),
|
|
451
|
+
} as unknown as Device;
|
|
452
|
+
method.postProgressMessage = jest.fn();
|
|
453
|
+
|
|
454
|
+
const firmwareUpdate = method as unknown as {
|
|
455
|
+
waitForProtocolV2FirmwareUpdateComplete: (
|
|
456
|
+
value: typeof targets,
|
|
457
|
+
requireCurrentInstallStatus: boolean
|
|
458
|
+
) => Promise<void>;
|
|
459
|
+
reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
|
|
460
|
+
};
|
|
461
|
+
firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
|
|
462
|
+
(method as any).isBleReconnect = jest.fn(() => true);
|
|
463
|
+
|
|
464
|
+
await expect(
|
|
465
|
+
firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true)
|
|
466
|
+
).rejects.toMatchObject({
|
|
467
|
+
errorCode: HardwareErrorCode.ActionCancelled,
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
expect(reconnectProtocolV2Device).toHaveBeenCalledWith({ skipProtocolProbe: true });
|
|
471
|
+
expect(method.postProgressMessage).not.toHaveBeenCalled();
|
|
472
|
+
}, 10_000);
|
|
420
473
|
|
|
421
474
|
test('confirms App mode when BLE status becomes empty after current install progress', async () => {
|
|
422
475
|
const method = new FirmwareUpdateV4({
|
|
@@ -5391,6 +5391,29 @@ describe('Protocol V2 firmware update targets', () => {
|
|
|
5391
5391
|
});
|
|
5392
5392
|
});
|
|
5393
5393
|
|
|
5394
|
+
test('treats a typed BLE disconnect during Protocol V2 normal reboot as expected', async () => {
|
|
5395
|
+
const method = new FirmwareUpdateV4({
|
|
5396
|
+
id: 1,
|
|
5397
|
+
payload: {
|
|
5398
|
+
method: 'firmwareUpdateV4',
|
|
5399
|
+
},
|
|
5400
|
+
});
|
|
5401
|
+
const typedCall = jest
|
|
5402
|
+
.fn()
|
|
5403
|
+
.mockRejectedValue(ERRORS.TypedError(HardwareErrorCode.BleDeviceDisconnected));
|
|
5404
|
+
|
|
5405
|
+
(method as any).device = stubDevice({
|
|
5406
|
+
getCommands: () => ({ typedCall }),
|
|
5407
|
+
});
|
|
5408
|
+
|
|
5409
|
+
await expect((method as any).protocolV2Reboot(DeviceRebootType.Normal)).resolves.toEqual({
|
|
5410
|
+
message: 'Device rebooted successfully',
|
|
5411
|
+
});
|
|
5412
|
+
expect((method as any).device.markProtocolV2Reboot).toHaveBeenCalledWith(
|
|
5413
|
+
DeviceRebootType.Normal
|
|
5414
|
+
);
|
|
5415
|
+
});
|
|
5416
|
+
|
|
5394
5417
|
test('uses a short timeout and continues after a BLE reboot response timeout', async () => {
|
|
5395
5418
|
const method = new FirmwareUpdateV4({
|
|
5396
5419
|
id: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirmwareUpdateV4.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV4.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAMZ,MAAM,qBAAqB,CAAC;AA0B7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAiC/E,OAAO,KAAK,EAEV,sBAAsB,EAEvB,MAAM,6BAA6B,CAAC;AAqErC,wBAAgB,wCAAwC,CACtD,UAA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BAA8B;IAU5C,OAAO,CAAC,kCAAkC;YAQ5B,cAAc;YAuCd,6BAA6B;YAW7B,0BAA0B;YAoB1B,6BAA6B;YAoD7B,gBAAgB;IA0B9B,OAAO,CAAC,qBAAqB;CAM9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM1D,OAAO,KAAK,EACV,oBAAoB,EACpB,wBAAwB,EACxB,gCAAgC,EAChC,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,MAAM,OAAO,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjG,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC,oBAAoB,GACpB;IACE,QAAQ,CAAC,EAAE,wBAAwB,GAAG,MAAM,GAAG,MAAM,CAAC;IACtD,SAAS,CAAC,EAAE,wBAAwB,GAAG,MAAM,GAAG,MAAM,CAAC;IACvD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,CAAC,EAAE,yBAAyB,EAAE,CAAC;IACtC,QAAQ,CAAC,EAAE,wBAAwB,GAAG,MAAM,GAAG,MAAM,CAAC;IACtD,SAAS,CAAC,EAAE,wBAAwB,GAAG,MAAM,GAAG,MAAM,CAAC;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,MAAM,CAAC,EAAE,gCAAgC,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,gBAAgB,CAAC,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAaF,eAAO,MAAM,mCAAmC,EAAE,oBAEjD,CAAC;AAEF,eAAO,MAAM,0CAA0C,EAAE,CACrD,SAAS,GACT,4BAA4B,CAC/B,EAA8C,CAAC;AAEhD,eAAO,MAAM,6BAA6B,UAAW,OAAO,WA6B3D,CAAC;AAEF,eAAO,MAAM,mCAAmC,UAAW,OAAO,YA6BjE,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,GAAG,gBAAgB,CAQxF;AAsCD,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,0BAA0B,GACjC,oBAAoB,EAAE,CA0BxB"}
|
package/dist/index.js
CHANGED
|
@@ -51816,6 +51816,12 @@ const getProtocolV2UnknownErrorText = (error) => {
|
|
|
51816
51816
|
return parts.filter(Boolean).join(' ');
|
|
51817
51817
|
};
|
|
51818
51818
|
const isProtocolV2DeviceDisconnectedError = (error) => {
|
|
51819
|
+
var _a;
|
|
51820
|
+
const errorCode = error && typeof error === 'object'
|
|
51821
|
+
? (_a = error.errorCode) !== null && _a !== void 0 ? _a : error.code
|
|
51822
|
+
: undefined;
|
|
51823
|
+
if (errorCode === hdShared.HardwareErrorCode.BleDeviceDisconnected)
|
|
51824
|
+
return true;
|
|
51819
51825
|
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51820
51826
|
const compactMessage = message.replace(/\s+/g, '');
|
|
51821
51827
|
return (message.includes('notfounderror') ||
|
|
@@ -52142,7 +52148,7 @@ const PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT = 5 * 1000;
|
|
|
52142
52148
|
const PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT = 15 * 1000;
|
|
52143
52149
|
const PROTOCOL_V2_INSTALL_TIMEOUT = 5 * 60 * 1000;
|
|
52144
52150
|
const PROTOCOL_V2_INSTALL_STATUS_INITIAL_DELAY = 1000;
|
|
52145
|
-
const
|
|
52151
|
+
const PROTOCOL_V2_INSTALL_FINISHED_AFTER_DISCONNECT_POLLS = 4;
|
|
52146
52152
|
const PROTOCOL_V2_TARGET_STATUS_PENDING = 0;
|
|
52147
52153
|
const PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS = 1;
|
|
52148
52154
|
const PROTOCOL_V2_TARGET_STATUS_FINISHED = 2;
|
|
@@ -53893,13 +53899,15 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53893
53899
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53894
53900
|
const expectedTargetIds = new Set(targets.map(target => target.target_id));
|
|
53895
53901
|
const expectedPaths = new Map(targets.map(target => [target.target_id, target.path]));
|
|
53902
|
+
const isBleCoprocessorInstall = this.isBleReconnect() &&
|
|
53903
|
+
expectedTargetIds.has(ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_COPROCESSOR);
|
|
53896
53904
|
const startTime = Date.now();
|
|
53897
53905
|
let lastError;
|
|
53898
53906
|
let shouldReconnect = this.protocolV2InstallNeedsReconnect;
|
|
53899
|
-
let installTransportReleaseObserved = shouldReconnect;
|
|
53900
53907
|
this.protocolV2InstallNeedsReconnect = false;
|
|
53901
53908
|
let deviceInfo;
|
|
53902
53909
|
let bleInstallLinkReady = false;
|
|
53910
|
+
let installStatusDisconnectObserved = false;
|
|
53903
53911
|
let installReconnectObserved = false;
|
|
53904
53912
|
let finishedStatusSnapshotKey;
|
|
53905
53913
|
let finishedStatusSnapshotPolls = 0;
|
|
@@ -53917,7 +53925,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53917
53925
|
deviceInfo = isBleInstallReconnect
|
|
53918
53926
|
? undefined
|
|
53919
53927
|
: yield this.verifyProtocolV2ReconnectIdentity();
|
|
53920
|
-
if (
|
|
53928
|
+
if (isBleInstallReconnect && installStatusDisconnectObserved) {
|
|
53921
53929
|
installReconnectObserved = true;
|
|
53922
53930
|
}
|
|
53923
53931
|
shouldReconnect = false;
|
|
@@ -53956,6 +53964,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53956
53964
|
const matchingFinishedTargetIds = new Set();
|
|
53957
53965
|
const matchingFinishedStatus = matchingStatusTargets
|
|
53958
53966
|
.map(target => {
|
|
53967
|
+
var _a;
|
|
53959
53968
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53960
53969
|
const expectedPath = targetId === undefined ? undefined : expectedPaths.get(targetId);
|
|
53961
53970
|
const expectedVersion = targetId === undefined
|
|
@@ -53965,12 +53974,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53965
53974
|
if (targetId === undefined ||
|
|
53966
53975
|
matchingFinishedTargetIds.has(targetId) ||
|
|
53967
53976
|
!isProtocolV2TargetStatusFinished(target.status) ||
|
|
53968
|
-
target.path !== expectedPath ||
|
|
53969
|
-
(expectedVersion !== undefined &&
|
|
53977
|
+
(Boolean(target.path) && Boolean(expectedPath) && target.path !== expectedPath) ||
|
|
53978
|
+
(expectedVersion !== undefined &&
|
|
53979
|
+
payloadVersion !== undefined &&
|
|
53980
|
+
payloadVersion !== expectedVersion)) {
|
|
53970
53981
|
return undefined;
|
|
53971
53982
|
}
|
|
53972
53983
|
matchingFinishedTargetIds.add(targetId);
|
|
53973
|
-
return [targetId, target.path, payloadVersion !== null && payloadVersion !== void 0 ? payloadVersion : null];
|
|
53984
|
+
return [targetId, (_a = target.path) !== null && _a !== void 0 ? _a : null, payloadVersion !== null && payloadVersion !== void 0 ? payloadVersion : null];
|
|
53974
53985
|
})
|
|
53975
53986
|
.filter((target) => !!target)
|
|
53976
53987
|
.sort(([leftTargetId], [rightTargetId]) => leftTargetId - rightTargetId);
|
|
@@ -54002,10 +54013,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54002
54013
|
this.postProgressMessage(1, 'installingFirmware');
|
|
54003
54014
|
fastFinishedInstallProgressReported = true;
|
|
54004
54015
|
}
|
|
54005
|
-
const
|
|
54016
|
+
const finishedAfterDisconnectObserved = finishedStatusSnapshotPolls >= PROTOCOL_V2_INSTALL_FINISHED_AFTER_DISCONNECT_POLLS;
|
|
54006
54017
|
const hasCurrentInstallEvidence = currentInstallStatusObserved ||
|
|
54007
54018
|
this.protocolV2InstallTerminalSuccessObserved ||
|
|
54008
|
-
|
|
54019
|
+
finishedAfterDisconnectObserved;
|
|
54009
54020
|
if (hasCurrentInstallEvidence) {
|
|
54010
54021
|
installEvidenceObserved = true;
|
|
54011
54022
|
}
|
|
@@ -54013,7 +54024,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54013
54024
|
if (shouldVerifyTargetCompletion &&
|
|
54014
54025
|
this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths, requireCurrentInstallStatus &&
|
|
54015
54026
|
!this.protocolV2InstallTerminalSuccessObserved &&
|
|
54016
|
-
!
|
|
54027
|
+
!finishedAfterDisconnectObserved
|
|
54017
54028
|
? liveTargetIds
|
|
54018
54029
|
: undefined)) {
|
|
54019
54030
|
return;
|
|
@@ -54090,8 +54101,10 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
54090
54101
|
}
|
|
54091
54102
|
}
|
|
54092
54103
|
else {
|
|
54093
|
-
if (
|
|
54094
|
-
|
|
54104
|
+
if (isBleCoprocessorInstall &&
|
|
54105
|
+
isProtocolV2DeviceDisconnectedError(error) &&
|
|
54106
|
+
!isProtocolV2ResponseTimeout(error)) {
|
|
54107
|
+
installStatusDisconnectObserved = true;
|
|
54095
54108
|
finishedStatusSnapshotKey = undefined;
|
|
54096
54109
|
finishedStatusSnapshotPolls = 0;
|
|
54097
54110
|
}
|
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.186",
|
|
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.186",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.186",
|
|
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": "d4b7f8e0e308ed4b95b1d82e385e1ec4b3e0e3f6"
|
|
50
50
|
}
|
|
@@ -93,7 +93,7 @@ const PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT = 5 * 1000;
|
|
|
93
93
|
const PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT = 15 * 1000;
|
|
94
94
|
const PROTOCOL_V2_INSTALL_TIMEOUT = 5 * 60 * 1000;
|
|
95
95
|
const PROTOCOL_V2_INSTALL_STATUS_INITIAL_DELAY = 1000;
|
|
96
|
-
const
|
|
96
|
+
const PROTOCOL_V2_INSTALL_FINISHED_AFTER_DISCONNECT_POLLS = 4;
|
|
97
97
|
const PROTOCOL_V2_TARGET_STATUS_PENDING = 0;
|
|
98
98
|
const PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS = 1;
|
|
99
99
|
const PROTOCOL_V2_TARGET_STATUS_FINISHED = 2;
|
|
@@ -2517,15 +2517,18 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2517
2517
|
) {
|
|
2518
2518
|
const expectedTargetIds = new Set(targets.map(target => target.target_id));
|
|
2519
2519
|
const expectedPaths = new Map(targets.map(target => [target.target_id, target.path]));
|
|
2520
|
+
const isBleCoprocessorInstall =
|
|
2521
|
+
this.isBleReconnect() &&
|
|
2522
|
+
expectedTargetIds.has(ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_COPROCESSOR);
|
|
2520
2523
|
const startTime = Date.now();
|
|
2521
2524
|
let lastError: unknown;
|
|
2522
2525
|
// The loader may release either USB or BLE as installation starts. Recovery reconnects
|
|
2523
2526
|
// directly to status polling without generic Ping or DeviceInfo probes.
|
|
2524
2527
|
let shouldReconnect = this.protocolV2InstallNeedsReconnect;
|
|
2525
|
-
let installTransportReleaseObserved = shouldReconnect;
|
|
2526
2528
|
this.protocolV2InstallNeedsReconnect = false;
|
|
2527
2529
|
let deviceInfo: ProtocolV2DeviceInfo | undefined;
|
|
2528
2530
|
let bleInstallLinkReady = false;
|
|
2531
|
+
let installStatusDisconnectObserved = false;
|
|
2529
2532
|
let installReconnectObserved = false;
|
|
2530
2533
|
let finishedStatusSnapshotKey: string | undefined;
|
|
2531
2534
|
let finishedStatusSnapshotPolls = 0;
|
|
@@ -2546,7 +2549,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2546
2549
|
deviceInfo = isBleInstallReconnect
|
|
2547
2550
|
? undefined
|
|
2548
2551
|
: await this.verifyProtocolV2ReconnectIdentity();
|
|
2549
|
-
if (
|
|
2552
|
+
if (isBleInstallReconnect && installStatusDisconnectObserved) {
|
|
2550
2553
|
installReconnectObserved = true;
|
|
2551
2554
|
}
|
|
2552
2555
|
shouldReconnect = false;
|
|
@@ -2604,15 +2607,17 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2604
2607
|
targetId === undefined ||
|
|
2605
2608
|
matchingFinishedTargetIds.has(targetId) ||
|
|
2606
2609
|
!isProtocolV2TargetStatusFinished(target.status) ||
|
|
2607
|
-
target.path !== expectedPath ||
|
|
2608
|
-
(expectedVersion !== undefined &&
|
|
2610
|
+
(Boolean(target.path) && Boolean(expectedPath) && target.path !== expectedPath) ||
|
|
2611
|
+
(expectedVersion !== undefined &&
|
|
2612
|
+
payloadVersion !== undefined &&
|
|
2613
|
+
payloadVersion !== expectedVersion)
|
|
2609
2614
|
) {
|
|
2610
2615
|
return undefined;
|
|
2611
2616
|
}
|
|
2612
2617
|
matchingFinishedTargetIds.add(targetId);
|
|
2613
|
-
return [targetId, target.path, payloadVersion ?? null] as const;
|
|
2618
|
+
return [targetId, target.path ?? null, payloadVersion ?? null] as const;
|
|
2614
2619
|
})
|
|
2615
|
-
.filter((target): target is readonly [number, string, number | null] => !!target)
|
|
2620
|
+
.filter((target): target is readonly [number, string | null, number | null] => !!target)
|
|
2616
2621
|
.sort(([leftTargetId], [rightTargetId]) => leftTargetId - rightTargetId);
|
|
2617
2622
|
const hasCompleteMatchingFinishedStatus =
|
|
2618
2623
|
matchingFinishedStatus.length === expectedTargetIds.size &&
|
|
@@ -2642,18 +2647,17 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2642
2647
|
!this.protocolV2InstallTerminalSuccessObserved &&
|
|
2643
2648
|
!fastFinishedInstallProgressReported
|
|
2644
2649
|
) {
|
|
2645
|
-
// A fast
|
|
2646
|
-
//
|
|
2647
|
-
// FINISHED snapshot is stabilized; completion still requires all polls.
|
|
2650
|
+
// A fast BLE install may finish while disconnected, so IN_PROGRESS can be hidden.
|
|
2651
|
+
// A status response timeout alone is not evidence that the install was accepted.
|
|
2648
2652
|
this.postProgressMessage(1, 'installingFirmware');
|
|
2649
2653
|
fastFinishedInstallProgressReported = true;
|
|
2650
2654
|
}
|
|
2651
|
-
const
|
|
2652
|
-
finishedStatusSnapshotPolls >=
|
|
2655
|
+
const finishedAfterDisconnectObserved =
|
|
2656
|
+
finishedStatusSnapshotPolls >= PROTOCOL_V2_INSTALL_FINISHED_AFTER_DISCONNECT_POLLS;
|
|
2653
2657
|
const hasCurrentInstallEvidence =
|
|
2654
2658
|
currentInstallStatusObserved ||
|
|
2655
2659
|
this.protocolV2InstallTerminalSuccessObserved ||
|
|
2656
|
-
|
|
2660
|
+
finishedAfterDisconnectObserved;
|
|
2657
2661
|
if (hasCurrentInstallEvidence) {
|
|
2658
2662
|
installEvidenceObserved = true;
|
|
2659
2663
|
}
|
|
@@ -2667,7 +2671,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2667
2671
|
expectedPaths,
|
|
2668
2672
|
requireCurrentInstallStatus &&
|
|
2669
2673
|
!this.protocolV2InstallTerminalSuccessObserved &&
|
|
2670
|
-
!
|
|
2674
|
+
!finishedAfterDisconnectObserved
|
|
2671
2675
|
? liveTargetIds
|
|
2672
2676
|
: undefined
|
|
2673
2677
|
)
|
|
@@ -2783,8 +2787,12 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2783
2787
|
);
|
|
2784
2788
|
}
|
|
2785
2789
|
} else {
|
|
2786
|
-
if (
|
|
2787
|
-
|
|
2790
|
+
if (
|
|
2791
|
+
isBleCoprocessorInstall &&
|
|
2792
|
+
isProtocolV2DeviceDisconnectedError(error) &&
|
|
2793
|
+
!isProtocolV2ResponseTimeout(error)
|
|
2794
|
+
) {
|
|
2795
|
+
installStatusDisconnectObserved = true;
|
|
2788
2796
|
finishedStatusSnapshotKey = undefined;
|
|
2789
2797
|
finishedStatusSnapshotPolls = 0;
|
|
2790
2798
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
|
+
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
3
|
|
|
3
4
|
import { invalidParameter, validateNonEmptyString } from '../helpers/filesystemValidation';
|
|
4
5
|
import { ProtocolV2FirmwareTargetType } from '../../protocols/protocol-v2/firmware';
|
|
@@ -103,6 +104,13 @@ export const getProtocolV2UnknownErrorText = (error: unknown) => {
|
|
|
103
104
|
};
|
|
104
105
|
|
|
105
106
|
export const isProtocolV2DeviceDisconnectedError = (error: unknown) => {
|
|
107
|
+
const errorCode =
|
|
108
|
+
error && typeof error === 'object'
|
|
109
|
+
? (error as { errorCode?: number; code?: number }).errorCode ??
|
|
110
|
+
(error as { errorCode?: number; code?: number }).code
|
|
111
|
+
: undefined;
|
|
112
|
+
if (errorCode === HardwareErrorCode.BleDeviceDisconnected) return true;
|
|
113
|
+
|
|
106
114
|
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
107
115
|
const compactMessage = message.replace(/\s+/g, '');
|
|
108
116
|
return (
|