Skip to content

Commit 1a9e2cf

Browse files
eriedclaude
andcommitted
fix(upload): cancel pending follow-up sweep when a new ride starts
The 60s post-finalize follow-up should not fire mid-ride. startRecording now cancels both follow-up unique-work names; the upcoming stopRecording will schedule a fresh one that covers this ride and anything earlier. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1524b3e commit 1a9e2cf

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

app/src/main/java/com/eried/eucplanet/data/repository/TripRepository.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ class TripRepository @Inject constructor(
261261
// intent), this returns false and we bail before announcing or opening files.
262262
if (!_recording.compareAndSet(expect = false, update = true)) return
263263

264+
// Drop any pending follow-up upload sweep from the previous trip. The
265+
// upcoming stopRecording will schedule its own follow-up that covers this
266+
// ride and anything earlier still pending.
267+
syncManager.cancelUploadFollowups()
268+
264269
// Sanity-check location permission at recording start so missing permission is obvious in logs.
265270
val hasFine = androidx.core.content.ContextCompat.checkSelfPermission(
266271
context, android.Manifest.permission.ACCESS_FINE_LOCATION

app/src/main/java/com/eried/eucplanet/data/sync/SyncManager.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,15 @@ class SyncManager @Inject constructor(
681681
)
682682
}
683683

684+
/** Drop any pending follow-up sweeps. Called when a new recording starts so the
685+
* previous trip's 60s follow-up doesn't fire mid-ride; the next finalize will
686+
* schedule its own. */
687+
fun cancelUploadFollowups() {
688+
val wm = WorkManager.getInstance(context)
689+
wm.cancelUniqueWork(UPLOAD_FOLLOWUP_WORK_NAME)
690+
wm.cancelUniqueWork(EUCSTATS_UPLOAD_FOLLOWUP_WORK_NAME)
691+
}
692+
684693
fun enqueueEucStatsUploadDelayed(settings: AppSettings, delaySeconds: Long) {
685694
val constraints = Constraints.Builder()
686695
.setRequiredNetworkType(NetworkType.CONNECTED)

0 commit comments

Comments
 (0)