Skip to content

Add geolocation listening minimum distance - #35784

Merged
jfversluis merged 4 commits into
net11.0from
jfversluis/geolocation-minimum-distance-api
Jun 8, 2026
Merged

jfversluis merged 4 commits into
net11.0from
jfversluis/geolocation-minimum-distance-api

Conversation

@jfversluis

Copy link
Copy Markdown
Member

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

Adds GeolocationListeningRequest.MinimumDistance so apps can explicitly control the movement threshold for foreground geolocation listening.

The new property defaults to 0, preserving the new no-hidden-distance-filter behavior, and is wired to:

  • Android LocationManager.RequestLocationUpdates minimum distance
  • Windows Geolocator.MovementThreshold
  • iOS/Mac Catalyst CLLocationManager.DistanceFilter, mapping 0 to CLLocationDistance.FilterNone

The existing desired accuracy value continues to configure platform accuracy and listener accuracy filtering.

Issues Fixed

Follow-up API for #22683

Validation

  • Ran src/Essentials/test/UnitTests/Essentials.UnitTests.csproj
  • Built src/Essentials/src/Essentials.csproj for net11.0-ios26.4
  • Built src/Essentials/src/Essentials.csproj for net11.0-android36.1 with TargetFrameworks=net11.0-android36.1

Note: local net11.0-android37.0 build is blocked because Android API 37 is not installed locally.

Expose an explicit minimum distance option for foreground geolocation listening and wire it to the platform movement threshold APIs.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35784

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35784"

Cover the default minimum distance value and shared foreground listening request validation.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Avoid ArgumentNullException.ThrowIfNull in shared geolocation code so the netstandard2.0 target compiles.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kubaflo

kubaflo commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

AI code review refresh for net11.0 target

Head reviewed: a53a11633f499a5fe8c04430eef7f26cd2035ce3
Base: net11.0 · State: open

Verdict: LGTM (minor notes)

Independent review of the diff and full changed files (Android/iOS-macOS/Windows/shared) before reading the PR narrative. The change adds GeolocationListeningRequest.MinimumDistance (default 0) and wires it to each platform's movement-threshold API.

Findings (high-signal)

  • Correctly fixes a pre-existing mis-mapping. Before this PR the distance argument was driven by accuracy, not distance: Android passed providerInfo.Accuracy as the minDistance arg of RequestLocationUpdates, and Windows set MovementThreshold = PlatformDesiredAccuracy. Both are now driven by the explicit MinimumDistance. Good.
  • ⚠️ Behavior change to flag (discussion, not blocker). Because the default is 0, existing apps that relied on the old implicit distance throttle (Android 50–500 m, Windows = accuracy meters) will now receive updates purely on the time interval — more frequent callbacks / higher battery use. This is intentional ("no-hidden-distance-filter") and is acceptable for a net11.0 major, and it's noted in the PR body, but it is an observable runtime change worth calling out in release notes.
  • netstandard fix is correct. Centralizing validation in ValidateListeningRequest (shared) and using an explicit null throw instead of ArgumentNullException.ThrowIfNull keeps the netstandard2.0 target compiling. Validation now also rejects negative MinimumTime/MinimumDistance consistently across platforms (Windows previously only checked time).
  • iOS mapping is sound. MinimumDistance == 0 ? CLLocationDistance.FilterNone : MinimumDistance; negatives are validated out beforehand.
  • PublicAPI entries added for all TFM folders (get/set). Tests cover defaults, setter, and negative-value validation.

Minor / optional

  • Per-platform StartListeningForegroundAsync XML docs still list only ArgumentNullException; the new ArgumentOutOfRangeException was added to the interface doc in Geolocation.shared.cs but not to the platform implementations. Cosmetic.
  • Unit tests exercise the shared validation only (expected); platform threshold wiring isn't unit-testable here.

CI

At review time maui-pr and Helix unit-test legs are pending (build in progress); license/cla and dogfood checks pass. No failing required checks observed — re-verify the build legs complete green before merge.

Confidence

Medium-high on the shared/platform logic (read full files at head). Behavior-change note is the main thing to weigh.


Automated non-binding review. Not an approval — I did not use --approve/--request-changes. A human maintainer should make the merge decision.

