mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Huawei: device specific fixes. Watch 3 for example
This commit is contained in:
parent
48717aaf42
commit
d23c931f95
@ -95,7 +95,7 @@ public class HuaweiInstallHandler implements InstallHandler {
|
||||
LOG.info("unknownBitrate {}", restrictions.unknownBitrate);
|
||||
|
||||
if(currentMusicInfo.getChannels() > restrictions.channels) {
|
||||
LOG.error("Not supported channels couunt {} > {}", currentMusicInfo.getChannels(), restrictions.channels);
|
||||
LOG.error("Not supported channels count {} > {}", currentMusicInfo.getChannels(), restrictions.channels);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -60,12 +60,12 @@ public class HuaweiMusicUtils {
|
||||
}
|
||||
|
||||
public static class MusicCapabilities {
|
||||
public short availableSpace = 0;
|
||||
public int availableSpace = 0;
|
||||
public List<String> supportedFormats = null;
|
||||
public short maxMusicCount = 0;
|
||||
public short maxPlaylistCount = 0;
|
||||
public short currentMusicCount = 0; // TODO: not sure
|
||||
public byte unknown = 0; // TODO: not sure
|
||||
public int maxMusicCount = 0;
|
||||
public int maxPlaylistCount = 0;
|
||||
public int currentMusicCount = 0; // TODO: not sure
|
||||
public int unknown = 0; // TODO: not sure
|
||||
public List<FormatRestrictions> formatsRestrictions = null;
|
||||
public List<PageStruct> pageStruct = null;
|
||||
|
||||
|
@ -827,12 +827,10 @@ public class HuaweiPacket {
|
||||
return retv;
|
||||
}
|
||||
|
||||
public List<byte[]> serializeFileChunk(byte[] fileChunk, int uploadPosition, short unitSize, byte fileId, boolean isEncrypted) throws SerializeException {
|
||||
public List<byte[]> serializeFileChunk(byte[] fileChunk, int uploadPosition, int unitSize, byte fileId, boolean isEncrypted) throws SerializeException {
|
||||
List<byte[]> retv = new ArrayList<>();
|
||||
int headerLength = 5; // Magic + (short)(bodyLength + 1) + 0x00
|
||||
int sliceHeaderLength = 6;
|
||||
|
||||
int footerLength = 2; //CRC16
|
||||
final int sliceHeaderLength = 6;
|
||||
final int packageHeaderAndFooterLength = 6;
|
||||
|
||||
int packetCount = (int) Math.ceil(((double) fileChunk.length) / (double) unitSize);
|
||||
|
||||
@ -842,7 +840,7 @@ public class HuaweiPacket {
|
||||
|
||||
for (int i = 0; i < packetCount; i++) {
|
||||
|
||||
short contentSize = (short) Math.min(unitSize, buffer.remaining());
|
||||
int contentSize = Math.min(unitSize, buffer.remaining());
|
||||
|
||||
ByteBuffer payload = ByteBuffer.allocate(contentSize + sliceHeaderLength);
|
||||
payload.put(fileId); // Slice
|
||||
@ -870,45 +868,23 @@ public class HuaweiPacket {
|
||||
throw new HuaweiPacket.SerializeException("new payload is null");
|
||||
}
|
||||
|
||||
short packetSize = (short)(new_payload.length + sliceHeaderLength + footerLength);
|
||||
ByteBuffer packet = ByteBuffer.allocate(packetSize);
|
||||
|
||||
int start = packet.position();
|
||||
packet.put((byte) 0x5a); // Magic byte
|
||||
packet.putShort((short) (packetSize - headerLength)); // Length
|
||||
|
||||
packet.put((byte) 0x00);
|
||||
packet.put(this.serviceId);
|
||||
packet.put(this.commandId);
|
||||
|
||||
packet.put(new_payload);
|
||||
|
||||
int length = packet.position() - start;
|
||||
if (length != packetSize - footerLength) {
|
||||
throw new HuaweiPacket.SerializeException(String.format(GBApplication.getLanguage(), "Packet lengths don't match! %d != %d", length, packetSize + headerLength));
|
||||
if ((new_payload.length + packageHeaderAndFooterLength) > paramsProvider.getSliceSize()) {
|
||||
retv.addAll(serializeSliced(new_payload));
|
||||
} else {
|
||||
retv.addAll(serializeUnsliced(new_payload));
|
||||
}
|
||||
|
||||
byte[] complete = new byte[length];
|
||||
packet.position(start);
|
||||
packet.get(complete, 0, length);
|
||||
int crc16 = CheckSums.getCRC16(complete, 0x0000);
|
||||
|
||||
packet.putShort((short) crc16); // CRC16
|
||||
|
||||
sliceStart += contentSize;
|
||||
|
||||
retv.add(packet.array());
|
||||
}
|
||||
return retv;
|
||||
}
|
||||
|
||||
public List<byte[]> serializeFileChunk1c(byte[] fileChunk, short transferSize, int packetCount) throws SerializeException {
|
||||
List<byte[]> retv = new ArrayList<>();
|
||||
int headerLength = 4; // Magic + (short)(bodyLength + 1) + 0x00
|
||||
int bodyHeaderLength = 2; // sID + cID
|
||||
int footerLength = 2; //CRC16
|
||||
int subHeaderLength = 1;
|
||||
|
||||
final int subHeaderLength = 1;
|
||||
final int packageHeaderAndFooterLength = 6;
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(fileChunk);
|
||||
|
||||
@ -925,34 +901,11 @@ public class HuaweiPacket {
|
||||
|
||||
byte[] new_payload = payload.array();
|
||||
|
||||
int bodyLength = bodyHeaderLength + new_payload.length;
|
||||
|
||||
short packetSize = (short)(headerLength + bodyLength + footerLength);
|
||||
ByteBuffer packet = ByteBuffer.allocate(packetSize);
|
||||
|
||||
int start = packet.position();
|
||||
packet.put((byte) 0x5a); // Magic byte
|
||||
packet.putShort((short) (bodyLength + 1)); // Length
|
||||
|
||||
packet.put((byte) 0x00);
|
||||
packet.put(this.serviceId);
|
||||
packet.put(this.commandId);
|
||||
|
||||
packet.put(new_payload);
|
||||
|
||||
int length = packet.position() - start;
|
||||
if (length != packetSize - footerLength) {
|
||||
throw new HuaweiPacket.SerializeException(String.format(GBApplication.getLanguage(), "Packet lengths don't match! %d != %d", length, packetSize + headerLength));
|
||||
if ((new_payload.length + packageHeaderAndFooterLength) > paramsProvider.getSliceSize()) {
|
||||
retv.addAll(serializeSliced(new_payload));
|
||||
} else {
|
||||
retv.addAll(serializeUnsliced(new_payload));
|
||||
}
|
||||
|
||||
byte[] complete = new byte[length];
|
||||
packet.position(start);
|
||||
packet.get(complete, 0, length);
|
||||
int crc16 = CheckSums.getCRC16(complete, 0x0000);
|
||||
|
||||
packet.putShort((short) crc16); // CRC16
|
||||
|
||||
retv.add(packet.array());
|
||||
}
|
||||
return retv;
|
||||
}
|
||||
|
@ -243,6 +243,16 @@ public class HuaweiTLV {
|
||||
return ByteBuffer.wrap(getBytes(tag)).getShort();
|
||||
}
|
||||
|
||||
public Integer getAsInteger(int tag) throws HuaweiPacket.MissingTagException {
|
||||
byte[] bytes = getBytes(tag);
|
||||
if(bytes.length == 1) {
|
||||
return bytes[0] & 0xFF;
|
||||
} else if(bytes.length == 2) {
|
||||
return ByteBuffer.wrap(getBytes(tag)).getShort() & 0xFFFF;
|
||||
}
|
||||
return ByteBuffer.wrap(getBytes(tag)).getInt();
|
||||
}
|
||||
|
||||
public String getString(int tag) throws HuaweiPacket.MissingTagException {
|
||||
return new String(getBytes(tag), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ public class FileUpload {
|
||||
public static class FileUploadParams {
|
||||
public byte file_id = 0;
|
||||
public String protocolVersion = "";
|
||||
public short app_wait_time = 0;
|
||||
public byte bitmap_enable = 0;
|
||||
public short unit_size = 0;
|
||||
public int app_wait_time = 0;
|
||||
public int bitmap_enable = 0;
|
||||
public int unit_size = 0;
|
||||
public int max_apply_data_size = 0;
|
||||
public short interval = 0;
|
||||
public int interval = 0;
|
||||
public int received_file_size = 0;
|
||||
public byte no_encrypt = 0;
|
||||
}
|
||||
@ -65,7 +65,7 @@ public class FileUpload {
|
||||
this.tlv = new HuaweiTLV()
|
||||
.put(0x01, fileName)
|
||||
.put(0x02, fileSize)
|
||||
.put(0x03, (byte) fileType);
|
||||
.put(0x03, fileType);
|
||||
|
||||
if (fileType == Filetype.watchface) {
|
||||
String watchfaceName = fileName.split("_")[0];
|
||||
@ -164,11 +164,11 @@ public class FileUpload {
|
||||
public void parseTlv() throws HuaweiPacket.ParseException {
|
||||
this.fileUploadParams.file_id = this.tlv.getByte(0x01);
|
||||
this.fileUploadParams.protocolVersion = this.tlv.getString(0x02);
|
||||
this.fileUploadParams.app_wait_time = this.tlv.getShort(0x03);
|
||||
this.fileUploadParams.bitmap_enable = this.tlv.getByte(0x04);
|
||||
this.fileUploadParams.unit_size = this.tlv.getShort(0x05);
|
||||
this.fileUploadParams.max_apply_data_size = this.tlv.getInteger(0x06);
|
||||
this.fileUploadParams.interval = this.tlv.getShort(0x07);
|
||||
this.fileUploadParams.app_wait_time = this.tlv.getAsInteger(0x03);
|
||||
this.fileUploadParams.bitmap_enable = this.tlv.getAsInteger(0x04);
|
||||
this.fileUploadParams.unit_size = this.tlv.getAsInteger(0x05);
|
||||
this.fileUploadParams.max_apply_data_size = this.tlv.getAsInteger(0x06);
|
||||
this.fileUploadParams.interval = this.tlv.getAsInteger(0x07);
|
||||
this.fileUploadParams.received_file_size = this.tlv.getInteger(0x08);
|
||||
if (this.tlv.contains(0x09)) // optional for older devices
|
||||
this.fileUploadParams.no_encrypt = this.tlv.getByte(0x09);
|
||||
|
@ -18,9 +18,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiMusicUtils.parseFormatBits;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -266,15 +263,15 @@ public class MusicControl {
|
||||
// LOG.info("Unknown: " + this.tlv.getShort(0x01));
|
||||
|
||||
if (this.tlv.contains(0x02))
|
||||
params.availableSpace = this.tlv.getShort(0x02);
|
||||
params.availableSpace = this.tlv.getAsInteger(0x02);
|
||||
if (this.tlv.contains(0x03)) {
|
||||
byte[] formatBits = this.tlv.getBytes(0x03);
|
||||
params.supportedFormats = parseFormatBits(formatBits);
|
||||
}
|
||||
if (this.tlv.contains(0x04))
|
||||
params.maxMusicCount = this.tlv.getShort(0x04);
|
||||
params.maxMusicCount = this.tlv.getAsInteger(0x04);
|
||||
if (this.tlv.contains(0x05))
|
||||
params.currentMusicCount = this.tlv.getByte(0x05);
|
||||
params.currentMusicCount = this.tlv.getAsInteger(0x05);
|
||||
|
||||
if (this.tlv.contains(0x86)) {
|
||||
params.pageStruct = new ArrayList<>();
|
||||
@ -327,15 +324,15 @@ public class MusicControl {
|
||||
@Override
|
||||
public void parseTlv() throws ParseException {
|
||||
if (this.tlv.contains(0x01))
|
||||
params.availableSpace = this.tlv.getShort(0x01);
|
||||
params.availableSpace = this.tlv.getAsInteger(0x01);
|
||||
if (this.tlv.contains(0x02)) {
|
||||
byte[] formatBits = this.tlv.getBytes(0x02);
|
||||
params.supportedFormats = parseFormatBits(formatBits);
|
||||
}
|
||||
if (this.tlv.contains(0x03))
|
||||
params.maxMusicCount = this.tlv.getShort(0x03);
|
||||
params.maxMusicCount = this.tlv.getAsInteger(0x03);
|
||||
if (this.tlv.contains(0x04))
|
||||
params.maxPlaylistCount = this.tlv.getShort(0x04);
|
||||
params.maxPlaylistCount = this.tlv.getAsInteger(0x04);
|
||||
if (this.tlv.contains(0x05))
|
||||
params.unknown = this.tlv.getByte(0x05);
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class HuaweiUploadManager {
|
||||
this.fileUploadParams = params;
|
||||
}
|
||||
|
||||
public short getUnitSize() {
|
||||
public int getUnitSize() {
|
||||
return fileUploadParams.unit_size;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user