Xiaomi: fix GPS dropping mid-workout on newer firmware

This commit is contained in:
Dany Mestas
2026-05-10 23:27:43 +02:00
committed by José Rebelo
parent 25b39b6d7c
commit 8a8b811acf
@@ -211,6 +211,9 @@ public class XiaomiHealthService extends AbstractXiaomiService {
@Override
public void dispose() {
gpsTimeoutHandler.removeCallbacksAndMessages(null);
gpsStarted = false;
gpsFixAcquired = false;
workoutStarted = false;
activityFetcher.dispose();
}
@@ -652,8 +655,6 @@ public class XiaomiHealthService extends AbstractXiaomiService {
gpsFixAcquired
);
workoutStarted = false;
final boolean sendGpsToBand = getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_WORKOUT_SEND_GPS_TO_BAND, false);
if (!sendGpsToBand) {
getSupport().sendCommand(
@@ -678,15 +679,21 @@ public class XiaomiHealthService extends AbstractXiaomiService {
GBLocationService.start(getSupport().getContext(), getSupport().getDevice(), GBLocationProviderType.GPS, 1000);
}
final int timeout = getDevicePrefs().getInt(DeviceSettingsPreferenceConst.PREF_WORKOUT_SEND_GPS_TO_BAND_TIMEOUT, 5000);
gpsTimeoutHandler.removeCallbacksAndMessages(null);
// Timeout if the watch stops sending workout open
gpsTimeoutHandler.postDelayed(() -> {
LOG.debug("Timed out waiting for workout");
gpsStarted = false;
gpsFixAcquired = false;
GBLocationService.stop(getSupport().getContext(), getSupport().getDevice());
}, timeout);
if (!workoutStarted) {
// Only schedule the timeout while we are still waiting for the watch to confirm
// workout start. Once WORKOUT_STARTED has arrived, only WORKOUT_FINISHED should
// stop GPS - newer firmwares (Mi Band 10 HyperOS 3.2.x) stop emitting
// WorkoutOpenWatch shortly after start, so a rescheduled timeout would fire
// mid-workout and starve the watch of GPS updates.
final int timeout = getDevicePrefs().getInt(DeviceSettingsPreferenceConst.PREF_WORKOUT_SEND_GPS_TO_BAND_TIMEOUT, 5000);
gpsTimeoutHandler.removeCallbacksAndMessages(null);
gpsTimeoutHandler.postDelayed(() -> {
LOG.debug("Timed out waiting for workout");
gpsStarted = false;
gpsFixAcquired = false;
GBLocationService.stop(getSupport().getContext(), getSupport().getDevice());
}, timeout);
}
}
private void handleWorkoutStatus(final XiaomiProto.WorkoutStatusWatch workoutStatus) {