diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiService.java index 995cdc240..1aa701abd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiService.java @@ -229,6 +229,7 @@ public class HuamiService { public static final byte COMMAND_ACTIVITY_DATA_TYPE_STRESS_AUTOMATIC = 0x13; public static final byte COMMAND_ACTIVITY_DATA_TYPE_SPO2_NORMAL = 0x25; public static final byte COMMAND_ACTIVITY_DATA_TYPE_SPO2_SLEEP = 0x26; + public static final byte COMMAND_ACTIVITY_DATA_TYPE_STATISTICS = 0x2c; public static final byte COMMAND_ACTIVITY_DATA_TYPE_TEMPERATURE = 0x2e; public static final byte COMMAND_ACTIVITY_DATA_TYPE_SLEEP_RESPIRATORY_RATE = 0x38; public static final byte COMMAND_ACTIVITY_DATA_TYPE_RESTING_HEART_RATE = 0x3a; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/RecordedDataTypes.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/RecordedDataTypes.java index 459ab25e4..53b4dec1a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/RecordedDataTypes.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/RecordedDataTypes.java @@ -28,6 +28,7 @@ public class RecordedDataTypes { public static final int TYPE_HEART_RATE = 0x00000080; public static final int TYPE_PAI = 0x00000100; public static final int TYPE_SLEEP_RESPIRATORY_RATE = 0x00000200; + public static final int TYPE_HUAMI_STATISTICS = 0x00000400; public static final int TYPE_ALL = (int)0xffffffff; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index dca37ae70..45732e189 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -122,6 +122,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.model.Alarm; import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.AbstractFetchOperation; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchStatisticsOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchTemperatureOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchHeartRateManualOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchHeartRateMaxOperation; @@ -1705,6 +1706,10 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements } } + if ((dataTypes & RecordedDataTypes.TYPE_HUAMI_STATISTICS) != 0) { + this.fetchOperationQueue.add(new FetchStatisticsOperation(this)); + } + final AbstractFetchOperation nextOperation = this.fetchOperationQueue.poll(); if (nextOperation != null) { try { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchStatisticsOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchStatisticsOperation.java new file mode 100644 index 000000000..1f5720e16 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchStatisticsOperation.java @@ -0,0 +1,68 @@ +/* Copyright (C) 2023 José Rebelo + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ +package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService; +import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; + +/** + * An operation that fetches statistics from /storage/statistics/ (hm_statis_data* files). We do not + * know what these are or how to parse them, but syncing them helps free up memory. + */ +public class FetchStatisticsOperation extends AbstractRepeatingFetchOperation { + private static final Logger LOG = LoggerFactory.getLogger(FetchStatisticsOperation.class); + + public FetchStatisticsOperation(final HuamiSupport support) { + super(support, HuamiService.COMMAND_ACTIVITY_DATA_TYPE_STATISTICS, "statistics data"); + } + + @Override + protected String taskDescription() { + return getContext().getString(R.string.busy_task_fetch_statistics); + } + + @Override + protected boolean handleActivityData(final GregorianCalendar timestamp, final byte[] bytes) { + LOG.debug("Ignoring {} bytes of statistics", bytes.length); + + timestamp.setTime(new Date()); + + return true; + } + + @Override + protected GregorianCalendar getLastSuccessfulSyncTime() { + // One minute ago - we don't really care about this data, and we don't want to fetch it all + final GregorianCalendar sinceWhen = BLETypeConversions.createCalendar(); + sinceWhen.add(Calendar.MINUTE, -1); + return sinceWhen; + } + + @Override + protected String getLastSyncTimeKey() { + return "lastStatisticsTimeMillis"; + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bfd319de3..72e854e5a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -631,6 +631,7 @@ Fetching heart rate data Fetching sleep respiratory rate data Fetching temperature data + Fetching statistics From %1$s to %2$s Wearing left or right? Wearing direction