Fix GPS fallback: reuse last GPS location instead of Berlin - #22
Conversation
When GPS mode was active but a fresh fix couldn't be obtained — revoked permission (Android 11+ auto-revokes for unused apps), disabled location services, or a cold-start timeout with no last-known position — the foreground path jumped straight to the Berlin default. That result flowed through `_loadWeather` → `NativeSvgService.fetchWeather`, overwriting the native `cached_latitude`/`cached_longitude` (and cached city/source) that the background widget refresh reads, so the widget got stuck on Berlin. Now every successful GPS resolution persists its coordinates + city to new `last_gps_*` keys, and all "no fresh fix" branches reuse that stored location (tagged as GPS) before falling back to Berlin. Berlin is only used when no GPS location was ever stored (genuine first run). Kept separate from the manual `saved_*` keys so the two modes don't clobber each other. Fix is Dart-side; the native cache self-heals on next fix. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesGPS Location Fallback Persistence
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Problem
When GPS is unavailable, Meteograph falls back to Berlin even when a valid GPS
location was previously acquired. This shows up after the app has been dormant
(Android 11+ auto-revokes location permission for unused apps) or after a reboot
when a cold GPS fix times out.
Root cause is in the foreground path (
LocationService._getGpsLocation):every "no fresh fix" branch — disabled location services, non-granted permission,
or a one-shot/last-known timeout — jumped straight to the Berlin default without
checking for a previously-resolved GPS location.
That Berlin result then propagates and poisons the widget cache:
home_screen.dart_loadWeather→NativeSvgService.fetchWeather(Berlin)overwrites the native
cached_latitude/cached_longitude(the sameSharedPreferences file the widget reads) and
cacheLocationInfooverwrites thecached city/source. The native background widget refresh then keeps rendering
Berlin.
Fix
_toLocationData, covering both theone-shot fix and the last-known fallback), persist coordinates + city to new
keys
last_gps_latitude/last_gps_longitude/last_gps_city._lastGpsOrFallback()helper, which returns the stored last-GPS location (tagged
LocationSource.gps)and only falls back to Berlin when no GPS location was ever stored (genuine
first run).
saved_*keys (manual-location-only, whichforce
use_gps=false), so GPS and manual modes don't clobber each other.The change is entirely Dart-side; the native cache self-heals on the next good fix.
Tests
Added a
LocationService GPS fallbackgroup covering:fresh fix times out (none fall back to Berlin)
make analyzeclean; all 120 Dart tests pass. No Kotlin changed.🤖 Generated with Claude Code
Summary by CodeRabbit