From 8a8b811acff8348f69e90f2d5ce651e0781bb969 Mon Sep 17 00:00:00 2001 From: Dany Mestas <94061157+DanyPM@users.noreply.github.com> Date: Sun, 10 May 2026 19:13:31 +0200 Subject: [PATCH] Xiaomi: fix GPS dropping mid-workout on newer firmware --- .../xiaomi/services/XiaomiHealthService.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java index 794cfd1f41..0f402bbcba 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java @@ -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) {