@lineageos-infra/libmjolnir 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -100,6 +100,12 @@ declare class InboundPacket extends BasePacket {
100
100
  }
101
101
  //#endregion
102
102
  //#region src/packets/outbound/OutboundPacket.d.ts
103
+ declare enum EmptySendKind {
104
+ None = 0,
105
+ Before = 1,
106
+ After = 2,
107
+ BeforeAndAfter = 3
108
+ }
103
109
  declare class OutboundPacket extends BasePacket {
104
110
  constructor(size: number);
105
111
  packInteger(offset: number, value: number): void;
@@ -231,7 +237,7 @@ declare class OdinDevice {
231
237
  */
232
238
  sendLz4File(fileData: Uint8Array, binaryType: EntryBinaryType, deviceType: number, fileIdentifier: number): Promise<void>;
233
239
  _sendFileSequence(sequenceData: Uint8Array, endByteCount: number, binaryType: EntryBinaryType, deviceType: number, fileIdentifier: number, isLastSequence: boolean, lz4: boolean): Promise<void>;
234
- sendPacket(packet: OutboundPacket, timeout?: number): Promise<void>;
240
+ sendPacket(packet: OutboundPacket, emptySendKind?: EmptySendKind, timeout?: number): Promise<void>;
235
241
  receivePacket<T extends InboundPacket>(Packet: {
236
242
  new (): T;
237
243
  }, timeout?: number, size?: number): Promise<T>;
package/dist/index.js CHANGED
@@ -901,7 +901,7 @@ function* lz4Sequences(data, header, maxSequenceDecompressedSize) {
901
901
  //#endregion
902
902
  //#region src/OdinDevice.ts
903
903
  const BEGIN_SESSION_DELAY = 3e3;
904
- const EMPTY_RECEIVE_TIMEOUT = 100;
904
+ const EMPTY_TRANSFER_TIMEOUT = 100;
905
905
  const DEFAULT_DEVICE_OPTIONS = {
906
906
  logging: false,
907
907
  timeout: 5e3,
@@ -1157,25 +1157,28 @@ var OdinDevice = class {
1157
1157
  }
1158
1158
  }
1159
1159
  async _sendFileSequence(sequenceData, endByteCount, binaryType, deviceType, fileIdentifier, isLastSequence, lz4) {
1160
- await this.sendPacket(new FlashPartFileTransferPacket(sequenceData.length, lz4), this._flashTimeout);
1160
+ await this.sendPacket(new FlashPartFileTransferPacket(sequenceData.length, lz4), void 0, this._flashTimeout);
1161
1161
  await this.receivePacket(FileTransferResponse, this._flashTimeout);
1162
1162
  const partCount = Math.ceil(sequenceData.length / this._flashPacketSize);
1163
1163
  for (let filePartIndex = 0; filePartIndex < partCount; filePartIndex++) {
1164
1164
  this._log("info", `sending part ${filePartIndex + 1} of ${partCount}`);
1165
1165
  const startOffset = filePartIndex * this._flashPacketSize;
1166
1166
  const partData = sequenceData.slice(startOffset, startOffset + this._flashPacketSize);
1167
- await this.sendPacket(new SendFilePartPacket(partData, this._flashPacketSize), this._flashTimeout);
1167
+ await this.sendPacket(new SendFilePartPacket(partData, this._flashPacketSize), filePartIndex === 0 ? 0 : 1, this._flashTimeout);
1168
1168
  const receivedPartIndex = (await this.receivePacket(SendFilePartResponse, this._flashTimeout)).partIndex;
1169
1169
  if (receivedPartIndex !== filePartIndex) throw new Error(`Expected file part index: ${filePartIndex} Received: ${receivedPartIndex}`);
1170
1170
  }
1171
1171
  const endPacket = binaryType === 1 ? new EndModemFileTransferPacket(endByteCount, binaryType, deviceType, isLastSequence, lz4) : new EndPhoneFileTransferPacket(endByteCount, binaryType, deviceType, fileIdentifier, isLastSequence, lz4);
1172
- await this.sendPacket(endPacket, this._flashTimeout);
1172
+ await this.sendPacket(endPacket, 3, this._flashTimeout);
1173
1173
  await this.receivePacket(FileTransferResponse, this._flashTimeout);
1174
1174
  }
1175
- async sendPacket(packet, timeout) {
1175
+ async sendPacket(packet, emptySendKind, timeout) {
1176
1176
  packet.pack();
1177
1177
  this._log("debug", "sending", packet);
1178
+ if (emptySendKind === void 0) emptySendKind = 2;
1179
+ if ((emptySendKind & 1) !== 0) await this.transport.send(new Uint8Array(), EMPTY_TRANSFER_TIMEOUT).catch(() => {});
1178
1180
  await this.transport.send(packet.data, timeout ?? this.deviceOptions.timeout);
1181
+ if ((emptySendKind & 2) !== 0) await this.transport.send(new Uint8Array(), EMPTY_TRANSFER_TIMEOUT).catch(() => {});
1179
1182
  this._log("debug", "sendPacket sent", packet);
1180
1183
  }
1181
1184
  async receivePacket(Packet, timeout, size) {
@@ -1189,7 +1192,7 @@ var OdinDevice = class {
1189
1192
  return packet;
1190
1193
  }
1191
1194
  async _emptyReceive(timeout) {
1192
- await this.transport.emptyReceive(1024, timeout ?? EMPTY_RECEIVE_TIMEOUT);
1195
+ await this.transport.emptyReceive(1024, timeout ?? EMPTY_TRANSFER_TIMEOUT);
1193
1196
  }
1194
1197
  };
1195
1198
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lineageos-infra/libmjolnir",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "WebUSB library for communicating with Samsung devices in Download Mode",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",