1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 18:45:49 +01:00

Amazfit Bip S: support flashing of new AGPS files with UIHH header

We do not know how to generate them yet.
But it was confirmed working with a file we reconstructed from a bluetooth hci dump
This commit is contained in:
Andreas Shimokawa 2021-05-11 12:10:40 +02:00
parent f553ac663e
commit 5765407366
11 changed files with 18 additions and 11 deletions

View File

@ -40,10 +40,14 @@ public abstract class HuamiFirmwareInfo {
0x48, 0x4d, 0x44, 0x49, 0x41, 0x4c
};
public static final byte[] WATCHFACE_HEADER_UIHH = new byte[]{
public static final byte[] UIHH_HEADER = new byte[]{
'U', 'I', 'H', 'H'
};
public static final byte[] AGPS_UIHH_HEADER = new byte[]{
'U', 'I', 'H', 'H', 0x04
};
protected static final byte[] FT_HEADER = new byte[]{ // HMZK font file (*.ft, *.ft.xx)
0x48, 0x4d, 0x5a, 0x4b
};

View File

@ -23,7 +23,7 @@ public enum HuamiFirmwareType {
RES_COMPRESSED((byte) 130),
GPS((byte) 3),
GPS_CEP((byte) 4),
GPS_CEP_NEW((byte) -4),
AGPS_UIHH((byte) -4),
GPS_ALMANAC((byte) 5),
WATCHFACE((byte) 8),
FONT_LATIN((byte) 11),

View File

@ -55,7 +55,7 @@ public class AmazfitBand5FirmwareInfo extends HuamiFirmwareInfo {
}
return HuamiFirmwareType.INVALID;
}
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH)) {
if (ArrayUtils.startsWith(bytes, UIHH_HEADER) && (bytes[4] == 1 || bytes[4] == 2)) {
return HuamiFirmwareType.WATCHFACE;
}
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {

View File

@ -99,6 +99,9 @@ public class AmazfitBipSFirmwareInfo extends HuamiFirmwareInfo {
if (ArrayUtils.startsWith(bytes, GPS_CEP_HEADER)) {
return HuamiFirmwareType.GPS_CEP;
}
if (ArrayUtils.startsWith(bytes, AGPS_UIHH_HEADER)) {
return HuamiFirmwareType.AGPS_UIHH;
}
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {
if (bytes[10] == 0x01 || bytes[10] == 0x06 || bytes[10] == 0x03) {
return HuamiFirmwareType.FONT;

View File

@ -78,7 +78,7 @@ public class AmazfitGTR2FirmwareInfo extends HuamiFirmwareInfo {
}
return HuamiFirmwareType.INVALID;
}
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH) || ArrayUtils.startsWith(bytes, WATCHFACE_HEADER) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
if ((ArrayUtils.startsWith(bytes, UIHH_HEADER) && (bytes[4] == 1 || bytes[4] == 2)) || ArrayUtils.startsWith(bytes, WATCHFACE_HEADER) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
return HuamiFirmwareType.WATCHFACE;
}
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {

View File

@ -78,7 +78,7 @@ public class AmazfitGTR2eFirmwareInfo extends HuamiFirmwareInfo {
}
return HuamiFirmwareType.INVALID;
}
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH) || ArrayUtils.startsWith(bytes, WATCHFACE_HEADER) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
if ((ArrayUtils.startsWith(bytes, UIHH_HEADER) && (bytes[4] == 1 || bytes[4] == 2)) || ArrayUtils.startsWith(bytes, WATCHFACE_HEADER) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
return HuamiFirmwareType.WATCHFACE;
}
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {

View File

@ -78,7 +78,7 @@ public class AmazfitGTS2FirmwareInfo extends HuamiFirmwareInfo {
}
return HuamiFirmwareType.INVALID;
}
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH) || ArrayUtils.startsWith(bytes, WATCHFACE_HEADER) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
if ((ArrayUtils.startsWith(bytes, UIHH_HEADER) && (bytes[4] == 1 || bytes[4] == 2)) || ArrayUtils.startsWith(bytes, WATCHFACE_HEADER) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
return HuamiFirmwareType.WATCHFACE;
}
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {

View File

@ -78,7 +78,7 @@ public class AmazfitGTS2MiniFirmwareInfo extends HuamiFirmwareInfo {
}
return HuamiFirmwareType.INVALID;
}
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH) || ArrayUtils.startsWith(bytes, WATCHFACE_HEADER) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
if ((ArrayUtils.startsWith(bytes, UIHH_HEADER) && (bytes[4] == 1 || bytes[4] == 2)) || ArrayUtils.startsWith(bytes, WATCHFACE_HEADER) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
return HuamiFirmwareType.WATCHFACE;
}
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {

View File

@ -78,7 +78,7 @@ public class AmazfitGTS2eFirmwareInfo extends HuamiFirmwareInfo {
}
return HuamiFirmwareType.INVALID;
}
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH) || ArrayUtils.startsWith(bytes, WATCHFACE_HEADER) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
if ((ArrayUtils.startsWith(bytes, UIHH_HEADER) && (bytes[4] == 1 || bytes[4] == 2)) || ArrayUtils.startsWith(bytes, WATCHFACE_HEADER) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, WATCHFACE_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
return HuamiFirmwareType.WATCHFACE;
}
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {

View File

@ -70,7 +70,7 @@ public class MiBand5FirmwareInfo extends HuamiFirmwareInfo {
}
return HuamiFirmwareType.INVALID;
}
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH)) {
if (ArrayUtils.startsWith(bytes, UIHH_HEADER) && (bytes[4] == 1 || bytes[4] == 2)) {
return HuamiFirmwareType.WATCHFACE;
}
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {

View File

@ -33,7 +33,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareT
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo.WATCHFACE_HEADER_UIHH;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo.UIHH_HEADER;
public class UpdateFirmwareOperationNew extends UpdateFirmwareOperation {
private static final Logger LOG = LoggerFactory.getLogger(UpdateFirmwareOperationNew.class);
@ -67,7 +67,7 @@ public class UpdateFirmwareOperationNew extends UpdateFirmwareOperation {
if (getFirmwareInfo().getFirmwareType() == HuamiFirmwareType.WATCHFACE) {
byte[] fwBytes = firmwareInfo.getBytes();
if (ArrayUtils.startsWith(fwBytes, WATCHFACE_HEADER_UIHH)) {
if (ArrayUtils.startsWith(fwBytes, UIHH_HEADER)) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION),
new byte[]{0x39, 0x00, 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff,
fwBytes[18],