From 576540736697f471cec77d9feb83924752d47905 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 11 May 2021 12:10:40 +0200 Subject: [PATCH] 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 --- .../service/devices/huami/HuamiFirmwareInfo.java | 6 +++++- .../service/devices/huami/HuamiFirmwareType.java | 2 +- .../huami/amazfitband5/AmazfitBand5FirmwareInfo.java | 2 +- .../devices/huami/amazfitbips/AmazfitBipSFirmwareInfo.java | 3 +++ .../devices/huami/amazfitgtr2/AmazfitGTR2FirmwareInfo.java | 2 +- .../devices/huami/amazfitgtr2/AmazfitGTR2eFirmwareInfo.java | 2 +- .../devices/huami/amazfitgts2/AmazfitGTS2FirmwareInfo.java | 2 +- .../huami/amazfitgts2/AmazfitGTS2MiniFirmwareInfo.java | 2 +- .../devices/huami/amazfitgts2/AmazfitGTS2eFirmwareInfo.java | 2 +- .../service/devices/huami/miband5/MiBand5FirmwareInfo.java | 2 +- .../huami/operations/UpdateFirmwareOperationNew.java | 4 ++-- 11 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java index a887f887f..3499533c7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java @@ -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 }; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareType.java index d343a6e7d..2fd948add 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareType.java @@ -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), diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5FirmwareInfo.java index 9d3925b94..137c465bc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5FirmwareInfo.java @@ -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)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSFirmwareInfo.java index 7b39a0a64..4391d87d2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSFirmwareInfo.java @@ -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; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2FirmwareInfo.java index f13ba77aa..d3a75c88d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2FirmwareInfo.java @@ -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)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2eFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2eFirmwareInfo.java index 2cbf3ebc2..498ec103f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2eFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr2/AmazfitGTR2eFirmwareInfo.java @@ -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)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2FirmwareInfo.java index 43a550e5d..a347c8620 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2FirmwareInfo.java @@ -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)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2MiniFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2MiniFirmwareInfo.java index 96ff0124b..c1aecd981 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2MiniFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2MiniFirmwareInfo.java @@ -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)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2eFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2eFirmwareInfo.java index 87e7adb69..36ba8bcfe 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2eFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2eFirmwareInfo.java @@ -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)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5FirmwareInfo.java index 4b243b20a..215e779ed 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5FirmwareInfo.java @@ -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)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperationNew.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperationNew.java index 14c1d3b6f..d511312b3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperationNew.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperationNew.java @@ -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],