From 1c93ffc3e5b1ccc5d89477317896da5f044129d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sat, 12 Nov 2022 19:02:57 +0000 Subject: [PATCH] Amazfit GTR 4: Fix and whitelist firmware 3.17.0.2 --- .../devices/huami/Huami2021Coordinator.java | 7 + .../devices/huami/HuamiFWHelper.java | 7 +- .../amazfitband7/AmazfitBand7Coordinator.java | 4 +- .../AmazfitBand7FWInstallHandler.java | 4 +- .../amazfitgtr3/AmazfitGTR3Coordinator.java | 4 +- .../AmazfitGTR3FWInstallHandler.java | 4 +- .../amazfitgtr4/AmazfitGTR4Coordinator.java | 3 +- .../AmazfitGTR4FWInstallHandler.java | 4 +- .../amazfitgts3/AmazfitGTS3Coordinator.java | 4 +- .../AmazfitGTS3FWInstallHandler.java | 4 +- .../amazfitgts4/AmazfitGTS4Coordinator.java | 4 +- .../AmazfitGTS4FWInstallHandler.java | 4 +- .../huami/miband7/MiBand7Coordinator.java | 4 +- .../miband7/MiBand7FWInstallHandler.java | 4 +- .../miband/AbstractMiBandFWHelper.java | 11 +- .../AbstractHuami2021FWInstallHandler.java | 37 ++++ .../huami/AbstractHuamiFirmwareInfo.java | 6 +- .../devices/huami/Huami2021FirmwareInfo.java | 190 +++++++++++------- .../AmazfitBand7FirmwareInfo.java | 5 - .../amazfitgtr3/AmazfitGTR3FirmwareInfo.java | 5 - .../amazfitgtr4/AmazfitGTR4FirmwareInfo.java | 6 +- .../amazfitgts3/AmazfitGTS3FirmwareInfo.java | 5 - .../amazfitgts4/AmazfitGTS4FirmwareInfo.java | 5 - .../huami/miband7/MiBand7FirmwareInfo.java | 5 - .../gadgetbridge/util/ZipFile.java | 22 -- 25 files changed, 206 insertions(+), 152 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuami2021FWInstallHandler.java diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java index 0abd61d80..e722c9c8c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/Huami2021Coordinator.java @@ -16,6 +16,9 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.huami; +import android.content.Context; +import android.net.Uri; + import androidx.annotation.NonNull; import org.apache.commons.lang3.ArrayUtils; @@ -37,11 +40,15 @@ import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.entities.HuamiExtendedActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryParser; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.services.ZeppOsConfigService; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiLanguageType; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiVibrationPatternNotificationType; public abstract class Huami2021Coordinator extends HuamiCoordinator { + @Override + public abstract AbstractHuami2021FWInstallHandler findInstallHandler(final Uri uri, final Context context); + @Override public boolean supportsHeartRateMeasurement(final GBDevice device) { return true; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiFWHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiFWHelper.java index cd8651b84..c089c41ea 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiFWHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiFWHelper.java @@ -28,7 +28,6 @@ import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWHelper; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuamiFirmwareInfo; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType; public abstract class HuamiFWHelper extends AbstractMiBandFWHelper { @@ -124,6 +123,12 @@ public abstract class HuamiFWHelper extends AbstractMiBandFWHelper { return firmwareInfo.getFirmwareType(); } + @Override + public void unsetFwBytes() { + super.unsetFwBytes(); + firmwareInfo.unsetFwBytes(); + } + public AbstractHuamiFirmwareInfo getFirmwareInfo() { return firmwareInfo; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7Coordinator.java index f59aefdc4..be96aa481 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7Coordinator.java @@ -25,11 +25,11 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; public class AmazfitBand7Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitBand7Coordinator.class); @@ -56,7 +56,7 @@ public class AmazfitBand7Coordinator extends Huami2021Coordinator { } @Override - public InstallHandler findInstallHandler(final Uri uri, final Context context) { + public AbstractHuami2021FWInstallHandler findInstallHandler(final Uri uri, final Context context) { final AmazfitBand7FWInstallHandler handler = new AmazfitBand7FWInstallHandler(uri, context); return handler.isValid() ? handler : null; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7FWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7FWInstallHandler.java index 805c7de2a..659164e72 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7FWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband7/AmazfitBand7FWInstallHandler.java @@ -23,11 +23,11 @@ import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWHelper; -import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWInstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; -class AmazfitBand7FWInstallHandler extends AbstractMiBandFWInstallHandler { +class AmazfitBand7FWInstallHandler extends AbstractHuami2021FWInstallHandler { AmazfitBand7FWInstallHandler(final Uri uri, final Context context) { super(uri, context); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3Coordinator.java index f34ea492f..df2b97f3d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3Coordinator.java @@ -25,11 +25,11 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; public class AmazfitGTR3Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTR3Coordinator.class); @@ -56,7 +56,7 @@ public class AmazfitGTR3Coordinator extends Huami2021Coordinator { } @Override - public InstallHandler findInstallHandler(final Uri uri, final Context context) { + public AbstractHuami2021FWInstallHandler findInstallHandler(final Uri uri, final Context context) { final AmazfitGTR3FWInstallHandler handler = new AmazfitGTR3FWInstallHandler(uri, context); return handler.isValid() ? handler : null; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3FWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3FWInstallHandler.java index 97b5b86c0..7220bddcd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3FWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr3/AmazfitGTR3FWInstallHandler.java @@ -23,11 +23,11 @@ import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWHelper; -import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWInstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; -class AmazfitGTR3FWInstallHandler extends AbstractMiBandFWInstallHandler { +class AmazfitGTR3FWInstallHandler extends AbstractHuami2021FWInstallHandler { AmazfitGTR3FWInstallHandler(Uri uri, Context context) { super(uri, context); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4Coordinator.java index 14c9ba1a8..3e08d7372 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4Coordinator.java @@ -30,6 +30,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; public class AmazfitGTR4Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTR4Coordinator.class); @@ -56,7 +57,7 @@ public class AmazfitGTR4Coordinator extends Huami2021Coordinator { } @Override - public InstallHandler findInstallHandler(final Uri uri, final Context context) { + public AbstractHuami2021FWInstallHandler findInstallHandler(final Uri uri, final Context context) { final AmazfitGTR4FWInstallHandler handler = new AmazfitGTR4FWInstallHandler(uri, context); return handler.isValid() ? handler : null; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4FWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4FWInstallHandler.java index f98f681a0..64fcd3fbe 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4FWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgtr4/AmazfitGTR4FWInstallHandler.java @@ -23,11 +23,11 @@ import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWHelper; -import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWInstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; -class AmazfitGTR4FWInstallHandler extends AbstractMiBandFWInstallHandler { +class AmazfitGTR4FWInstallHandler extends AbstractHuami2021FWInstallHandler { AmazfitGTR4FWInstallHandler(final Uri uri, final Context context) { super(uri, context); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3Coordinator.java index a5d5b4c52..d6a34951d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3Coordinator.java @@ -25,11 +25,11 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; public class AmazfitGTS3Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTS3Coordinator.class); @@ -56,7 +56,7 @@ public class AmazfitGTS3Coordinator extends Huami2021Coordinator { } @Override - public InstallHandler findInstallHandler(final Uri uri, final Context context) { + public AbstractHuami2021FWInstallHandler findInstallHandler(final Uri uri, final Context context) { final AmazfitGTS3FWInstallHandler handler = new AmazfitGTS3FWInstallHandler(uri, context); return handler.isValid() ? handler : null; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3FWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3FWInstallHandler.java index cc9e60e76..f9203b700 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3FWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts3/AmazfitGTS3FWInstallHandler.java @@ -23,11 +23,11 @@ import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWHelper; -import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWInstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; -class AmazfitGTS3FWInstallHandler extends AbstractMiBandFWInstallHandler { +class AmazfitGTS3FWInstallHandler extends AbstractHuami2021FWInstallHandler { AmazfitGTS3FWInstallHandler(Uri uri, Context context) { super(uri, context); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4Coordinator.java index cc9e2bd2b..ffc4ca5da 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4Coordinator.java @@ -25,11 +25,11 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; public class AmazfitGTS4Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(AmazfitGTS4Coordinator.class); @@ -56,7 +56,7 @@ public class AmazfitGTS4Coordinator extends Huami2021Coordinator { } @Override - public InstallHandler findInstallHandler(final Uri uri, final Context context) { + public AbstractHuami2021FWInstallHandler findInstallHandler(final Uri uri, final Context context) { final AmazfitGTS4FWInstallHandler handler = new AmazfitGTS4FWInstallHandler(uri, context); return handler.isValid() ? handler : null; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4FWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4FWInstallHandler.java index 2dcb489e8..ccc5d3f58 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4FWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitgts4/AmazfitGTS4FWInstallHandler.java @@ -23,11 +23,11 @@ import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWHelper; -import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWInstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; -class AmazfitGTS4FWInstallHandler extends AbstractMiBandFWInstallHandler { +class AmazfitGTS4FWInstallHandler extends AbstractHuami2021FWInstallHandler { AmazfitGTS4FWInstallHandler(final Uri uri, final Context context) { super(uri, context); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7Coordinator.java index 7c7854862..5726c1d41 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7Coordinator.java @@ -25,11 +25,11 @@ import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; public class MiBand7Coordinator extends Huami2021Coordinator { private static final Logger LOG = LoggerFactory.getLogger(MiBand7Coordinator.class); @@ -56,7 +56,7 @@ public class MiBand7Coordinator extends Huami2021Coordinator { } @Override - public InstallHandler findInstallHandler(final Uri uri, final Context context) { + public AbstractHuami2021FWInstallHandler findInstallHandler(final Uri uri, final Context context) { final MiBand7FWInstallHandler handler = new MiBand7FWInstallHandler(uri, context); return handler.isValid() ? handler : null; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7FWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7FWInstallHandler.java index 465b616c2..7c0c35cae 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7FWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband7/MiBand7FWInstallHandler.java @@ -23,11 +23,11 @@ import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWHelper; -import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWInstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuami2021FWInstallHandler; -class MiBand7FWInstallHandler extends AbstractMiBandFWInstallHandler { +class MiBand7FWInstallHandler extends AbstractHuami2021FWInstallHandler { MiBand7FWInstallHandler(Uri uri, Context context) { super(uri, context); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/AbstractMiBandFWHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/AbstractMiBandFWHelper.java index d3e7a7a8e..a43ad98c1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/AbstractMiBandFWHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/AbstractMiBandFWHelper.java @@ -43,8 +43,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.UriHelper; public abstract class AbstractMiBandFWHelper { private static final Logger LOG = LoggerFactory.getLogger(AbstractMiBandFWHelper.class); - @NonNull - private final byte[] fw; + private byte[] fw; public AbstractMiBandFWHelper(Uri uri, Context context) throws IOException { UriHelper uriHelper = UriHelper.get(uri, context); @@ -104,9 +103,17 @@ public abstract class AbstractMiBandFWHelper { @NonNull public byte[] getFw() { + if (fw == null) { + throw new IllegalStateException("fw is null"); + } + return fw; } + public void unsetFwBytes() { + this.fw = null; + } + public boolean isFirmwareWhitelisted() { for (int wlf : getWhitelistedFirmwareVersions()) { if (wlf == getFirmwareVersion()) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuami2021FWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuami2021FWInstallHandler.java new file mode 100644 index 000000000..f053b643a --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuami2021FWInstallHandler.java @@ -0,0 +1,37 @@ +/* Copyright (C) 2022 José Rebelo + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ +package nodomain.freeyourgadget.gadgetbridge.service.devices.huami; + +import android.content.Context; +import android.net.Uri; + +import nodomain.freeyourgadget.gadgetbridge.devices.miband.AbstractMiBandFWInstallHandler; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; + +public abstract class AbstractHuami2021FWInstallHandler extends AbstractMiBandFWInstallHandler { + public AbstractHuami2021FWInstallHandler(final Uri uri, final Context context) { + super(uri, context); + } + + @Override + public void onStartInstall(GBDevice device) { + // Unset the firmware bytes + // Huami2021 firmwares are large (> 130MB). With the current architecture, the update operation + // will re-read them to memory, and we run out-of-memory. + helper.unsetFwBytes(); + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuamiFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuamiFirmwareInfo.java index 4ccd608e8..96cbf60a1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuamiFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuamiFirmwareInfo.java @@ -26,7 +26,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; import nodomain.freeyourgadget.gadgetbridge.util.CheckSums; public abstract class AbstractHuamiFirmwareInfo { - private final byte[] bytes; + private byte[] bytes; private final int crc16; private final int crc32; @@ -78,6 +78,10 @@ public abstract class AbstractHuamiFirmwareInfo { return firmwareType; } + public void unsetFwBytes() { + this.bytes = null; + } + public abstract String toVersion(int crc16); public abstract boolean isGenerallyCompatibleWith(GBDevice device); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/Huami2021FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/Huami2021FirmwareInfo.java index e0bc3ac75..676eacae3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/Huami2021FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/Huami2021FirmwareInfo.java @@ -28,15 +28,18 @@ import java.util.Arrays; import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; -import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.ZipFile; +import nodomain.freeyourgadget.gadgetbridge.util.ZipFileException; public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { private static final Logger LOG = LoggerFactory.getLogger(Huami2021FirmwareInfo.class); + private final String preComputedVersion; + public Huami2021FirmwareInfo(final byte[] bytes) { super(bytes); + this.preComputedVersion = preComputeVersion(); } /** @@ -44,11 +47,6 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { */ public abstract String deviceName(); - /** - * The expected firmware header bytes, to search on firmware.bin in order to determine compatibility. - */ - public abstract byte[] getExpectedFirmwareHeader(); - @Override protected HuamiFirmwareType determineFirmwareType(final byte[] bytes) { if (ArrayUtils.equals(bytes, UIHHContainer.UIHH_HEADER, 0)) { @@ -70,7 +68,7 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { UIHHContainer.FileEntry uihhFirmwareZipFile = null; boolean hasChangelog = false; for (final UIHHContainer.FileEntry file : uihh.getFiles()) { - switch(file.getType()) { + switch (file.getType()) { case FIRMWARE_ZIP: uihhFirmwareZipFile = file; continue; @@ -83,7 +81,14 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { } if (uihhFirmwareZipFile != null && hasChangelog) { - byte[] firmwareBin = ZipFile.tryReadFileQuick(uihhFirmwareZipFile.getContent(), "META/firmware.bin"); + final ZipFile zipFile = new ZipFile(uihhFirmwareZipFile.getContent()); + final byte[] firmwareBin; + try { + firmwareBin = zipFile.getFileFromZip("META/firmware.bin"); + } catch (final ZipFileException e) { + LOG.error("Failed to read zip from UIHH", e); + return HuamiFirmwareType.INVALID; + } if (isCompatibleFirmwareBin(firmwareBin)) { return HuamiFirmwareType.FIRMWARE_UIHH_2021_ZIP_WITH_CHANGELOG; @@ -94,13 +99,33 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { } private HuamiFirmwareType handleZipPackage(byte[] bytes) { - final byte[] firmwareBin = ZipFile.tryReadFileQuick(bytes, "META/firmware.bin"); + final ZipFile zipFile = new ZipFile(bytes); + final byte[] firmwareBin; + try { + firmwareBin = zipFile.getFileFromZip("META/firmware.bin"); + } catch (final ZipFileException e) { + LOG.error("Failed to get firmware.bin from zip file", e); + return HuamiFirmwareType.FIRMWARE; + } + if (isCompatibleFirmwareBin(firmwareBin)) { return HuamiFirmwareType.FIRMWARE; } - final String appType = getAppType(); - switch(appType) { + final JSONObject appJson = getAppJson(zipFile); + if (appJson == null) { + return HuamiFirmwareType.INVALID; + } + + final String appType; + try { + appType = appJson.getJSONObject("app").getString("appType"); + } catch (final Exception e) { + LOG.error("Failed to get appType from app.json", e); + return HuamiFirmwareType.INVALID; + } + + switch (appType) { case "watchface": return HuamiFirmwareType.WATCHFACE; case "app": @@ -119,27 +144,35 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { return crcMapVersion; } - switch (firmwareType) { - case FIRMWARE_UIHH_2021_ZIP_WITH_CHANGELOG: - final UIHHContainer uihh = UIHHContainer.fromRawBytes(getBytes()); - if (uihh == null) { - return null; - } - return getFirmwareVersion(uihh.getFile(UIHHContainer.FileType.FIRMWARE_ZIP)); - case FIRMWARE: - return getFirmwareVersion(getBytes()); - case WATCHFACE: - final String watchfaceName = getAppName(); - if (watchfaceName == null) { - return "(unknown watchface)"; - } - return String.format("%s (watchface)", watchfaceName); - case APP: - final String appName = getAppName(); - if (appName == null) { - return "(unknown app)"; - } - return String.format("%s (app)", appName); + return preComputedVersion; + } + + public String preComputeVersion() { + try { + switch (firmwareType) { + case FIRMWARE_UIHH_2021_ZIP_WITH_CHANGELOG: + final UIHHContainer uihh = UIHHContainer.fromRawBytes(getBytes()); + if (uihh == null) { + return null; + } + return getFirmwareVersion(uihh.getFile(UIHHContainer.FileType.FIRMWARE_ZIP)); + case FIRMWARE: + return getFirmwareVersion(getBytes()); + case WATCHFACE: + final String watchfaceName = getAppName(new ZipFile(getBytes())); + if (watchfaceName == null) { + return "(unknown watchface)"; + } + return String.format("%s (watchface)", watchfaceName); + case APP: + final String appName = getAppName(new ZipFile(getBytes())); + if (appName == null) { + return "(unknown app)"; + } + return String.format("%s (app)", appName); + } + } catch (final Exception e) { + LOG.error("Failed to pre compute version", e); } return null; @@ -150,7 +183,7 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { throw new IllegalStateException("Can only repack FIRMWARE"); } - final UIHHContainer uihh = packFirmwareInUIHH(); + final UIHHContainer uihh = packFirmwareInUIHH(getBytes()); try { final Constructor constructor = this.getClass().getConstructor(byte[].class); @@ -160,7 +193,7 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { } } - private UIHHContainer packFirmwareInUIHH() { + private static UIHHContainer packFirmwareInUIHH(final byte[] zipBytes) { final UIHHContainer uihh = new UIHHContainer(); final byte[] timestampBytes = BLETypeConversions.fromUint32((int) (System.currentTimeMillis() / 1000L)); final String changelogText = "Unknown changelog"; @@ -168,23 +201,18 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { timestampBytes, changelogText.getBytes(StandardCharsets.UTF_8) ); - uihh.addFile(UIHHContainer.FileType.FIRMWARE_ZIP, getBytes()); + uihh.addFile(UIHHContainer.FileType.FIRMWARE_ZIP, zipBytes); uihh.addFile(UIHHContainer.FileType.FIRMWARE_CHANGELOG, changelogBytes); return uihh; } private boolean isCompatibleFirmwareBin(final byte[] firmwareBin) { if (firmwareBin == null) { + LOG.error("firmware bin is null"); return false; } - if (!ArrayUtils.equals(firmwareBin, getExpectedFirmwareHeader(), 0)) { - LOG.warn("Unexpected firmware header: {}", GB.hexdump(Arrays.copyOfRange(firmwareBin, 0, getExpectedFirmwareHeader().length + 3))); - return false; - } - - // On the MB7, this only works for firmwares > 1.8.5.1, not for any older firmware - if (!searchString32BitAligned(firmwareBin, deviceName() + "\0")) { + if (!searchString(firmwareBin, deviceName())) { LOG.warn("Failed to find {} in fwBytes", deviceName()); return false; } @@ -192,11 +220,13 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { return true; } - public String getFirmwareVersion(final byte[] fwbytes) { - final byte[] firmwareBin = ZipFile.tryReadFileQuick(fwbytes, "META/firmware.bin"); - - if (firmwareBin == null) { - LOG.warn("Failed to read firmware.bin"); + public static String getFirmwareVersion(final byte[] fwBytes) { + final ZipFile zipFile = new ZipFile(fwBytes); + final byte[] firmwareBin; + try { + firmwareBin = zipFile.getFileFromZip("META/firmware.bin"); + } catch (final ZipFileException e) { + LOG.error("Failed to get firmware.bin from zip", e); return null; } @@ -225,10 +255,30 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { return new String(Arrays.copyOfRange(firmwareBin, startIdx, endIdx)); } - public String getAppName() { - final byte[] appJsonBin = ZipFile.tryReadFileQuick(getBytes(), "app.json"); - if (appJsonBin == null) { - LOG.warn("Failed to get app.json from zip"); + public String getAppName(final ZipFile zipFile) { + // TODO check i18n section? + // TODO Show preview icon? + + final JSONObject appJson = getAppJson(zipFile); + if (appJson == null) { + return null; + } + + try { + return appJson.getJSONObject("app").getString("appName"); + } catch (final Exception e) { + LOG.error("Failed to get appName from app.json", e); + } + + return null; + } + + private static JSONObject getAppJson(final ZipFile zipFile) { + final byte[] appJsonBin; + try { + appJsonBin = zipFile.getFileFromZip("app.json"); + } catch (final ZipFileException e) { + LOG.error("Failed to read app.json", e); return null; } @@ -236,12 +286,7 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { final String appJsonString = new String(appJsonBin, StandardCharsets.UTF_8) // Remove UTF-8 BOM if present .replace("\uFEFF", ""); - final JSONObject jsonObject = new JSONObject(appJsonString); - // TODO check i18n section? - // TODO Show preview icon? - final String appName = jsonObject.getJSONObject("app").getString("appName"); - - return String.format("%s", appName); + return new JSONObject(appJsonString); } catch (final Exception e) { LOG.error("Failed to parse app.json", e); } @@ -249,23 +294,22 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { return null; } - public String getAppType() { - final byte[] appJsonBin = ZipFile.tryReadFileQuick(getBytes(), "app.json"); - if (appJsonBin == null) { - LOG.warn("Failed to get app.json from zip"); - return null; + public static boolean searchString(final byte[] fwBytes, final String str) { + final byte[] strBytes = (str + "\0").getBytes(StandardCharsets.UTF_8); + + for (int i = 0; i < fwBytes.length - strBytes.length + 1; i++) { + boolean found = true; + for (int j = 0; j < strBytes.length; j++) { + if (fwBytes[i + j] != strBytes[j]) { + found = false; + break; + } + } + if (found) { + return true; + } } - try { - final String appJsonString = new String(appJsonBin, StandardCharsets.UTF_8) - // Remove UTF-8 BOM if present - .replace("\uFEFF", ""); - final JSONObject jsonObject = new JSONObject(appJsonString); - return jsonObject.getJSONObject("app").getString("appType"); - } catch (final Exception e) { - LOG.error("Failed to parse app.json", e); - } - - return null; + return false; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband7/AmazfitBand7FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband7/AmazfitBand7FirmwareInfo.java index 7e0b40e81..756b51db5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband7/AmazfitBand7FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband7/AmazfitBand7FirmwareInfo.java @@ -37,11 +37,6 @@ public class AmazfitBand7FirmwareInfo extends Huami2021FirmwareInfo { return HuamiConst.AMAZFIT_BAND7_NAME; } - @Override - public byte[] getExpectedFirmwareHeader() { - return new byte[]{0x51, 0x71}; - } - @Override public boolean isGenerallyCompatibleWith(final GBDevice device) { return isHeaderValid() && device.getType() == DeviceType.AMAZFITBAND7; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr3/AmazfitGTR3FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr3/AmazfitGTR3FirmwareInfo.java index 9c3782de2..e1cd6f485 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr3/AmazfitGTR3FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr3/AmazfitGTR3FirmwareInfo.java @@ -43,11 +43,6 @@ public class AmazfitGTR3FirmwareInfo extends Huami2021FirmwareInfo { return HuamiConst.AMAZFIT_GTR3_NAME; } - @Override - public byte[] getExpectedFirmwareHeader() { - return new byte[]{0x00, 0x00, 0x50}; // Probably bogus, only checked against 2 firmware files - } - @Override public boolean isGenerallyCompatibleWith(final GBDevice device) { return isHeaderValid() && device.getType() == DeviceType.AMAZFITGTR3; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr4/AmazfitGTR4FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr4/AmazfitGTR4FirmwareInfo.java index 4bad7f693..a9301de10 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr4/AmazfitGTR4FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgtr4/AmazfitGTR4FirmwareInfo.java @@ -27,6 +27,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.Huami2021Firmw public class AmazfitGTR4FirmwareInfo extends Huami2021FirmwareInfo { private static final Map crcToVersion = new HashMap() {{ // firmware + put(1699, "3.17.0.2"); }}; public AmazfitGTR4FirmwareInfo(final byte[] bytes) { @@ -38,11 +39,6 @@ public class AmazfitGTR4FirmwareInfo extends Huami2021FirmwareInfo { return HuamiConst.AMAZFIT_GTR4_NAME; } - @Override - public byte[] getExpectedFirmwareHeader() { - return new byte[]{(byte) 0x51, (byte) 0x71, (byte) 0x9c}; // Probably bogus, only checked against 1 firmware files - } - @Override public boolean isGenerallyCompatibleWith(final GBDevice device) { return isHeaderValid() && device.getType() == DeviceType.AMAZFITGTR4; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts3/AmazfitGTS3FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts3/AmazfitGTS3FirmwareInfo.java index 3b4a0ff4f..fe9638bce 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts3/AmazfitGTS3FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts3/AmazfitGTS3FirmwareInfo.java @@ -43,11 +43,6 @@ public class AmazfitGTS3FirmwareInfo extends Huami2021FirmwareInfo { return HuamiConst.AMAZFIT_GTS3_NAME; } - @Override - public byte[] getExpectedFirmwareHeader() { - return new byte[]{0x00, 0x00, 0x50}; // Probably bogus, only checked against 2 firmware files - } - @Override public boolean isGenerallyCompatibleWith(final GBDevice device) { return isHeaderValid() && device.getType() == DeviceType.AMAZFITGTS3; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts4/AmazfitGTS4FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts4/AmazfitGTS4FirmwareInfo.java index d4ee2ffa8..1be99de31 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts4/AmazfitGTS4FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts4/AmazfitGTS4FirmwareInfo.java @@ -38,11 +38,6 @@ public class AmazfitGTS4FirmwareInfo extends Huami2021FirmwareInfo { return HuamiConst.AMAZFIT_GTS4_NAME; } - @Override - public byte[] getExpectedFirmwareHeader() { - return new byte[]{(byte) 0x51, (byte) 0x71, (byte) 0x9c}; // Probably bogus, only checked against 1 firmware files - } - @Override public boolean isGenerallyCompatibleWith(final GBDevice device) { return isHeaderValid() && device.getType() == DeviceType.AMAZFITGTS4; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband7/MiBand7FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband7/MiBand7FirmwareInfo.java index ee0398d72..c00250cc6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband7/MiBand7FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband7/MiBand7FirmwareInfo.java @@ -43,11 +43,6 @@ public class MiBand7FirmwareInfo extends Huami2021FirmwareInfo { return HuamiConst.XIAOMI_SMART_BAND7_NAME; } - @Override - public byte[] getExpectedFirmwareHeader() { - return new byte[]{0x51, 0x71}; - } - @Override public boolean isGenerallyCompatibleWith(final GBDevice device) { return isHeaderValid() && device.getType() == DeviceType.MIBAND7; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/ZipFile.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/ZipFile.java index ae24c178e..c17995ec7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/ZipFile.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/ZipFile.java @@ -79,28 +79,6 @@ public class ZipFile { } } - /** - * Tries to obtain file from ZIP file without much hassle, but is not safe.
- * Please only use this in place of old code where correctness of the result is checked only later on.
- * Use getFileFromZip of ZipFile instance instead. - * @param zipBytes - * @param path Path of the file in the ZIP file. - * @return Contents of requested file or null. - */ - @Deprecated - @Nullable - public static byte[] tryReadFileQuick(final byte[] zipBytes, final String path) { - try { - return new ZipFile(zipBytes).getFileFromZip(path); - } catch (ZipFileException e) { - LOG.error("Quick ZIP reading failed.", e); - } catch (Exception e) { - LOG.error("Unable to close ZipFile.", e); - } - - return null; - } - private static byte[] readAllBytes(final InputStream is) throws IOException { final ByteArrayOutputStream buffer = new ByteArrayOutputStream();