mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Mi Band 7: Fix and enable firmware upgrades
This commit is contained in:
parent
8af0c074f5
commit
37554e8f8a
@ -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
|
||||
|
@ -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<HuamiSupport> {
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -32,6 +32,7 @@ public class MiBand7FirmwareInfo extends Huami2021FirmwareInfo {
|
||||
|
||||
private static final Map<Integer, String> crcToVersion = new HashMap<Integer, String>() {{
|
||||
// firmware
|
||||
put(26036, "1.20.3.1");
|
||||
}};
|
||||
|
||||
public MiBand7FirmwareInfo(final byte[] bytes) {
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
});
|
||||
|
@ -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 <http://www.gnu.org/licenses/>. */
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user