1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-08 19:27:04 +01:00

Huawei: Use proper file type for sleep files

This commit is contained in:
Me7c7 2024-08-27 17:44:07 +03:00 committed by José Rebelo
parent 88c8629ec0
commit 9321e470d7
3 changed files with 20 additions and 10 deletions

View File

@ -31,13 +31,16 @@ public class FileDownloadService2C {
public static final int id = 0x2c; public static final int id = 0x2c;
public enum FileType { public enum FileType {
SLEEP, SLEEP_STATE,
SLEEP_DATA,
UNKNOWN; // Never use this as input UNKNOWN; // Never use this as input
static byte fileTypeToByte(FileType fileType) { static byte fileTypeToByte(FileType fileType) {
switch (fileType) { switch (fileType) {
case SLEEP: case SLEEP_STATE:
return (byte) 0x0e; return (byte) 0x0e;
case SLEEP_DATA:
return (byte) 0x0f;
default: default:
throw new RuntimeException(); throw new RuntimeException();
} }
@ -46,7 +49,9 @@ public class FileDownloadService2C {
static FileType byteToFileType(byte b) { static FileType byteToFileType(byte b) {
switch (b) { switch (b) {
case 0x0e: case 0x0e:
return FileType.SLEEP; return FileType.SLEEP_STATE;
case 0x0f:
return FileType.SLEEP_DATA;
default: default:
return FileType.UNKNOWN; return FileType.UNKNOWN;
} }

View File

@ -107,7 +107,8 @@ public class HuaweiFileDownloadManager {
*/ */
public enum FileType { public enum FileType {
DEBUG, DEBUG,
SLEEP, SLEEP_STATE,
SLEEP_DATA,
UNKNOWN // Never for input! UNKNOWN // Never for input!
} }
@ -243,7 +244,7 @@ public class HuaweiFileDownloadManager {
public void downloadSleep(boolean supportsTruSleepNewSync, String filename, int startTime, int endTime) { public void downloadSleep(boolean supportsTruSleepNewSync, String filename, int startTime, int endTime) {
FileRequest request = new FileRequest(); FileRequest request = new FileRequest();
request.filename = filename; request.filename = filename;
request.fileType = FileType.SLEEP; request.fileType = (filename.equals("sleep_state.bin"))?FileType.SLEEP_STATE: FileType.SLEEP_DATA;
request.newSync = supportsTruSleepNewSync; request.newSync = supportsTruSleepNewSync;
request.startTime = startTime; request.startTime = startTime;
request.endTime = endTime; request.endTime = endTime;

View File

@ -53,8 +53,10 @@ public class GetFileDownloadInitRequest extends Request {
private FileDownloadService2C.FileType convertFileTypeTo2C(HuaweiFileDownloadManager.FileType type) { private FileDownloadService2C.FileType convertFileTypeTo2C(HuaweiFileDownloadManager.FileType type) {
switch (type) { switch (type) {
case SLEEP: case SLEEP_STATE:
return FileDownloadService2C.FileType.SLEEP; return FileDownloadService2C.FileType.SLEEP_STATE;
case SLEEP_DATA:
return FileDownloadService2C.FileType.SLEEP_DATA;
default: default:
return FileDownloadService2C.FileType.UNKNOWN; return FileDownloadService2C.FileType.UNKNOWN;
} }
@ -62,8 +64,10 @@ public class GetFileDownloadInitRequest extends Request {
private HuaweiFileDownloadManager.FileType convertFileTypeFrom2C(FileDownloadService2C.FileType type) { private HuaweiFileDownloadManager.FileType convertFileTypeFrom2C(FileDownloadService2C.FileType type) {
switch (type) { switch (type) {
case SLEEP: case SLEEP_STATE:
return HuaweiFileDownloadManager.FileType.SLEEP; return HuaweiFileDownloadManager.FileType.SLEEP_STATE;
case SLEEP_DATA:
return HuaweiFileDownloadManager.FileType.SLEEP_DATA;
default: default:
return HuaweiFileDownloadManager.FileType.UNKNOWN; return HuaweiFileDownloadManager.FileType.UNKNOWN;
} }
@ -80,7 +84,7 @@ public class GetFileDownloadInitRequest extends Request {
} else { } else {
if (this.request.fileType == HuaweiFileDownloadManager.FileType.DEBUG) if (this.request.fileType == HuaweiFileDownloadManager.FileType.DEBUG)
return new FileDownloadService0A.FileDownloadInit.DebugFilesRequest(paramsProvider).serialize(); 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(); return new FileDownloadService0A.FileDownloadInit.SleepFilesRequest(paramsProvider, request.startTime, request.endTime).serialize();
else else
throw new RequestCreationException("Unknown file type"); throw new RequestCreationException("Unknown file type");