From 9321e470d7dc2131263028b154288d88198e8140 Mon Sep 17 00:00:00 2001 From: Me7c7 Date: Tue, 27 Aug 2024 17:44:07 +0300 Subject: [PATCH] Huawei: Use proper file type for sleep files --- .../huawei/packets/FileDownloadService2C.java | 11 ++++++++--- .../devices/huawei/HuaweiFileDownloadManager.java | 5 +++-- .../requests/GetFileDownloadInitRequest.java | 14 +++++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/FileDownloadService2C.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/FileDownloadService2C.java index dba51c29f..07f651444 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/FileDownloadService2C.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/FileDownloadService2C.java @@ -31,13 +31,16 @@ public class FileDownloadService2C { public static final int id = 0x2c; public enum FileType { - SLEEP, + SLEEP_STATE, + SLEEP_DATA, UNKNOWN; // Never use this as input static byte fileTypeToByte(FileType fileType) { switch (fileType) { - case SLEEP: + case SLEEP_STATE: return (byte) 0x0e; + case SLEEP_DATA: + return (byte) 0x0f; default: throw new RuntimeException(); } @@ -46,7 +49,9 @@ public class FileDownloadService2C { static FileType byteToFileType(byte b) { switch (b) { case 0x0e: - return FileType.SLEEP; + return FileType.SLEEP_STATE; + case 0x0f: + return FileType.SLEEP_DATA; default: return FileType.UNKNOWN; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiFileDownloadManager.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiFileDownloadManager.java index d3146aa90..da8716bb7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiFileDownloadManager.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiFileDownloadManager.java @@ -107,7 +107,8 @@ public class HuaweiFileDownloadManager { */ public enum FileType { DEBUG, - SLEEP, + SLEEP_STATE, + SLEEP_DATA, UNKNOWN // Never for input! } @@ -243,7 +244,7 @@ public class HuaweiFileDownloadManager { public void downloadSleep(boolean supportsTruSleepNewSync, String filename, int startTime, int endTime) { FileRequest request = new FileRequest(); request.filename = filename; - request.fileType = FileType.SLEEP; + request.fileType = (filename.equals("sleep_state.bin"))?FileType.SLEEP_STATE: FileType.SLEEP_DATA; request.newSync = supportsTruSleepNewSync; request.startTime = startTime; request.endTime = endTime; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetFileDownloadInitRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetFileDownloadInitRequest.java index 9009acf5d..ebe80c53a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetFileDownloadInitRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetFileDownloadInitRequest.java @@ -53,8 +53,10 @@ public class GetFileDownloadInitRequest extends Request { private FileDownloadService2C.FileType convertFileTypeTo2C(HuaweiFileDownloadManager.FileType type) { switch (type) { - case SLEEP: - return FileDownloadService2C.FileType.SLEEP; + case SLEEP_STATE: + return FileDownloadService2C.FileType.SLEEP_STATE; + case SLEEP_DATA: + return FileDownloadService2C.FileType.SLEEP_DATA; default: return FileDownloadService2C.FileType.UNKNOWN; } @@ -62,8 +64,10 @@ public class GetFileDownloadInitRequest extends Request { private HuaweiFileDownloadManager.FileType convertFileTypeFrom2C(FileDownloadService2C.FileType type) { switch (type) { - case SLEEP: - return HuaweiFileDownloadManager.FileType.SLEEP; + case SLEEP_STATE: + return HuaweiFileDownloadManager.FileType.SLEEP_STATE; + case SLEEP_DATA: + return HuaweiFileDownloadManager.FileType.SLEEP_DATA; default: return HuaweiFileDownloadManager.FileType.UNKNOWN; } @@ -80,7 +84,7 @@ public class GetFileDownloadInitRequest extends Request { } else { if (this.request.fileType == HuaweiFileDownloadManager.FileType.DEBUG) return new FileDownloadService0A.FileDownloadInit.DebugFilesRequest(paramsProvider).serialize(); - else if (this.request.fileType == HuaweiFileDownloadManager.FileType.SLEEP) + else if (this.request.fileType == HuaweiFileDownloadManager.FileType.SLEEP_STATE) return new FileDownloadService0A.FileDownloadInit.SleepFilesRequest(paramsProvider, request.startTime, request.endTime).serialize(); else throw new RequestCreationException("Unknown file type");