Garmin: Fix activity fetch getting stuck on error

If fetch unknown files was enabled, an INDEX_UNKNOWN might sometimes be
received for some of the files, which would make the activity fetch get
stuck as we do not check the isDownloading() state anymore.
This commit is contained in:
José Rebelo
2025-08-12 11:01:32 +01:00
parent 00d3e9b23d
commit 2339242c33
3 changed files with 15 additions and 1 deletions
@@ -141,8 +141,14 @@ public CreateFileMessage initiateUpload(byte[] fileAsByteArray, FileType.FILETYP
throw new IllegalStateException("Received file transfer of unknown file");
if (downloadRequestStatusMessage.canProceed())
currentlyDownloading.setSize(downloadRequestStatusMessage);
else
else {
// Signal to the support class that the download failed so it can also continue to the next one
FileDownloadedDeviceEvent fileDownloadedDeviceEvent = new FileDownloadedDeviceEvent();
fileDownloadedDeviceEvent.directoryEntry = currentlyDownloading.directoryEntry;
fileDownloadedDeviceEvent.success = false;
deviceSupport.evaluateGBDeviceEvent(fileDownloadedDeviceEvent);
currentlyDownloading = null;
}
}
private void saveFileToExternalStorage() {
@@ -383,6 +383,13 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
this.supportedFileTypeList.addAll(((SupportedFileTypesDeviceEvent) deviceEvent).getSupportedFileTypes());
} else if (deviceEvent instanceof FileDownloadedDeviceEvent fileDownloadedDeviceEvent) {
final FileTransferHandler.DirectoryEntry entry = fileDownloadedDeviceEvent.directoryEntry;
if (!fileDownloadedDeviceEvent.success) {
LOG.warn("FILE DOWNLOAD FAILED");
// Continue to the next one
currentlyDownloading = null;
return;
}
if (entry != null) {
final String filename = entry.getFileName();
LOG.debug("FILE DOWNLOAD COMPLETE {}", filename);
@@ -7,6 +7,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.FileTransferHandler;
public class FileDownloadedDeviceEvent extends GBDeviceEvent {
public boolean success = true;
public FileTransferHandler.DirectoryEntry directoryEntry;
public String localPath;