mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-29 18:45:17 +02:00
Mi Band 4: WIP firmware update preparation
Nothing works yet
This commit is contained in:
parent
9042966a40
commit
044f6c11cd
@ -0,0 +1,40 @@
|
|||||||
|
/* Copyright (C) 2017-2019 Andreas Shimokawa, Carsten Pfeiffer
|
||||||
|
|
||||||
|
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.devices.huami.miband4;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband4.MiBand4FirmwareInfo;
|
||||||
|
|
||||||
|
public class MiBand4FWHelper extends HuamiFWHelper {
|
||||||
|
|
||||||
|
public MiBand4FWHelper(Uri uri, Context context) throws IOException {
|
||||||
|
super(uri, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void determineFirmwareInfo(byte[] wholeFirmwareBytes) {
|
||||||
|
firmwareInfo = new MiBand4FirmwareInfo(wholeFirmwareBytes);
|
||||||
|
if (!firmwareInfo.isHeaderValid()) {
|
||||||
|
throw new IllegalArgumentException("Not a Mi Band 4 firmware");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/* Copyright (C) 2015-2019 Andreas Shimokawa, Carsten Pfeiffer
|
||||||
|
|
||||||
|
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.devices.huami.miband4;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3FWHelper;
|
||||||
|
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;
|
||||||
|
|
||||||
|
class MiBand4FWInstallHandler extends AbstractMiBandFWInstallHandler {
|
||||||
|
MiBand4FWInstallHandler(Uri uri, Context context) {
|
||||||
|
super(uri, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getFwUpgradeNotice() {
|
||||||
|
return mContext.getString(R.string.fw_upgrade_notice_miband4, helper.getHumanFirmwareVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AbstractMiBandFWHelper createHelper(Uri uri, Context context) throws IOException {
|
||||||
|
return new MiBand4FWHelper(uri, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isSupportedDeviceType(GBDevice device) {
|
||||||
|
return device.getType() == DeviceType.MIBAND4;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
/* Copyright (C) 2017-2019 Andreas Shimokawa, Carsten Pfeiffer
|
||||||
|
|
||||||
|
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.miband4;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
|
||||||
|
|
||||||
|
public class MiBand4FirmwareInfo extends HuamiFirmwareInfo {
|
||||||
|
|
||||||
|
private static final byte[] FW_HEADER = new byte[]{
|
||||||
|
0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x9c, (byte) 0xe3, 0x7d, 0x5c, 0x00, 0x04
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final int FW_HEADER_OFFSET = 16;
|
||||||
|
|
||||||
|
private static Map<Integer, String> crcToVersion = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
// firmware
|
||||||
|
crcToVersion.put(8969, "1.0.5.22");
|
||||||
|
|
||||||
|
// resources
|
||||||
|
crcToVersion.put(27412, "1.0.5.22");
|
||||||
|
|
||||||
|
// font
|
||||||
|
crcToVersion.put(31978, "1");
|
||||||
|
}
|
||||||
|
|
||||||
|
public MiBand4FirmwareInfo(byte[] bytes) {
|
||||||
|
super(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HuamiFirmwareType determineFirmwareType(byte[] bytes) {
|
||||||
|
if (ArrayUtils.equals(bytes, RES_HEADER, COMPRESSED_RES_HEADER_OFFSET) || ArrayUtils.equals(bytes, NEWRES_HEADER, COMPRESSED_RES_HEADER_OFFSET_NEW) || ArrayUtils.equals(bytes, NEWRES_HEADER, COMPRESSED_RES_HEADER_OFFSET)) {
|
||||||
|
return HuamiFirmwareType.RES_COMPRESSED;
|
||||||
|
}
|
||||||
|
if (ArrayUtils.equals(bytes, FW_HEADER, FW_HEADER_OFFSET)) {
|
||||||
|
if (searchString32BitAligned(bytes, "Mi Smart Band 4")) {
|
||||||
|
return HuamiFirmwareType.FIRMWARE;
|
||||||
|
}
|
||||||
|
return HuamiFirmwareType.INVALID;
|
||||||
|
}
|
||||||
|
if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER)) {
|
||||||
|
return HuamiFirmwareType.WATCHFACE;
|
||||||
|
}
|
||||||
|
if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) {
|
||||||
|
if (bytes[10] == 0x03) {
|
||||||
|
return HuamiFirmwareType.FONT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// somebody might have unpacked the compressed res
|
||||||
|
if (ArrayUtils.startsWith(bytes, RES_HEADER)) {
|
||||||
|
return HuamiFirmwareType.RES;
|
||||||
|
}
|
||||||
|
return HuamiFirmwareType.INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGenerallyCompatibleWith(GBDevice device) {
|
||||||
|
return isHeaderValid() && device.getType() == DeviceType.MIBAND4;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<Integer, String> getCrcMap() {
|
||||||
|
return crcToVersion;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user