1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-19 19:40:22 +02:00

Amazfit GTR/S 3: Enable AGPS Updates

This commit is contained in:
José Rebelo 2023-07-25 21:43:58 +01:00
parent 69ae0817cf
commit 606e20a065
5 changed files with 66 additions and 7 deletions

View File

@ -465,6 +465,10 @@ public abstract class Huami2021Coordinator extends HuamiCoordinator {
return false;
}
public boolean sendAgpsAsFileTransfer() {
return true;
}
public boolean supportsGpxUploads() {
return false;
}

View File

@ -61,6 +61,16 @@ public class AmazfitGTR3Coordinator extends Huami2021Coordinator {
return new AmazfitGTR3FWInstallHandler(uri, context);
}
@Override
public boolean supportsAgpsUpdates() {
return true;
}
@Override
public boolean sendAgpsAsFileTransfer() {
return false;
}
@Override
public boolean supportsBluetoothPhoneCalls(final GBDevice device) {
return false;

View File

@ -61,6 +61,16 @@ public class AmazfitGTS3Coordinator extends Huami2021Coordinator {
return new AmazfitGTS3FWInstallHandler(uri, context);
}
@Override
public boolean supportsAgpsUpdates() {
return true;
}
@Override
public boolean sendAgpsAsFileTransfer() {
return false;
}
@Override
public boolean supportsBluetoothPhoneCalls(final GBDevice device) {
return false;

View File

@ -33,6 +33,7 @@ import java.io.IOException;
import java.lang.reflect.Constructor;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@ -84,6 +85,7 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo {
return HuamiFirmwareType.INVALID;
}
final Set<UIHHContainer.FileType> agpsEpoTypes = new HashSet<>();
UIHHContainer.FileEntry uihhFirmwareZipFile = null;
boolean hasChangelog = false;
for (final UIHHContainer.FileEntry file : uihh.getFiles()) {
@ -94,12 +96,18 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo {
case FIRMWARE_CHANGELOG:
hasChangelog = true;
continue;
case AGPS_EPO_GR_3:
case AGPS_EPO_GAL_7:
case AGPS_EPO_BDS_3:
agpsEpoTypes.add(file.getType());
continue;
default:
LOG.warn("Unexpected file for {}", file.getType());
}
}
if (uihhFirmwareZipFile != null && hasChangelog) {
// UIHH firmware update
final ZipFile zipFile = new ZipFile(uihhFirmwareZipFile.getContent());
final byte[] firmwareBin;
try {
@ -114,6 +122,11 @@ public abstract class Huami2021FirmwareInfo extends AbstractHuamiFirmwareInfo {
}
}
if (agpsEpoTypes.size() == 3) {
// AGPS EPO update
return HuamiFirmwareType.AGPS_UIHH;
}
return HuamiFirmwareType.INVALID;
}

View File

@ -94,6 +94,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.Reminder;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
@ -581,13 +582,34 @@ public abstract class Huami2021Support extends HuamiSupport implements ZeppOsFil
final ZeppOsAgpsInstallHandler agpsHandler = new ZeppOsAgpsInstallHandler(uri, getContext());
if (agpsHandler.isValid()) {
try {
new ZeppOsAgpsUpdateOperation(
this,
agpsHandler.getFile(),
agpsService,
fileTransferService,
configService
).perform();
if (getCoordinator().sendAgpsAsFileTransfer()) {
LOG.info("Sending AGPS as file transfer");
new ZeppOsAgpsUpdateOperation(
this,
agpsHandler.getFile(),
agpsService,
fileTransferService,
configService
).perform();
} else {
LOG.info("Sending AGPS as firmware update");
// Write the agps epo update to a temporary file in cache, so we can reuse the firmware update operation
final File cacheDir = getContext().getCacheDir();
final File agpsCacheDir = new File(cacheDir, "zepp-os-agps");
agpsCacheDir.mkdir();
final File uihhFile = new File(agpsCacheDir, "epo-agps.uihh");
try (FileOutputStream outputStream = new FileOutputStream(uihhFile)) {
outputStream.write(agpsHandler.getFile().getUihhBytes());
} catch (final IOException e) {
LOG.error("Failed to write agps bytes to temporary uihhFile", e);
return;
}
new UpdateFirmwareOperation2021(Uri.parse(uihhFile.toURI().toString()), this).perform();
}
} catch (final Exception e) {
GB.toast(getContext(), "AGPS file cannot be installed: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
}