Skip to content

Read location providers according to the permission actually granted - #990

Open
Madroid2 wants to merge 1 commit into
prebid:masterfrom
Madroid2:fix/location-coarse-permission-956
Open

Read location providers according to the permission actually granted#990
Madroid2 wants to merge 1 commit into
prebid:masterfrom
Madroid2:fix/location-coarse-permission-956

Conversation

@Madroid2

@Madroid2 Madroid2 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Change Log with reasoning:

  • LastKnownLocationInfoManager gated both providers behind a single check that passed when either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION was granted, then read GPS_PROVIDER and NETWORK_PROVIDER inside one try block.

  • GPS_PROVIDER requires precise location. Since Android 12 a user can grant approximate location on its own, and that is the common case -- the runtime dialog offers it as a first-class choice. In that state the GPS read throws SecurityException, which unwinds to the shared catch before NETWORK_PROVIDER is ever reached, so the SDK ends up with no location at all rather than the coarse fix the user did consent to. The only trace is a log line blaming an "android firmware bug", which sends anyone debugging it in the wrong direction.

  • Each provider is now asked for separately and only when the permission it actually needs is held: GPS_PROVIDER for precise, NETWORK_PROVIDER for either grant. The read itself is isolated per provider, so a refusal or a provider missing on the device no longer prevents the other from being consulted -- IllegalArgumentException is handled for that second case, which the previous code did not cover at all. The selection logic that prefers GPS and falls back to the network fix via isBetterLocation is unchanged.

  • Covers the new behaviour in LastKnownLocationInfoManagerTest: coarse-only never asks for GPS, a refused GPS read still yields the network location, and no grant reads no provider.

  • Partially addresses Deprecated API usage for device and user info #956 (location permissions). The deprecated display metrics and network connection APIs named in that issue are handled separately.

LastKnownLocationInfoManager gated both providers behind a single check that
passed when either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION was
granted, then read GPS_PROVIDER and NETWORK_PROVIDER inside one try block.

GPS_PROVIDER requires precise location. Since Android 12 a user can grant
approximate location on its own, and that is the common case -- the runtime
dialog offers it as a first-class choice. In that state the GPS read throws
SecurityException, which unwinds to the shared catch before NETWORK_PROVIDER
is ever reached, so the SDK ends up with no location at all rather than the
coarse fix the user did consent to. The only trace is a log line blaming an
"android firmware bug", which sends anyone debugging it in the wrong
direction.

Each provider is now asked for separately and only when the permission it
actually needs is held: GPS_PROVIDER for precise, NETWORK_PROVIDER for either
grant. The read itself is isolated per provider, so a refusal or a provider
missing on the device no longer prevents the other from being consulted --
IllegalArgumentException is handled for that second case, which the previous
code did not cover at all. The selection logic that prefers GPS and falls back
to the network fix via isBetterLocation is unchanged.

Covers the new behaviour in LastKnownLocationInfoManagerTest: coarse-only
never asks for GPS, a refused GPS read still yields the network location, and
no grant reads no provider.

Partially addresses prebid#956 (location permissions). The deprecated display
metrics and network connection APIs named in that issue are handled
separately.
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.

1 participant