Add the ArgumentOutOfRangeException XML docs to platform StartListeningForegroundAsync implementations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kubaflo

kubaflo commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

AI code review refresh for net11.0 target

Head reviewed: 1856434b17b3d3338acf3b8e450a3eedd0efb9e8
(Assignment listed 421a0df…; trusted the actual current PR head from the API.)

Verdict: LGTM (minor, non-blocking notes) — confidence: high.

What changed since the prior marker

The only new commit is 1856434 "Document geolocation listening validation exceptions". It adds <exception cref="ArgumentOutOfRangeException"> XML doc tags to the shared IGeolocation interface and all three platform StartListeningForegroundAsync implementations (Android, iOS/macOS, Windows). This is documentation-only and directly completes the doc surface for the validation introduced in earlier commits. No behavioral code changed in this commit.

Independent assessment of the full change

  • API surface: GeolocationListeningRequest.MinimumDistance { get; set; } -> double added; PublicAPI.Unshipped.txt updated consistently across all TFMs (net, net-android, net-ios, net-maccatalyst, net-windows, net-tizen, netstandard). ✔️
  • Validation: centralized in GeolocationImplementation.ValidateListeningRequest (null → ArgumentNullException; negative MinimumTime/MinimumDistance → ArgumentOutOfRangeException). Replaces the previously duplicated/Windows-only checks. ✔️
  • Platform wiring:
    • Android: passes (float)request.MinimumDistance to RequestLocationUpdates — fixes the prior code that incorrectly passed providerInfo.Accuracy as the min-distance arg. ✔️
    • iOS/macOS: DistanceFilter = MinimumDistance == 0 ? CLLocationDistance.FilterNone : MinimumDistance — correct kCLDistanceFilterNone semantics for the 0 sentinel. ✔️
    • Windows: MovementThreshold = request.MinimumDistance — fixes prior code that reused PlatformDesiredAccuracy. ✔️
  • Tests: new GeolocationListeningRequest_Tests cover default-to-zero init across all three constructors, settability, zero allowed, and negative distance/time throwing (uses -double.Epsilon edge). ✔️

Minor / non-blocking notes

  • Tizen ships the public MinimumDistance API but there's no Tizen implementation wiring it into a distance filter, so the value is silently ignored on Tizen. Consider a follow-up or a doc note. (Low signal.)
  • Coverage is unit-level only (property + validation); no test exercises the platform filter wiring. Acceptable given the surface, but worth noting.

CI note

maui-pr is red, but the failures are the AOT/trim "Unexpected warning files detected" template issue (linker-cache/apply-preserve-attribute.xml from ILC) hitting the base maui template across AOT macOS and RunOniOS_MauiRelease*Trim* legs. These are environmental/known net11.0 trimming-warning failures, not caused by this Essentials managed-code change (no trimming descriptors or platform-native code touched). Helix unit-test legs, Android, Blazor, Windows, and non-trim iOS legs all pass. Build Analysis matched no known issues but lists only these unmatched template-trim failures.


Automated net11.0 fleet refresh (round 11). This is not an approval or merge authorization — no --approve/--request-changes was used; posting an informational comment only. A human reviewer should make the merge decision.

@jfversluis

Copy link
Copy Markdown
Member Author

Heads-up for any future merge-forward/cherry-pick involving the service-release fix from #35783: both changes touch the same Android RequestLocationUpdates min-distance argument. If a conflict appears, keep the net11.0 API version:

LocationManager.RequestLocationUpdates(provider, minTimeMilliseconds, (float)request.MinimumDistance, continuousListener, looper);

This preserves the service-release behavior because MinimumDistance defaults to 0, while retaining the new explicit API.

@jfversluis
jfversluis enabled auto-merge (squash) June 8, 2026 13:58
@jfversluis
jfversluis disabled auto-merge June 8, 2026 14:15
@jfversluis
jfversluis merged commit ef49a2b into net11.0 Jun 8, 2026
30 of 36 checks passed
@jfversluis
jfversluis deleted the jfversluis/geolocation-minimum-distance-api branch June 8, 2026 14:16
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/android platform/ios platform/macos macOS / Mac Catalyst platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants