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 38e781711..3f02c709f 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 @@ -54,7 +54,7 @@ public abstract class AbstractMiBandFWHelper { } try (InputStream in = new BufferedInputStream(uriHelper.openInputStream())) { - this.fw = FileUtils.readAll(in, 1024 * 1024 * 16); // 16.0 MB + this.fw = FileUtils.readAll(in, 1024 * 1024 * 32); // 32.0 MB determineFirmwareInfo(fw); } catch (IOException ex) { throw ex; // pass through diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuamiOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuamiOperation.java index 7f74c8298..12fea4ad0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuamiOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/AbstractHuamiOperation.java @@ -17,7 +17,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.AbstractMiBandOperation; public abstract class AbstractHuamiOperation extends AbstractMiBandOperation { 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 6104a40ef..67c16c10a 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 @@ -27,8 +27,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -81,7 +79,7 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { final byte[] firmwareBin = getFileFromZip(uihhFirmwareZipFile.getContent(), "META/firmware.bin"); if (isCompatibleFirmwareBin(firmwareBin)) { - // TODO: Firmware upgrades are untested, so they are disabled + // TODO: Firmware upgrades with UIHH files are untested, so they are disabled return HuamiFirmwareType.INVALID; //return HuamiFirmwareType.FIRMWARE_UIHH_2021_ZIP_WITH_CHANGELOG; } @@ -96,9 +94,7 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo { final byte[] firmwareBin = getFileFromZip(bytes, "META/firmware.bin"); if (isCompatibleFirmwareBin(firmwareBin)) { - // TODO: Firmware upgrades are untested, so they are disabled - return HuamiFirmwareType.INVALID; - //return HuamiFirmwareType.FIRMWARE; + return HuamiFirmwareType.FIRMWARE; } final String appType = getAppType(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/Huami2021Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/Huami2021Support.java index b22e2f455..de702976c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/Huami2021Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/Huami2021Support.java @@ -148,7 +148,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.Fet import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.HuamiFetchDebugLogsOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation2020; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation2021; import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils; import nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil; import nodomain.freeyourgadget.gadgetbridge.util.CheckSums; @@ -1745,7 +1745,7 @@ public abstract class Huami2021Support extends HuamiSupport { @Override public UpdateFirmwareOperation createUpdateFirmwareOperation(final Uri uri) { - return new UpdateFirmwareOperation2020(uri, this); + return new UpdateFirmwareOperation2021(uri, this); } @Override 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 6f351e8c5..46eef5aac 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 @@ -32,6 +32,7 @@ public class MiBand7FirmwareInfo extends Huami2021FirmwareInfo { private static final Map crcToVersion = new HashMap() {{ // firmware + put(26036, "1.20.3.1"); }}; public MiBand7FirmwareInfo(final byte[] bytes) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation.java index 73cf1845d..492263b02 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation.java @@ -41,7 +41,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAc import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuamiFirmwareInfo; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuamiOperation; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; import nodomain.freeyourgadget.gadgetbridge.util.GB; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation2020.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation2020.java index cfb2fcdce..33de2c0ef 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation2020.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation2020.java @@ -32,7 +32,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuamiFirmwareInfo; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; @@ -47,15 +46,15 @@ public class UpdateFirmwareOperation2020 extends UpdateFirmwareOperation { super(uri, support); } - private final byte COMMAND_REQUEST_PARAMETERS = (byte) 0xd0; - private final byte COMMAND_UNKNOWN_D1 = (byte) 0xd1; - private final byte COMMAND_SEND_FIRMWARE_INFO = (byte) 0xd2; - private final byte COMMAND_START_TRANSFER = (byte) 0xd3; - private final byte REPLY_UPDATE_PROGRESS = (byte) 0xd4; - private final byte COMMAND_COMPLETE_TRANSFER = (byte) 0xd5; - private final byte COMMAND_FINALIZE_UPDATE = (byte) 0xd6; + public static final byte COMMAND_REQUEST_PARAMETERS = (byte) 0xd0; + public static final byte COMMAND_UNKNOWN_D1 = (byte) 0xd1; + public static final byte COMMAND_SEND_FIRMWARE_INFO = (byte) 0xd2; + public static final byte COMMAND_START_TRANSFER = (byte) 0xd3; + public static final byte REPLY_UPDATE_PROGRESS = (byte) 0xd4; + public static final byte COMMAND_COMPLETE_TRANSFER = (byte) 0xd5; + public static final byte COMMAND_FINALIZE_UPDATE = (byte) 0xd6; - private int mChunkLength = -1; + protected int mChunkLength = -1; @Override protected void doPerform() throws IOException { @@ -266,7 +265,7 @@ public class UpdateFirmwareOperation2020 extends UpdateFirmwareOperation { protected void sendTransferStart() throws IOException { - TransactionBuilder builder = performInitialized("trasfer complete"); + TransactionBuilder builder = performInitialized("transfer complete"); builder.write(fwCControlChar, new byte[]{ COMMAND_START_TRANSFER, 1, }); @@ -274,7 +273,7 @@ public class UpdateFirmwareOperation2020 extends UpdateFirmwareOperation { } protected void sendTransferComplete() throws IOException { - TransactionBuilder builder = performInitialized("trasfer complete"); + TransactionBuilder builder = performInitialized("transfer complete"); builder.write(fwCControlChar, new byte[]{ COMMAND_COMPLETE_TRANSFER, }); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation2021.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation2021.java new file mode 100644 index 000000000..3fa73efb6 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperation2021.java @@ -0,0 +1,40 @@ +/* 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.operations; + +import android.net.Uri; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService; +import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; + +public class UpdateFirmwareOperation2021 extends UpdateFirmwareOperation2020 { + private static final Logger LOG = LoggerFactory.getLogger(UpdateFirmwareOperation2021.class); + + public UpdateFirmwareOperation2021(final Uri uri, final HuamiSupport support) { + super(uri, support); + } + + @Override + protected void enableOtherNotifications(final TransactionBuilder builder, final boolean enable) { + // Disable 2021 chunked reads, otherwise firmware upgrades get interrupted + builder.notify(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_CHUNKEDTRANSFER_2021_READ), enable); + } +}