Skip to content

Identify the app in the tile request User-Agent - #62

Merged
afarber merged 1 commit into
mainfrom
per-app-user-agent
Oct 14, 2026
Merged

afarber merged 1 commit into
mainfrom
per-app-user-agent

Conversation

@afarber

@afarber afarber commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Tile requests sent the same User-Agent for every app, OpenMapView/<version> (https://github.com/afarber/OpenMapView). The OSM tile usage policy asks for a User-Agent that identifies the application. If one app overused the tile servers and OSM blocked that string, every app using OpenMapView would lose its tiles. The base map User-Agent also could not be changed, unlike overlays, which can override UrlTileProvider.getUserAgent().

Now the User-Agent includes the app package name, for both the base map and overlays:

OpenMapView/0.17.1 (com.example.app; https://github.com/afarber/OpenMapView)
  • New internal UserAgent object, filled in from context.packageName by every MapController (it is process-wide because UrlTileProvider has no Context)
  • TileDownloader and the default UrlTileProvider.getUserAgent() use it; subclasses that override getUserAgent() are unaffected
  • The build now generates only LIBRARY_VERSION
  • docs/PERFORMANCE.md and docs/REPLACING_GOOGLE_MAPS.md describe the new header

No public setter is added: the package name already identifies the app, and the Google Maps API has nothing like it. One can be added later if someone needs a custom base map User-Agent.

Tests

  • UserAgentTest: format with and without a package name, and MapController sets the package name
  • TileDownloaderTest and UrlTileProviderTest: base map and overlay requests send the app User-Agent

- Add the app package name to the User-Agent of base map and overlay
  tile requests, as the OSM tile usage policy asks, so a block caused by
  one app does not affect every app using OpenMapView
- Generate only LIBRARY_VERSION and build the User-Agent in UserAgent
@afarber
afarber merged commit 44e1ef2 into main Oct 14, 2026
14 checks passed
@afarber
afarber deleted the per-app-user-agent branch October 14, 2026 17:46
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