1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-24 01:25:50 +01:00

Xiaomi: Cache firmware version

This commit is contained in:
José Rebelo 2023-10-18 14:07:26 +01:00
parent db57072dd3
commit afaf0baa79
2 changed files with 12 additions and 4 deletions

View File

@ -88,10 +88,6 @@ public class XiaomiEncryptedSupport extends XiaomiSupport {
@Override
protected void startAuthentication(final TransactionBuilder builder) {
// FIXME why is this needed? We get an NPE without it
getDevice().setFirmwareVersion("...");
//getDevice().setFirmwareVersion2("...");
authService.startEncryptedHandshake(builder);
}
}

View File

@ -78,6 +78,8 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
protected final XiaomiSystemService systemService = new XiaomiSystemService(this);
protected final XiaomiCalendarService calendarService = new XiaomiCalendarService(this);
private String mFirmwareVersion = null;
private final Map<Integer, AbstractXiaomiService> mServiceMap = new LinkedHashMap<Integer, AbstractXiaomiService>() {{
put(XiaomiAuthService.COMMAND_TYPE, authService);
put(XiaomiMusicService.COMMAND_TYPE, musicService);
@ -107,6 +109,11 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
final BluetoothGattCharacteristic btCharacteristicActivityData = getCharacteristic(getCharacteristicActivityData());
final BluetoothGattCharacteristic btCharacteristicDataUpload = getCharacteristic(getCharacteristicDataUpload());
// FIXME unsetDynamicState unsets the fw version, which causes problems..
if (getDevice().getFirmwareVersion() == null && mFirmwareVersion != null) {
getDevice().setFirmwareVersion(mFirmwareVersion);
}
if (btCharacteristicCommandRead == null || btCharacteristicCommandWrite == null) {
LOG.warn("Characteristics are null, will attempt to reconnect");
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.WAITING_FOR_RECONNECT, getContext()));
@ -150,6 +157,11 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
@Override
public void setContext(final GBDevice gbDevice, final BluetoothAdapter btAdapter, final Context context) {
// FIXME unsetDynamicState unsets the fw version, which causes problems..
if (mFirmwareVersion == null && gbDevice.getFirmwareVersion() != null) {
mFirmwareVersion = gbDevice.getFirmwareVersion();
}
super.setContext(gbDevice, btAdapter, context);
for (final AbstractXiaomiService service : mServiceMap.values()) {
service.setContext(context);