1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-13 11:17:33 +01:00

Huami: Allow activity fetch timestamps to be sent in seconds

This commit is contained in:
José Rebelo 2022-11-06 12:13:33 +00:00 committed by Gitea
parent 2216b6b76a
commit 2a47dc863a
30 changed files with 45 additions and 45 deletions

View File

@ -120,6 +120,7 @@ public class AmazfitBand5Coordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -95,6 +95,7 @@ public class AmazfitBipCoordinator extends HuamiCoordinator {
R.xml.devicesettings_buttonactions_with_longpress, R.xml.devicesettings_buttonactions_with_longpress,
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -85,6 +85,7 @@ public class AmazfitBipLiteCoordinator extends AmazfitBipCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_relax_firmware_checks, R.xml.devicesettings_relax_firmware_checks,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -111,6 +111,7 @@ public class AmazfitBipSCoordinator extends HuamiCoordinator {
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -126,6 +126,7 @@ public class AmazfitBipUCoordinator extends HuamiCoordinator {
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -123,6 +123,7 @@ public class AmazfitBipUProCoordinator extends HuamiCoordinator {
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -103,6 +103,7 @@ public class AmazfitCorCoordinator extends HuamiCoordinator {
R.xml.devicesettings_bt_connected_advertisement, R.xml.devicesettings_bt_connected_advertisement,
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -105,6 +105,7 @@ public class AmazfitCor2Coordinator extends HuamiCoordinator {
R.xml.devicesettings_bt_connected_advertisement, R.xml.devicesettings_bt_connected_advertisement,
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -105,6 +105,7 @@ public class AmazfitGTRCoordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -103,6 +103,7 @@ public class AmazfitGTRLiteCoordinator extends HuamiCoordinator {
R.xml.devicesettings_expose_hr_thirdparty, R.xml.devicesettings_expose_hr_thirdparty,
R.xml.devicesettings_bt_connected_advertisement, R.xml.devicesettings_bt_connected_advertisement,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -110,6 +110,7 @@ public class AmazfitGTR2Coordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -110,6 +110,7 @@ public class AmazfitGTR2eCoordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -104,6 +104,7 @@ public class AmazfitGTSCoordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -110,6 +110,7 @@ public class AmazfitGTS2Coordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -79,6 +79,7 @@ public class AmazfitGTS2MiniCoordinator extends AmazfitGTS2Coordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -110,6 +110,7 @@ public class AmazfitGTS2eCoordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -109,6 +109,7 @@ public class AmazfitNeoCoordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -104,6 +104,7 @@ public class AmazfitTRexCoordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -104,6 +104,7 @@ public class AmazfitTRexProCoordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -104,6 +104,7 @@ public class AmazfitVergeLCoordinator extends HuamiCoordinator {
R.xml.devicesettings_bt_connected_advertisement, R.xml.devicesettings_bt_connected_advertisement,
R.xml.devicesettings_buttonactions_with_longpress, R.xml.devicesettings_buttonactions_with_longpress,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -110,6 +110,7 @@ public class AmazfitXCoordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -95,6 +95,7 @@ public class MiBand2Coordinator extends HuamiCoordinator {
R.xml.devicesettings_reserve_alarms_calendar, R.xml.devicesettings_reserve_alarms_calendar,
R.xml.devicesettings_bt_connected_advertisement, R.xml.devicesettings_bt_connected_advertisement,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -97,6 +97,7 @@ public class MiBand2HRXCoordinator extends HuamiCoordinator {
R.xml.devicesettings_inactivity_dnd, R.xml.devicesettings_inactivity_dnd,
R.xml.devicesettings_rotatewrist_cycleinfo, R.xml.devicesettings_rotatewrist_cycleinfo,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -119,6 +119,7 @@ public class MiBand3Coordinator extends HuamiCoordinator {
R.xml.devicesettings_bt_connected_advertisement, R.xml.devicesettings_bt_connected_advertisement,
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -115,6 +115,7 @@ public class MiBand4Coordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -129,6 +129,7 @@ public class MiBand5Coordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -110,6 +110,7 @@ public class MiBand6Coordinator extends HuamiCoordinator {
R.xml.devicesettings_expose_hr_thirdparty, R.xml.devicesettings_expose_hr_thirdparty,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -103,6 +103,7 @@ public class ZeppECoordinator extends HuamiCoordinator {
R.xml.devicesettings_device_actions, R.xml.devicesettings_device_actions,
R.xml.devicesettings_high_mtu, R.xml.devicesettings_high_mtu,
R.xml.devicesettings_overwrite_settings_on_connection, R.xml.devicesettings_overwrite_settings_on_connection,
R.xml.devicesettings_huami2021_fetch_operation_time_unit,
R.xml.devicesettings_transliteration R.xml.devicesettings_transliteration
}; };
} }

View File

@ -910,18 +910,6 @@ public abstract class Huami2021Support extends HuamiSupport {
return this; return this;
} }
@Override
public byte[] getTimeBytes(final Calendar calendar, final TimeUnit precision) {
final byte[] bytes = BLETypeConversions.shortCalendarToRawBytes(calendar);
if (precision != TimeUnit.MINUTES && precision != TimeUnit.SECONDS) {
throw new IllegalArgumentException("Unsupported precision, only MINUTES and SECONDS are supported");
}
final byte seconds = precision == TimeUnit.SECONDS ? fromUint8(calendar.get(Calendar.SECOND)) : 0;
final byte tz = BLETypeConversions.mapTimeZone(calendar, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ);
return BLETypeConversions.join(bytes, new byte[]{seconds, tz});
}
@Override @Override
public Huami2021Support setCurrentTimeWithService(TransactionBuilder builder) { public Huami2021Support setCurrentTimeWithService(TransactionBuilder builder) {
// It seems that the format sent to the Current Time characteristic changed in newer devices // It seems that the format sent to the Current Time characteristic changed in newer devices
@ -1398,15 +1386,6 @@ public abstract class Huami2021Support extends HuamiSupport {
return 8; return 8;
} }
@Override
public TimeUnit getFetchOperationsTimeUnit() {
// This is configurable because using seconds was causing issues on Amazfit GTR 3
// However, using minutes can cause issues while fetching workouts shorter than 1 minute
final Prefs devicePrefs = getDevicePrefs();
final boolean truncate = devicePrefs.getBoolean("huami_truncate_fetch_operation_timestamps", true);
return truncate ? TimeUnit.MINUTES : TimeUnit.SECONDS;
}
@Override @Override
public boolean force2021Protocol() { public boolean force2021Protocol() {
return true; return true;

View File

@ -275,6 +275,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_NAME; import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_NAME;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_WEIGHT_KG; import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_WEIGHT_KG;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_YEAR_OF_BIRTH; import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_YEAR_OF_BIRTH;
import static nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions.fromUint8;
import static nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL; import static nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL;
public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements Huami2021Handler { public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements Huami2021Handler {
@ -402,29 +403,15 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
return weatherSpec.windSpeedAsBeaufort() + ""; // cast to string return weatherSpec.windSpeedAsBeaufort() + ""; // cast to string
} }
/** public byte[] getTimeBytes(final Calendar calendar, final TimeUnit precision) {
* Returns the given date/time (calendar) as a byte sequence, suitable for sending to the final byte[] bytes = BLETypeConversions.shortCalendarToRawBytes(calendar);
* Mi Band 2 (or derivative). The band appears to not handle DST offsets, so we simply add this
* to the timezone. if (precision != TimeUnit.MINUTES && precision != TimeUnit.SECONDS) {
* throw new IllegalArgumentException("Unsupported precision, only MINUTES and SECONDS are supported");
* @param calendar
* @param precision
* @return
*/
public byte[] getTimeBytes(Calendar calendar, TimeUnit precision) {
byte[] bytes;
if (precision == TimeUnit.MINUTES) {
bytes = BLETypeConversions.shortCalendarToRawBytes(calendar);
} else if (precision == TimeUnit.SECONDS) {
bytes = BLETypeConversions.calendarToRawBytes(calendar);
} else {
throw new IllegalArgumentException("Unsupported precision, only MINUTES and SECONDS are supported till now");
} }
byte[] tail = new byte[] { 0, BLETypeConversions.mapTimeZone(calendar, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ) }; final byte seconds = precision == TimeUnit.SECONDS ? fromUint8(calendar.get(Calendar.SECOND)) : 0;
// 0 = adjust reason bitflags? or DST offset?? , timezone final byte tz = BLETypeConversions.mapTimeZone(calendar, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ);
// byte[] tail = new byte[] { 0x2 }; // reason return BLETypeConversions.join(bytes, new byte[]{seconds, tz});
byte[] all = BLETypeConversions.join(bytes, tail);
return all;
} }
public Calendar fromTimeBytes(byte[] bytes) { public Calendar fromTimeBytes(byte[] bytes) {
@ -434,7 +421,9 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
public HuamiSupport setCurrentTimeWithService(TransactionBuilder builder) { public HuamiSupport setCurrentTimeWithService(TransactionBuilder builder) {
GregorianCalendar now = BLETypeConversions.createCalendar(); GregorianCalendar now = BLETypeConversions.createCalendar();
byte[] bytes = getTimeBytes(now, TimeUnit.SECONDS); byte[] head = BLETypeConversions.calendarToRawBytes(now);
byte[] tail = new byte[] { 0, BLETypeConversions.mapTimeZone(now, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ) };
byte[] bytes = BLETypeConversions.join(head, tail);
builder.write(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_CURRENT_TIME), bytes); builder.write(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_CURRENT_TIME), bytes);
return this; return this;
} }
@ -4107,7 +4096,11 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
} }
public TimeUnit getFetchOperationsTimeUnit() { public TimeUnit getFetchOperationsTimeUnit() {
return TimeUnit.MINUTES; // This is configurable because using seconds was causing issues on Amazfit GTR 3
// However, using minutes can cause issues while fetching workouts shorter than 1 minute
final Prefs devicePrefs = getDevicePrefs();
final boolean truncate = devicePrefs.getBoolean("huami_truncate_fetch_operation_timestamps", true);
return truncate ? TimeUnit.MINUTES : TimeUnit.SECONDS;
} }
public boolean force2021Protocol() { public boolean force2021Protocol() {