From d946053bcbb0978810fa5054c449308f03c6faf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sun, 16 Jun 2024 18:37:07 +0100 Subject: [PATCH] Garmin: Allow fetching unknown files --- .../gadgetbridge/devices/garmin/GarminCoordinator.java | 1 + .../gadgetbridge/service/AbstractDeviceSupport.java | 4 ++-- .../service/devices/garmin/FileTransferHandler.java | 5 +++-- .../gadgetbridge/util/preferences/DevicePrefs.java | 4 ++++ app/src/main/res/values/strings.xml | 2 ++ .../res/xml/devicesettings_fetch_unknown_files.xml | 10 ++++++++++ 6 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/xml/devicesettings_fetch_unknown_files.xml diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminCoordinator.java index 0b6ef7494..ec0cfbdfc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminCoordinator.java @@ -127,6 +127,7 @@ public abstract class GarminCoordinator extends AbstractBLEDeviceCoordinator { final List developer = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.DEVELOPER); developer.add(R.xml.devicesettings_keep_activity_data_on_device); + developer.add(R.xml.devicesettings_fetch_unknown_files); return deviceSpecificSettings; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java index 10c7eeb2f..7502e2bfc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java @@ -776,8 +776,8 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { LocalBroadcastManager.getInstance(context).sendBroadcast(messageIntent); } - public Prefs getDevicePrefs() { - return new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress())); + public DevicePrefs getDevicePrefs() { + return GBApplication.getDevicePrefs(gbDevice.getAddress()); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/FileTransferHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/FileTransferHandler.java index 50fe09c2c..6abb94bb4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/FileTransferHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/FileTransferHandler.java @@ -159,6 +159,7 @@ public class FileTransferHandler implements MessageHandler { throw new IllegalArgumentException("Invalid directory data length"); final GarminByteBufferReader reader = new GarminByteBufferReader(currentlyDownloading.dataHolder.array()); reader.setByteOrder(ByteOrder.LITTLE_ENDIAN); + final boolean fetchUnknownFiles = deviceSupport.getDevicePrefs().getFetchUnknownFiles(); while (reader.remaining() > 0) { final int fileIndex = reader.readShort();//2 final int fileDataType = reader.readByte();//3 @@ -175,7 +176,7 @@ public class FileTransferHandler implements MessageHandler { LOG.warn("Unsupported directory entry of type {}/{}", fileDataType, fileSubType); continue; } - if (!FILE_TYPES_TO_PROCESS.contains(directoryEntry.filetype)) { + if (!FILE_TYPES_TO_PROCESS.contains(directoryEntry.filetype) && !fetchUnknownFiles) { continue; } LOG.debug("Queueing {} for download", directoryEntry); @@ -367,7 +368,7 @@ public class FileTransferHandler implements MessageHandler { public String toString() { return "DirectoryEntry{" + "fileIndex=" + fileIndex + - ", fileType=" + filetype.name() + + ", fileType=" + filetype + ", fileNumber=" + fileNumber + ", specificFlags=" + specificFlags + ", fileFlags=" + fileFlags + diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/DevicePrefs.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/DevicePrefs.java index df76dec38..e21386cfd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/DevicePrefs.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/DevicePrefs.java @@ -31,4 +31,8 @@ public class DevicePrefs extends Prefs { public int getBatteryNotifyFullThreshold(final BatteryConfig batteryConfig) { return getInt(PREF_BATTERY_NOTIFY_FULL_THRESHOLD + batteryConfig.getBatteryIndex(), batteryConfig.getDefaultFullThreshold()); } + + public boolean getFetchUnknownFiles() { + return getBoolean("fetch_unknown_files", false); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9b1e420c5..d9167421e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2922,4 +2922,6 @@ Full battery threshold Default (%1$d%%) %1$s%% + Fetch unknown files + Fetch unknown activity files from the watch. They will not be processed, but will be saved in the phone. diff --git a/app/src/main/res/xml/devicesettings_fetch_unknown_files.xml b/app/src/main/res/xml/devicesettings_fetch_unknown_files.xml new file mode 100644 index 000000000..443c1af62 --- /dev/null +++ b/app/src/main/res/xml/devicesettings_fetch_unknown_files.xml @@ -0,0 +1,10 @@ + + + +