From 0229d24092dcab04bf5755b0a6a47c3cd155ccc6 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 12 Jun 2020 23:24:26 +0200 Subject: [PATCH] Mi Band 4 (possibly others): Fix detected RES version being always 69 for non-whitelisted res files Fixes #1886 --- CHANGELOG.md | 1 + .../service/devices/huami/HuamiFirmwareInfo.java | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d44980882..a19b2bb43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Amazfit Bip S: Support flashing firmware, res, gps firmware, watchfaces, fonts and GPS CEP * Amazfit Bip S: Allow setting high MTU (much faster firmware installation, default off since it does not work for some) * Amazfit Bip S: remove disconnect notification and button action settings (they do not work) +* Mi Band 4 (possibly others): Fix detected RES version being always 69 for non-whitelisted res files * Fossil Hybrid HR: Add last notification widget * Try to fix vanishing incoming call information when VoIP call support is enabled * Allow setting device aliases (useful if you manage multiple ones of the same type) 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 c3c513253..b49ab7d6b 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 @@ -105,7 +105,16 @@ public abstract class HuamiFirmwareInfo { version = "RES " + bytes[5]; break; case RES_COMPRESSED: - version = "RES " + bytes[14]; + byte versionByte; + // there are two possible locations of the version for compressed res, probe the format in a dirty way :P + if (bytes[COMPRESSED_RES_HEADER_OFFSET + 2] == 0x52 && + bytes[COMPRESSED_RES_HEADER_OFFSET + 3] == 0x45 && + bytes[COMPRESSED_RES_HEADER_OFFSET + 4] == 0x53) { + versionByte = bytes[14]; + } else { + versionByte = bytes[18]; + } + version = "RES " + (versionByte & 0xff); break; case FONT: version = "FONT " + bytes[4]; @@ -167,9 +176,7 @@ public abstract class HuamiFirmwareInfo { } /** - * Returns the size of the firmware in number of bytes. - * - * @return + * @return the size of the firmware in number of bytes. */ public int getSize() { return bytes.length;