2017-03-10 14:53:19 +01:00
|
|
|
/* Copyright (C) 2015-2017 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
|
|
|
Gobbetti
|
|
|
|
|
|
|
|
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/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
|
2015-07-23 17:14:51 +02:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.net.Uri;
|
2016-03-20 01:05:23 +01:00
|
|
|
import android.support.annotation.NonNull;
|
2015-07-23 17:14:51 +02:00
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2015-08-04 23:02:36 +02:00
|
|
|
import java.io.IOException;
|
2015-07-23 17:14:51 +02:00
|
|
|
|
2015-12-07 01:11:07 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2016-03-20 01:05:23 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.AbstractMiFirmwareInfo;
|
2015-08-04 23:02:36 +02:00
|
|
|
|
2016-03-11 01:31:16 +01:00
|
|
|
/**
|
2016-03-20 01:05:23 +01:00
|
|
|
* Also see Mi1SFirmwareInfo.
|
2016-03-11 01:31:16 +01:00
|
|
|
*/
|
2016-12-11 02:10:07 +01:00
|
|
|
public class MiBandFWHelper extends AbstractMiBandFWHelper {
|
2015-07-23 17:14:51 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(MiBandFWHelper.class);
|
|
|
|
|
2016-03-22 16:11:55 +01:00
|
|
|
/**
|
|
|
|
* The backing firmware info instance, which in general supports the provided
|
|
|
|
* given firmware. You must call AbstractMiFirmwareInfo#checkValid() before
|
|
|
|
* attempting to flash it.
|
|
|
|
*/
|
2016-03-22 21:55:15 +01:00
|
|
|
@NonNull
|
2016-12-11 02:10:07 +01:00
|
|
|
private AbstractMiFirmwareInfo firmwareInfo;
|
2015-07-23 17:14:51 +02:00
|
|
|
|
2015-10-22 00:53:27 +02:00
|
|
|
/**
|
|
|
|
* Provides a different notification API which is also used on Mi1A devices.
|
|
|
|
*/
|
|
|
|
public static final int FW_16779790 = 16779790;
|
|
|
|
|
2015-07-23 17:14:51 +02:00
|
|
|
private final int[] whitelistedFirmwareVersion = {
|
2015-07-28 17:30:20 +02:00
|
|
|
16779534, // 1.0.9.14 tested by developer
|
2015-07-28 22:03:53 +02:00
|
|
|
16779547, //1.0.9.27 tested by developer
|
2015-08-30 00:21:51 +02:00
|
|
|
16779568, //1.0.9.48 tested by developer
|
|
|
|
16779585, //1.0.9.65 tested by developer
|
2015-09-17 16:03:15 +02:00
|
|
|
16779779, //1.0.10.3 reported on the wiki
|
2015-12-07 01:22:27 +01:00
|
|
|
16779782, //1.0.10.6 reported on the wiki
|
2015-09-17 16:03:15 +02:00
|
|
|
16779787, //1.0.10.11 tested by developer
|
2015-10-22 00:53:27 +02:00
|
|
|
//FW_16779790, //1.0.10.14 reported on the wiki (vibration does not work currently)
|
2016-08-04 00:05:01 +02:00
|
|
|
68094986, // 4.15.12.10 tested by developer
|
2016-07-08 22:17:19 +02:00
|
|
|
68158215, // 4.16.3.7 tested by developer
|
2016-10-05 23:17:02 +02:00
|
|
|
68158486, // 4.16.4.22 tested by developer and user
|
2015-12-07 01:22:27 +01:00
|
|
|
84870926, // 5.15.7.14 tested by developer
|
2015-07-23 17:14:51 +02:00
|
|
|
};
|
|
|
|
|
2015-08-04 23:02:36 +02:00
|
|
|
public MiBandFWHelper(Uri uri, Context context) throws IOException {
|
2016-12-11 02:10:07 +01:00
|
|
|
super(uri, context);
|
2015-07-23 17:14:51 +02:00
|
|
|
}
|
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
@Override
|
2016-03-20 01:05:23 +01:00
|
|
|
public int getFirmwareVersion() {
|
|
|
|
// FIXME: UnsupportedOperationException!
|
|
|
|
return firmwareInfo.getFirst().getFirmwareVersion();
|
2015-12-07 01:11:07 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
@Override
|
2016-03-20 01:05:23 +01:00
|
|
|
public int getFirmware2Version() {
|
|
|
|
return firmwareInfo.getFirst().getFirmwareVersion();
|
2015-07-23 17:14:51 +02:00
|
|
|
}
|
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
@Override
|
2016-03-11 01:31:16 +01:00
|
|
|
public String getHumanFirmwareVersion2() {
|
2016-03-20 01:05:23 +01:00
|
|
|
return format(firmwareInfo.getSecond().getFirmwareVersion());
|
2016-03-11 01:31:16 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
@Override
|
|
|
|
protected int[] getWhitelistedFirmwareVersions() {
|
|
|
|
return whitelistedFirmwareVersion;
|
2015-07-23 17:14:51 +02:00
|
|
|
}
|
2015-12-07 01:11:07 +01:00
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
@Override
|
2015-12-07 01:11:07 +01:00
|
|
|
public boolean isFirmwareGenerallyCompatibleWith(GBDevice device) {
|
2016-03-20 01:05:23 +01:00
|
|
|
return firmwareInfo.isGenerallyCompatibleWith(device);
|
2015-12-07 01:11:07 +01:00
|
|
|
}
|
2016-03-11 01:31:16 +01:00
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
@Override
|
2016-03-11 01:31:16 +01:00
|
|
|
public boolean isSingleFirmware() {
|
2016-03-20 01:05:23 +01:00
|
|
|
return firmwareInfo.isSingleMiBandFirmware();
|
|
|
|
}
|
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
/**
|
|
|
|
* @param wholeFirmwareBytes
|
|
|
|
* @return
|
|
|
|
* @throws IllegalArgumentException when the data is not recognized as firmware data
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void determineFirmwareInfo(byte[] wholeFirmwareBytes) {
|
|
|
|
firmwareInfo = AbstractMiFirmwareInfo.determineFirmwareInfoFor(wholeFirmwareBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void checkValid() throws IllegalArgumentException {
|
|
|
|
firmwareInfo.checkValid();
|
|
|
|
}
|
|
|
|
|
2016-03-20 01:05:23 +01:00
|
|
|
/**
|
|
|
|
* @param wholeFirmwareBytes
|
|
|
|
* @return
|
|
|
|
* @throws IllegalArgumentException when the data is not recognized as firmware data
|
|
|
|
*/
|
2016-03-20 15:00:05 +01:00
|
|
|
public static
|
|
|
|
@NonNull
|
|
|
|
AbstractMiFirmwareInfo determineFirmwareInfoFor(byte[] wholeFirmwareBytes) {
|
2016-03-20 01:05:23 +01:00
|
|
|
return AbstractMiFirmwareInfo.determineFirmwareInfoFor(wholeFirmwareBytes);
|
|
|
|
}
|
|
|
|
|
2016-03-22 16:11:55 +01:00
|
|
|
/**
|
|
|
|
* The backing firmware info instance, which in general supports the provided
|
|
|
|
* given firmware. You MUST call AbstractMiFirmwareInfo#checkValid() AND
|
|
|
|
* isGenerallyCompatibleWithDevice() before attempting to flash it.
|
|
|
|
*/
|
2016-03-22 21:55:15 +01:00
|
|
|
@NonNull
|
2016-03-20 01:05:23 +01:00
|
|
|
public AbstractMiFirmwareInfo getFirmwareInfo() {
|
|
|
|
return firmwareInfo;
|
2016-03-11 01:31:16 +01:00
|
|
|
}
|
2015-07-28 17:30:20 +02:00
|
|
|
}
|