From 3902db5abd4658377b9aec984b62c49c1ec4a467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sun, 25 Feb 2024 13:25:12 +0000 Subject: [PATCH] Huami: Keep track of last debug logs titmestamp --- .../fetch/FetchDebugLogsOperation.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/fetch/FetchDebugLogsOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/fetch/FetchDebugLogsOperation.java index c03e49fa6..3d13d6fa3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/fetch/FetchDebugLogsOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/fetch/FetchDebugLogsOperation.java @@ -16,7 +16,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.fetch; -import android.widget.Toast; +import androidx.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,15 +25,11 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; -import androidx.annotation.NonNull; - import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; @@ -43,7 +39,7 @@ public class FetchDebugLogsOperation extends AbstractFetchOperation { private FileOutputStream logOutputStream; - public FetchDebugLogsOperation(HuamiSupport support) { + public FetchDebugLogsOperation(final HuamiSupport support) { super(support); setName("fetch debug logs"); } @@ -54,7 +50,7 @@ public class FetchDebugLogsOperation extends AbstractFetchOperation { } @Override - protected void startFetching(TransactionBuilder builder) { + protected void startFetching(final TransactionBuilder builder) { File dir; try { dir = FileUtils.getExternalFilesDir(); @@ -62,19 +58,17 @@ public class FetchDebugLogsOperation extends AbstractFetchOperation { return; } - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.US); - String filename = "huamidebug_" + dateFormat.format(new Date()) + ".log"; + final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.US); + final String filename = "huamidebug_" + dateFormat.format(new Date()) + ".log"; - File outputFile = new File(dir, filename ); + File outputFile = new File(dir, filename); try { logOutputStream = new FileOutputStream(outputFile); } catch (IOException e) { LOG.warn("could not create file " + outputFile, e); return; } - - GregorianCalendar sinceWhen = BLETypeConversions.createCalendar(); - sinceWhen.add(Calendar.DAY_OF_MONTH, -10); + final GregorianCalendar sinceWhen = getLastSuccessfulSyncTime(); startFetching(builder, HuamiFetchDataType.DEBUG_LOGS.getCode(), sinceWhen); } @@ -89,8 +83,8 @@ public class FetchDebugLogsOperation extends AbstractFetchOperation { try { logOutputStream.close(); logOutputStream = null; - } catch (IOException e) { - LOG.warn("could not close output stream", e); + } catch (final IOException e) { + LOG.error("could not close output stream", e); return false; } @@ -109,8 +103,7 @@ public class FetchDebugLogsOperation extends AbstractFetchOperation { try { logOutputStream.write(value, 1, value.length - 1); } catch (final IOException e) { - LOG.warn("could not write to output stream", e); - operationValid = false; + LOG.error("could not write to output stream", e); } } }