1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-05 01:37:03 +01:00

Huami: Do not crash when failing to parse activity summary

This commit is contained in:
José Rebelo 2022-10-16 21:29:10 +01:00
parent b5a016a03f
commit a717fd1db2
2 changed files with 13 additions and 3 deletions

View File

@ -12,7 +12,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary; import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
public class ActivitySummaryJsonSummary { public class ActivitySummaryJsonSummary {
@ -73,7 +72,11 @@ public class ActivitySummaryJsonSummary {
private String getCorrectSummary(BaseActivitySummary item){ private String getCorrectSummary(BaseActivitySummary item){
if (item.getRawSummaryData() != null) { if (item.getRawSummaryData() != null) {
item = summaryParser.parseBinaryData(item); try {
item = summaryParser.parseBinaryData(item);
} catch (final Exception e) {
LOG.error("Failed to re-parse corrected summary", e);
}
} }
return item.getSummaryData(); return item.getSummaryData();
} }

View File

@ -93,7 +93,14 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
summary = new BaseActivitySummary(); summary = new BaseActivitySummary();
summary.setStartTime(getLastStartTimestamp().getTime()); // due to a bug this has to be set summary.setStartTime(getLastStartTimestamp().getTime()); // due to a bug this has to be set
summary.setRawSummaryData(buffer.toByteArray()); summary.setRawSummaryData(buffer.toByteArray());
summary = summaryParser.parseBinaryData(summary); try {
summary = summaryParser.parseBinaryData(summary);
} catch (final Exception e) {
GB.toast(getContext(), "Failed to parse activity summary", Toast.LENGTH_LONG, GB.ERROR, e);
summary = null;
parseSummarySuccess = false;
}
if (summary != null) { if (summary != null) {
summary.setSummaryData(null); // remove json before saving to database, summary.setSummaryData(null); // remove json before saving to database,
try (DBHandler dbHandler = GBApplication.acquireDB()) { try (DBHandler dbHandler = GBApplication.acquireDB()) {