Repository navigation
Architecture
English · Italiano
The app is split into Gradle modules with one simple rule: every feature depends only on core modules, never on another feature. This way one screen cannot break the others. Each part is built and tested on its own.
The app module depends on the features; the features depend on the core modules. Arrows go from the module that uses another to the module it uses (dependencies from build.gradle.kts, without those of the tests). For readability, the direct arrows to core:data and core:ui are left out for modules that already reach them through another module.
flowchart TD
accTitle: Dependencies between modules
accDescr: app depends on feature:ai, feature:guide, feature:map, feature:sources, feature:vault and core:sync. feature:ai uses core:speech, core:translate, core:sync, core:ui and core:data. feature:map uses core:routing-engine, core:speech, core:ui and core:data. feature:guide, feature:sources and feature:vault use core:ui and core:data. core:sync uses core:tiles, core:ui and core:data. core:ui uses core:data and core:poi. core:data uses core:poi and core:transit-routing.
app["app"] --> ai["feature:ai"]
app --> guide["feature:guide"]
app --> map["feature:map"]
app --> sources["feature:sources"]
app --> vault["feature:vault"]
app --> sync["core:sync"]
ai --> speech["core:speech"]
ai --> translate["core:translate"]
ai --> sync
ai --> ui["core:ui"]
map --> routing["core:routing-engine"]
map --> speech
map --> ui
guide --> ui
sources --> ui
vault --> ui
sync --> tiles["core:tiles"]
sync --> ui
ui --> data["core:data"]
ui --> poi["core:poi"]
sync --> data
data --> poi
data --> transit["core:transit-routing"]
| Module | What it does |
|---|---|
app |
navigation, main screens (country list, settings, first launch) |
core:data |
Room database, package files on disk, encryption |
core:sync |
catalog, download and installation of packages (WorkManager) |
core:poi |
point of interest categories (pure Kotlin, also used by the pipeline) |
core:tiles |
PMTiles tile ids of a bounding box, in blocks (pure Kotlin, also used by the pipeline) |
core:ui |
Material 3 theme, icons, shared components |
core:speech |
reading aloud with the system voice |
core:routing-engine |
BRouter with the project's patches (also used by the pipeline) |
core:transit-routing |
public transport journeys on a GTFS network (RAPTOR), in pure Kotlin |
core:translate |
on-device translator (bergamot-translator) and zstd decompressor |
feature:guide, feature:map, feature:ai, feature:vault, feature:sources
|
the individual features |
baselineprofile |
generates the app's baseline profile and measures startup (not part of the APK) |
-
core:tilesalso serves the pipeline for the SHA-256 hash of the map. -
core:uiuses the system colors, from Android 12, if the "System colors" switch in Settings → Appearance is on. -
core:speech(ReadAloud,SystemReadAloud) reads aloud for the assistant and provides the Navigator's voice (NavigationVoice): see Accessibility and voice. -
core:routing-enginebuilds BRouter from thethird-party/broutersubmodule. -
baselineprofileruns on an emulator or a phone and measures startup with and without the profile.
core:transit-routing uses RAPTOR to compute public transport journeys on a network (Public transport).
core:translate builds bergamot-translator and the zstd decompressor with JNI: see On-device translation.
core:poi and core:tiles are pure Kotlin on purpose. The same rules on points of interest and the same tile ids serve both the app and the pipeline that prepares the data, and they must not diverge.
When a feature needs something that lives in another one, the interface goes in core and the implementation stays where the data is. For example, the assistant (feature:ai) asks CarRouteCalculator of core:data for the car route between two cities. feature:map implements it with BRouter (BRouterCarRouteCalculator) and binds it with Hilt.
- Jetpack Compose and Material 3 for the interface, with an adaptive layout for phones and tablets.
- Hilt to connect the parts without passing objects around by hand.
- Room 3 for the database (see Room and Database).
- WorkManager for downloads and updates (see WorkManager).
- MapLibre for the map.
- BRouter for routes, llama.cpp for the assistant and bergamot-translator for translation, as submodules (see Submodules and patches).
- OkHttp for downloads, CameraX for document photos.
- R8 in the release build (see R8).
Room uses SQLite with the Android driver (AndroidSQLiteDriver). It holds installed regions, country and city guides, points of interest, and encrypted documents and notes. Full-text search uses FTS4 with the unicode61 tokenizer, which also recognizes accented capital letters.
Downloads and updates go through WorkManager because they survive the app being closed and device restarts, and they can wait for Wi-Fi.
A region download runs in the foreground (type dataSync), with a progress notification and "Cancel". This way the system does not stop it when the screen is off. On Android 12 and later, which reports the reason for the stop, "Cancel" also deletes the partially downloaded files, even for a region that is already installed.
On Android 12 and later, a retry started from the background cannot start the foreground work, and it downloads without a notification. Without a notification the work has a 10-minute limit, and the map extraction starts over from the beginning at every stop. For this reason, from the third attempt without a notification the download stops with an error.
Each download request is a job of its own, with a unique name per request. The tag region-download:<region> is used to follow and cancel it. With a chain on the region name, one failed download would also make the ones queued after it fail.
Requests for the same region are queued on the preparation lock. Among several finished downloads, the screens follow the last one queued (tag region-download-at:<time>), because WorkManager does not return the jobs of a tag in order. Each request cleans up only its own staging folder. This way a second request for the same region does not delete that of the first, which is waiting to retry.
The catalog entry that describes the region does not go through the job data. WorkManager rejects data above 10 KB, and regions with many road network segments exceed it (Russia - Siberia, Brazil, Australia: 22 in total). Without this rule the app would close when "Download" is tapped.
The entry is written to a file per request (DownloadRequestFiles). Only the file name goes into the job data, which the job reads and then deletes. Files of requests that never started are removed after 30 days.
The catalog, signatures and signed files are read with a size cap (ReadBodyAtMost). A catalog with a size of zero is rejected. enqueueDownload and enqueueGuidesSync are suspend and work on IO.
The periodic check of the countries (RegionManifestSyncWorker) also compares house numbers and public transport timetables, like the country list (regionUpdates). The house number and transport indexes are downloaded only if an installed region has that package. For transport, the networks already installed count.
The "update available" notifications (countries, app, AI model) never download anything on their own. They show the size with the right unit ("4.7 kB", "12 MB"). Tapping opens the Updates screen, where the user starts the update. The intent is the explicit launch intent of the package with an extra (UpdateAvailableNotifier.EXTRA_OPEN_SCREEN), and MainActivity accepts only its known values.
BRouter, llama.cpp and bergamot-translator are git submodules in third-party/. BRouter and llama.cpp each sit on the commit of an upstream release; llama.cpp is at tag v1.0.0. bergamot-translator sits on commit 9271618, because the project has made no releases since 2024. This makes builds reproducible, and an update is a tag change. The llama.cpp security fix that affects the app is described in Native libraries, in Privacy and security.
The submodules stay identical to upstream. The project's changes are patches in third-party/patches/, which the build applies to a copy:
- for llama.cpp, the CMake of
feature:aiinfeature/ai/.cache/cxx/llama-cpp-src; - for bergamot-translator, the CMake of
core:translateincore/translate/.cache/cxx/bergamot-src, without thenonbreaking_prefixesfiles of ssplit-cpp, which are LGPL; - for BRouter, the
brouterSourcestask incore/routing-engine/build/generated/brouter.
A patch that no longer applies makes the build fail with its name. Before the build, CI checks that the patches apply to the submodules. Each patch states in its description the upstream PR or issue ("Upstream:") and when it can be removed ("Da togliere quando:"). CI warns, without failing, when a patch turns out to be already in the submodule.
There are four BRouter patches:
- the casts for CodeQL;
-
RoutingEngine.getProgress, described below; - the
DirectWeaverfix from BRouter PR #958, not yet in a release; -
foundTracks, the list of all computed routes, which gives the main route and two alternatives with a single calculation instead of three.
getProgress estimates the progress of the calculation for the progress bar in navigation. The quick search counts for 10%, measured by straight-line proximity. The exact search counts for 88%, measured by the cost reached compared with the cost found by the quick search. The reconstruction counts for 2%. The estimate is calibrated on Milan-Rome by car.
Besides the patches, the :core:routing-engine module adds to BRouter a file of its own, TurnInstructions, which reads the turns: their fields are package-private.
The only llama.cpp patch lowers the message "Git repository not found" from warning to info, because the compiled copy has no .git.
The 11 bergamot-translator patches are listed in Translation.
In the release build, R8 removes unused code and resources and optimizes the classes. The rules in app/proguard-rules.pro keep BRouter whole, because it creates classes from the name written in the .brf profiles. They also keep the llama.cpp JNI class, because the native symbols depend on its full name. Stack traces keep the line numbers.
On every push, CI searches OSV for known vulnerabilities in all resolved libraries, transitive ones included. Dependency Guard then compares the dependencies of the release APK with the list in app/dependencies/releaseRuntimeClasspath.txt. An extra library, for example Google Play Services brought in by another one, fails the job until the list is regenerated. The command is in the developer guide (Italian), section "Compilare e provare"; the other checks are on the Publishing page.
The release APK contains the list of classes and methods used at startup (app/src/release/generated/baselineProfiles). Android compiles them right away, instead of interpreting them during the first launches. profileinstaller has them compiled even when the APK comes from GitHub Releases and not from the Play Store.
The profile is regenerated on an emulator or a phone with Android 13 or later, and committed. StartupBenchmark in the same module measures the cold start without compilation and with the profile. The two commands are in the developer guide (Italian), section "Compilare e provare".
Modules and classes for vaccinations, alerts, weather and exchange rate in the Guide are in Guide screen.
RegionRepository, AddressSearchRepository and TransitRepository of core:data are interfaces. They are implemented by RoomRegionRepository, SqliteAddressSearchRepository and SqliteTransitRepository, bound with Hilt. The test fakes (FakeRegionRepository and the others) live in testFixtures, like those of feature:ai. This way a ViewModel is tested with a unit test, without a database or a device.
Classes created by Hilt receive the dispatcher with the qualifiers @IoDispatcher and @DefaultDispatcher (core:data), instead of writing Dispatchers.IO or Dispatchers.Default. This way tests pass a test dispatcher. For the same reason, local preferences are created with PreferencesFactory.
NavigationViewModel, NavigationPlannerViewModel, MapRouteViewModel, RegionListViewModel, RegionHubViewModel and SettingsViewModel expose a single StateFlow of UiState (for example RegionHubUiState), instead of one flow per field. This way the screen always reads a consistent state.
What derives from repositories and preferences is built with combine(...).stateIn(viewModelScope, WhileSubscribed(5_000), ...). State that the ViewModel changes by itself (a question in progress, a download) lives in a MutableStateFlow updated with update { it.copy(...) }. The two patterns coexist even in the same ViewModel.
What the screen must do only once goes through a Channel read with receiveAsFlow(): opening another screen, showing a message that then disappears. The assistant's navigation requests work the same way. An outcome that stays visible is state, not an effect, because it must stay the same after a rotation. An example is the "updated" note after "Update" for public transport.
UiMessage in core:ui is the text that the ViewModel decides: Res with a resource and arguments, Plain with ready-made text. asString() reads it with stringResource, so it follows the app's language. For now it is used by the catalog error in Settings; the other screens move to UiMessage one at a time.
After the system closes the app, some screens come back as they were left:
- destination, travel mode and arrival time of the Navigator (
SavedStateHandle); - the question not yet sent to the assistant (
SavedStateHandleofAiAssistantViewModel); - the section and city chosen in the guide and the text searched among the countries (
rememberSaveablein the screen).
The passport form does not come back, because it would end up in clear text in the state the system saves.
NavigationPlannerScreen, NavigationScreen, GuideScreen, RegionListScreen, AiAssistantScreen, VaccinationScreen and VaultScreen are split into files per section. RegionListViewModel keeps the state types in RegionListUiState.kt and the functions that build the rows in RegionUiItems.kt. No screen exceeds about 600 lines.
The app has a single NavHost, PocketTravelNavHost, with type-safe routes in PocketTravelDestinations.kt. Screens are registered with NavGraphBuilder.xxxScreen(navController) functions in navigation/graph/, one file per area: regions, Navigator, Documents, More, onboarding, in-app browser.
The in-app browser (InAppBrowserScreen) opens the source websites. If a page does not open, stops loading or has an invalid certificate, instead of Android's error page it shows a screen that says whether the device is offline or the page is not available, with a "Retry" button. HTTP errors such as 404 show the site's own page; if the site sends an empty reply, the app's screen appears. After an error the app closes the WebView: "Retry" opens the page in a new one, and Back loads the previous page again. If Android closes the page's process, the app stays open and shows the same screen. If the site has a service worker and the page does not download, the screen appears only when the service worker has no saved copy: the app tells from the address of the page shown, read when it enters the history.
The automatic openings at startup are a queue of commands of StartDestinationViewModel.startCommands, run in order. Examples are the map of the last region and the Navigator from the notification. There is a single planner and a single navigation for the app: the NavHost takes them from the activity and passes them to the screens with LocalNavigatorViewModels.
The Back arrows call popBackStack() inside dropUnlessResumed, which ignores taps while the screen is already exiting. Without it, two quick taps on Back in a region page would also remove the country list from the stack.
"Emergency" and "Shortcuts" are Jetpack Glance 1.2.0 widgets in the app's widget package. WidgetStateLoader reads only local data: last region, emergency numbers, nationality, diplomatic missions, assistant availability.
The changes flow of WidgetStateLoader makes WidgetRefresher redraw the widgets, with a 1 s wait. While a Glance session is open it also makes them reread, with produceState, because updateAll alone redraws without rereading the data.
Taps open MainActivity with EXTRA_OPEN_SCREEN (region:<id>:<tab>, navigator, documents), with the values checked by openScreenTarget. A region page opens on top of Countries. If the same region is already open, only the tab changes (OpenScreenRequests.regionTab), so a response in progress is not lost.
A number opens the dialer with ACTION_DIAL, without calling. "This region has no single emergency number" appears only if the table says so. If the data is missing, "Numbers not available yet" appears.
StrictModeModule in app/src/debug turns on StrictMode at startup, as one of the AppInitializers. It writes to the log, with the tag StrictMode, disk reads and writes and network calls on the main thread. It also reports unclosed Closeables and SQLite cursors, and retained activities. It never closes the app, and the release does not contain it.
PocketTravelNavHostTest runs the real NavHost with Robolectric and a test Hilt graph (@TestInstallIn), without a network. It checks the startup path, the main bar with a single copy per destination, Back from the hub and the opening of the Navigator from the notification. On the first run Robolectric downloads the test SDK's Android library from Maven Central.
The fixed numbers in the code are named constants, instead of numbers written in the middle of an expression.
The app has a single Room database, region.db, at schema 28. It contains:
- the guides of the whole world, in a table with a full-text index;
- the points of interest per region, in compact form (see Compact points of interest);
-
diplomatic_missions, the embassies and consulates from Wikidata, which arrive with the guides package; - the vaccination tables (
vacc_*), also from the guides package; - population, capital and coordinates of cities (
latitude,longitudeincity_sections), with which the assistant computes the distance between two cities; - the
translatedcolumn of the guide and city sections, which marks in Sources the machine-translated sections; -
conversationsandconversation_turns, the assistant's history, encrypted with the keys ofHistoryKeys(see Assistant history, in Privacy and security); -
city_climate, the monthly averages of cities; -
guide_terms, the local terms of the guides.
On points of interest, an index by region and latitude speeds up the map queries in large countries. An index by region, category and OSM tag gives the categories present and the counts without scanning the table.
The address search index is not in Room: it is one SQLite file per region (addresses-search.db). It is read by SqliteAddressSearchRepository, with a read-only connection per region. The connection stays open between searches, so SQLite reuses the statements already prepared. It is closed when the file is replaced or deleted, which is checked at every search.
Every schema change has its migration, verified by tests on the device. The database is not deleted and recreated, because the downloaded data would be lost.
Migrations are one per database version that shipped in a release, not one for every change made during development. Intermediate schemas that never shipped do not exist on users' devices, and this keeps the migrations few and readable. Inside each one are the original steps in order, with a comment for each.
During development, the steps added after the last release live in a single migration. The latest stays separate until its version ships, and at release it is merged with the others; today it is MIGRATION_27_28. The device tests (RegionDatabaseMigrationTest) follow the same split. A development build with an intermediate schema (UNRELEASED_VERSIONS) starts over from scratch.
More > Updates gathers in one screen:
- the new app version, from
app-status.json; - the countries to update, with the same download as the list (
RegionListViewModel); - the guides;
- the new AI model (
AiModelUpdates).
Under each country, a bulleted list says which packages change and how much they weigh. The map can be sized only by extracting it, so its size is estimated as about that of the installed map (mapEstimateBytes). With more than one package, each has its own "Update". It is the same download as a package in the Content sheet, with the same confirmation on a metered connection.
The manual check for updates is only on this screen. The country list has no pull-to-refresh and no TalkBack action, and its rows keep "update available" and the Update button.
Available updates have a single notification, "N updates available", which opens the Updates screen. The catalog, app and AI model checks each write their own part of a saved list (PendingUpdatesStore). The notification is rebuilt with the same ID, on a single channel, "Available updates".
The notification makes a sound only when something new arrives: a republished country, another version of the app or of the model. With nothing new it is updated silently if it is visible, and does not reappear if the user dismissed it. Without updates it is removed.
When app-status.json has the SHA-256 hash and size of the APK, the App section shows "Update" with the size. The APK is downloaded in the background (AppUpdateDownloads). Then the hash, package, versionCode and signing certificate are checked, and "Install" hands the APK to PackageInstaller.
On Android 12 and later, an app that updates itself does not show the system dialog. The first time, the "Install unknown apps" permission is needed, which the section explains with a button to the settings. On a metered connection the download asks for confirmation with the size ("Download without Wi-Fi?").
If the required network is missing, WorkManager stops the download. The section then says "Waiting for network", or "Waiting for Wi-Fi" if the metered connection was not accepted, with the percentage read from the .part file (networkWait). When the network returns, the download resumes with Range. If the user cancels in the system dialog, the section says "Installation canceled".
After the update, Android closes the app and does not reopen it. For this reason AppUpdatedReceiver (MY_PACKAGE_REPLACED) shows the notification "Pocket Travel updated to X.Y.Z". The notification appears only if the installed version is the one handed over by "Install" (PendingAppInstall), not after an update from the browser.
"What's new" opens the vX.Y.Z release on GitHub, which carries the CHANGELOG section. "Download from GitHub" remains as an alternative. It is the only action when the file has no hash (versions up to 0.14.0). It is also the only one after an error that the same APK would repeat: wrong signature, package, version or archive (canRetry).
After a network error or a different hash, "Update" remains. The error applies only to the version that caused it: with a newer version in app-status.json, "Update" returns (relevantDownload).
Under "Check for updates" the screen shows the time of the last successful check of app-status.json, with the date if it is not today. The time is written by HttpAppStatusClient, also in the daily check. "Update all" starts immediately on an unmetered network, and asks for confirmation with the size on a metered connection.
Without a connection, the screen says "No connection" instead of "Everything is up to date". The check is offline when app-status.json, which is always downloaded, does not arrive and the device has no usable network (updateCheckOffline). The catalog is not enough, because in the last 10 minutes it comes from memory even without a network. When a network is available, an error comes from the server, and the screen keeps the previous values.
Measurements are from Oct 11, 2026, where no other date is written.
The native libraries are installed without debug symbols. For this reason the app declares ndkVersion, so that AGP strips them, and the llama.cpp CMake builds with -g0. The release contains only arm64-v8a; the debug build also x86_64 for emulators. This brings the APK down from 116 to 20 MB and the extracted libraries from about 190 to 35 MB. 32-bit devices stay on 0.10.0.
The llama and llama-common libraries of llama.cpp are static inside libllm-engine.so (--exclude-libs,ALL). This way the linker removes the code the app does not use: download, HTTP server, argument parser. The library drops from 8.3 to 4.9 MB on arm64 (Oct 20, 2026). ggml stays shared, because the CPU variants are loaded with dlopen.
region.db shrinks by itself after a deletion. Android's SQLite creates databases with auto_vacuum FULL, which at every commit returns the freed pages to the disk, even with minSdk 26. For this reason the app does not run VACUUM.
Points of interest are in compact form (PoiRow). regionRef and code are integers pointing to the poi_region and poi_code tables, and the coordinates latE6/lonE6 are integers. The indexes are (regionRef), (regionRef, latE6) and (regionRef, code). For Italy (measured on Oct 11, 2026) they take 94 MB in region.db instead of 180, against the 54 of the downloaded poi.db. The queries still return PoiEntity, with joins and aliases.
Migration 24→25 converts the data in SQL if the disk has twice the table's estimate plus 8 MB, because the new table goes through the WAL. It also recomputes in SQL the weight of each country's POIs, with the same constants as the estimate. Without space, it removes the POIs and writes da-riscaricare as the version.
A country with the version da-riscaricare counts as "update available". At startup a catalog check, at most one a day, sends the available-updates notification, with the text ": there was not enough space to update them", which opens Updates. Storage shows the estimate PoiEntity.estimatedStorageBytes, calibrated on Italy (−0.7%).
During installation the compressed file is deleted as soon as it is unpacked and verified. The cache of the online world map is limited to 20 MB.
At startup, the .part files of downloads left half-finished are deleted, also for countries already installed, if no download is queued. They are left half-finished, for example, after a "Cancel" on Android 8–11 or after a crash.
manifest.json, the catalog's file of regions (about 3.7 MB), must be verified and read in full. It is downloaded, however, only when it has changed. With the ETag of the saved copy the site answers 304, and the app rereads the copy, verified again (see Signed catalog, in Privacy and security). On the emulator, the second launch of the app receives 8 kB instead of the whole file.
ManifestClient.recentManifest() reuses the catalog downloaded in the last 10 minutes, the same time as the site's Cache-Control. It serves the screens that read it only to display it: country list, region page, Licenses and the check for the missing road network in the Navigator. Requests go one at a time (RecentFetch). At startup the list and the region page ask for it together, and the second finds the value of the first.
fetchManifest() always asks the site for it. It is used for the manual check for updates and before downloading a package.
ManifestClient is a singleton. With one instance per ViewModel the cache would be valid only within the same screen, and every opening of a region page would download the whole file again.
With a network, on the first read the country list starts from savedManifest(): the catalog in memory, or the verified copy on the phone, read without a network. Downloaded countries say "Checking for updates…" until the site answers. Without a network they say "Checking the catalog…" until the attempt fails; then the list of installed countries remains.
Downloads and content choices stay disabled until the site's catalog arrives, because the entries of the copy have no grid house numbers and public transport. The copy is shown even if the site does not send the ETag; in that case the next check downloads the catalog in full again. If the site does not answer, the list goes back to the installed countries.
Turn-by-turn navigation lives in the Navigator (NavigationInstructions), not in a separate navigation route. The Navigator appears in two places: the main bar and the Navigator tab of a region page. The planner (NavigationPlannerViewModel) and the navigation (NavigationViewModel), however, are shared by the whole app, tied to the activity and not to the screen.
This way the two places show the same destination and the same navigation. Navigation started in one place does not appear as interrupted in the other.
GPS, tracking, recalculation, voice and notification live in NavigationController, a singleton and not a ViewModel: navigation continues even with the app removed from recents, as long as the foreground service lives. The NavigationViewModel starts it, stops it and reads its state. A new ViewModel, after the app is reopened, finds the navigation already in progress.
The catalog and the downloads of the missing road network live in the app module (RoutingDownloadViewModel), which feature:map does not see. The app module passes them to the Navigator as functions.
NavigationSession (singleton) is the bridge between NavigationController and the service. NavigationController writes a state to show: turn, distance, street, time and arrival time, or null when there is no navigation. The notification sends back the "End" and "open the Navigator" requests. Neither knows the other.
NavigationService is a foreground service of type location. It tracks nothing: it only keeps the app in the foreground, because without it Android limits locations when the screen is off and the navigation would freeze. It draws the notification from the session state, at most once a second. It stops by itself when the state returns to null. On Android 16 the notification is a Live Update (POST_PROMOTED_NOTIFICATIONS).
On a tap on the notification, MainActivity (onNewIntent) passes the request to the session. If a region page is open, it switches to its Navigator tab; otherwise the Navigator of the main bar opens.
The Navigator's preferences live in NavigationPreferences, written by Settings: "Turn off GPS on arrival" and "Vibration when walking". The navigation in progress (ActiveNavigation) also lives there, saved to resume it after a forced close. The departure reminder ("Set a departure reminder") is an AlarmManager with two receivers: one for the notification and one that reschedules it after the restart. The Navigator's behavior is described in Navigator, in the Map page.
AiAvailability (singleton in feature:ai) says whether the assistant is usable. It is usable with a saved API key, or with a downloaded model among those visible for the RAM and the guide language. The region page hides the AI tab when it is false.
AiAvailability combines two flows, AiSettingsStore.hasApiKeyFlow and LlmModelManager.downloadedModelIds, plus a refresh() after a language change. For this reason LlmModelManager is a singleton: a single copy of the file state.
The configuration is a composable of feature:ai (AiSettingsSection) inserted in the Settings screen of app, with the same ViewModel as the chat.
The app is in Italian and English. The language is chosen at first launch and in More → Settings. Without a choice, Italian applies if the device is in Italian, and English in all other cases. Even with a device in French or German, English applies: otherwise Android would show the default texts, that is, Italian.
On Android 13 and later the language is the Android's per-app language (LocaleManager), the same as in the device settings. On Android 8–12 the app saves it and applies it by itself at startup.
The APK is not split by language, because the language is changed inside the app and both are always needed. The data texts (guides, cities) arrive in separate packages per language (see Data and packages). Names of countries, currencies and languages are computed by Android in the chosen language, with no tables to maintain.
On Android 13 and later the language change does not recreate the activity (configChanges="locale|layoutDirection"). Compose redraws the texts with the new configuration, instead of leaving about a second of black screen. onConfigurationChanged makes guides and cities download again in the new language (LanguageChangeReload, see Data and packages). It does so only when the language changes, not at every rotation or theme change.
Before the comparison, MainActivity aligns the default language (Locale.getDefault()) with its own configuration. A process that is already alive without screens, for example started by WorkManager after an update, would otherwise keep the previous language when the per-app language changes. currentGuidesLanguage() reads this language across the app. Screens that show the chosen language reread it when the configuration changes.
The country list (RegionListViewModel) survives the language change. It keeps in memory the catalog read for the language of that moment, with the English cities in place of the Italian ones (forLanguage). When the language changes it rereads it, and the guides of the cities installed in the other language count as needing an update, with the right size.
A download can start before the list is reread. If the entry's cities are still in the other language, the cities package is taken from the catalog read at that moment (hasCitiesIn). Without these two rules, the cities downloaded right after the change would stay in the previous language, and the assistant would answer with their phrases in that language.
In the first launch, the countries step passes to RegionListViewModel the language chosen in step 1, like the country list. Without it, the names would stay in the device language.
The Licenses screen has three sections, Software, AI models and Data, plus the sources of house numbers and the public transport networks of the catalog. The list is generated at build time with the AboutLibraries Gradle plugin (res/raw/aboutlibraries.json). It contains all the libraries of the APK, indirect dependencies included, with one entry each.
The manual definitions in app/aboutlibraries cover what Gradle does not see: llama.cpp with ggml, KleidiAI, nlohmann/json and cpp-httplib, LLVM OpenMP, BRouter, fonts, icons, models and data. Names and notes of the manual definitions are in strings.xml, in Italian and English (LicenseData.kt).
Each entry opens the component's page with the copyright notice and the full license text, readable without internet. At the bottom is the "License page" button. The license texts stay in the original language.
The build stops if a library has a license outside the allowed ones. The allowed code licenses are a list in app/build.gradle.kts. Those of models and data come from the definitions with tag data or models in app/aboutlibraries/libraries. LicenseDataTest checks that every definition in the folder reaches the screen and that every entry has the text of its license. The web page of licenses, generated from the same definitions, is described in Publishing.
The first launch has three steps (OnboardingStep):
- language, travel modes and nationality;
- the countries to download, which start in the background;
- a summary.
In the first step you can continue only with at least one travel mode and one nationality. The proposed nationality comes from the country of the system settings, because Locale.getDefault() follows the app's language, which has no country. The guides of all countries are downloaded automatically at the last step.
The explanations about the AI assistant, Documents and Official sources are a ContextualHint (core:ui). It is a card at the top of the screen, only the first time it is opened, with a "seen" flag in the local preferences. "Introduction" in More resets the flags.
- A single module: simpler at the beginning, but every change rebuilt everything and the dependencies got tangled.
- Room for the map: tiles are better in a PMTiles file, read directly by MapLibre.