Skip to content

fix geotagging location selection, providers, lifecycle and staleness - #662

Open
thomasbuilds wants to merge 4 commits into
GrapheneOS:mainfrom
thomasbuilds:location-fixes
Open

fix geotagging location selection, providers, lifecycle and staleness#662
thomasbuilds wants to merge 4 commits into
GrapheneOS:mainfrom
thomasbuilds:location-fixes

Conversation

@thomasbuilds

@thomasbuilds thomasbuilds commented Jul 9, 2026

Copy link
Copy Markdown

Follow-up to #637 and the remaining part of #530. The one-line fix in #637 was incomplete on its own: with the comparison direction corrected, the one-sided staleness check still lets a significantly older but accurate fix win whenever it appears after a fresher one in a candidate list (last known location scans, batched updates), and the wall-clock time comparison it relies on isn't reliable across providers in the first place.

  1. Pick the most accurate recent location for geotagging instead of the least accurate one: the accuracy tiebreaker was inverted (smaller getAccuracy() is better), the staleness check was one-sided (a significantly older candidate fell through to the accuracy comparison, making the result order-dependent), and ages were compared via wall-clock Location.getTime(), which the platform documentation says "should not be used to order or compare locations". The selection is now: take the newest fix (by elapsedRealtimeNanos), and among fixes not significantly older than it, pick the most accurate; missing accuracy ranks last, ties go to the newer fix. It lives in its own file as a plain top-level getOptimalLocation(locations) with instrumented tests covering the ordering, staleness, missing-accuracy and threshold-boundary cases. This commit also stops discarding the stored fix: both the batched update callback and the last known location scan now merge it into the selection instead of replacing or skipping it.

  2. Request location from the fused provider alone instead of every provider at once: previously updates were requested from every provider at once (gps, network, fused, passive), duplicating what fused already combines and forcing the GNSS engine on. The system-app gate from Consider both staleness and accuracy to decide optimal location #531 is replaced with hasProvider(FUSED_PROVIDER): availability is the OS's contract, not the caller's privilege. Falls back to gps, network and passive before S, or on the off chance fused is absent on a newer release.

  3. Stop location updates while the activity is paused: the listener used to stay registered for the process lifetime; now it follows onResume/onPause, and disabling geotagging clears the stored fix.

  4. Stop attaching stale locations to captures: getLocation() returns null for fixes older than 15 minutes, and drops the stored fix so it can't be reused, instead of silently writing an arbitrarily old position into EXIF; the existing location-unavailable message covers that case. minDistance goes from 10 m to 0 so stationary users keep receiving fixes (otherwise a still-valid fix ages past any bound).

@RankoR RankoR left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will also require a rebase after #665 merged

Comment thread app/src/main/java/app/grapheneos/camera/App.kt Outdated
Comment thread app/src/main/java/app/grapheneos/camera/App.kt
Comment thread app/src/main/java/app/grapheneos/camera/App.kt Outdated
Comment thread app/src/main/java/app/grapheneos/camera/App.kt Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants