1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-23 09:07:44 +01:00

Huami: Use activity summary timezone for details fetching (#3592)

It looks like some watches will reply with a fetch timestamp in a
different timezone than the request. When this happens, when we fetch
the activity details, the watch will reply with the details from the
wrong activity.

Use the same timezone in the activity details request as the watch
replies in the activity summary.
This commit is contained in:
José Rebelo 2024-09-06 22:32:32 +01:00
parent 42277fceb9
commit 4bfb7d4621
3 changed files with 20 additions and 7 deletions

View File

@ -196,7 +196,9 @@ public abstract class AbstractFetchOperation extends AbstractHuamiOperation {
buffer.write(value, 1, value.length - 1); // skip the counter
}
protected void startFetching(final TransactionBuilder builder, final byte fetchType, final GregorianCalendar sinceWhen) {
protected void startFetching(final TransactionBuilder builder, final byte fetchType, final Calendar sinceWhen) {
LOG.debug("Requesting {} since {}", getName(), sinceWhen.getTime());
final HuamiSupport support = getSupport();
byte[] fetchBytes = BLETypeConversions.join(new byte[]{
HuamiService.COMMAND_ACTIVITY_DATA_START_DATE,

View File

@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import androidx.annotation.NonNull;
@ -55,17 +56,20 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
private static final Logger LOG = LoggerFactory.getLogger(FetchSportsDetailsOperation.class);
private final AbstractHuamiActivityDetailsParser detailsParser;
private final BaseActivitySummary summary;
private final Calendar summarySyncTime;
private final String lastSyncTimeKey;
FetchSportsDetailsOperation(@NonNull BaseActivitySummary summary,
@NonNull AbstractHuamiActivityDetailsParser detailsParser,
@NonNull HuamiSupport support,
@NonNull Calendar summarySyncTime,
@NonNull String lastSyncTimeKey,
int fetchCount) {
super(support);
setName("fetching sport details");
this.summary = summary;
this.detailsParser = detailsParser;
this.summarySyncTime = summarySyncTime;
this.lastSyncTimeKey = lastSyncTimeKey;
this.fetchCount = fetchCount;
}
@ -77,9 +81,9 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
@Override
protected void startFetching(TransactionBuilder builder) {
LOG.info("start " + getName());
final GregorianCalendar sinceWhen = getLastSuccessfulSyncTime();
startFetching(builder, HuamiFetchDataType.SPORTS_DETAILS.getCode(), sinceWhen);
LOG.info("start {}", getName());
// Use the actual last time, including tz - #3592
startFetching(builder, HuamiFetchDataType.SPORTS_DETAILS.getCode(), summarySyncTime);
}
@Override
@ -191,7 +195,7 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
@Override
protected GregorianCalendar getLastSuccessfulSyncTime() {
final GregorianCalendar calendar = BLETypeConversions.createCalendar();
calendar.setTime(summary.getStartTime());
calendar.setTime(summarySyncTime.getTime());
return calendar;
}

View File

@ -60,7 +60,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
@Override
protected void startFetching(TransactionBuilder builder) {
LOG.info("start" + getName());
LOG.info("start {}", getName());
final GregorianCalendar sinceWhen = getLastSuccessfulSyncTime();
startFetching(builder, HuamiFetchDataType.SPORTS_SUMMARIES.getCode(), sinceWhen);
}
@ -106,7 +106,14 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
}
final AbstractHuamiActivityDetailsParser detailsParser = ((HuamiActivitySummaryParser) summaryParser).getDetailsParser(summary);
final FetchSportsDetailsOperation nextOperation = new FetchSportsDetailsOperation(summary, detailsParser, getSupport(), getLastSyncTimeKey(), fetchCount);
final FetchSportsDetailsOperation nextOperation = new FetchSportsDetailsOperation(
summary,
detailsParser,
getSupport(),
getLastStartTimestamp(), // we need the actual start timestamp, including tz - #3592
getLastSyncTimeKey(),
fetchCount
);
getSupport().getFetchOperationQueue().add(0, nextOperation);
return true;