fix geotagging location selection, providers, lifecycle and staleness - #662
Open
thomasbuilds wants to merge 4 commits into
Open
fix geotagging location selection, providers, lifecycle and staleness#662thomasbuilds wants to merge 4 commits into
thomasbuilds wants to merge 4 commits into
Conversation
RankoR
suggested changes
Jul 27, 2026
…least accurate one
thomasbuilds
force-pushed
the
location-fixes
branch
from
July 29, 2026 12:27
7ab807e to
715db51
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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-clockLocation.getTime(), which the platform documentation says "should not be used to order or compare locations". The selection is now: take the newest fix (byelapsedRealtimeNanos), 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-levelgetOptimalLocation(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.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.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.
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.minDistancegoes from 10 m to 0 so stationary users keep receiving fixes (otherwise a still-valid fix ages past any bound).