Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / appstore / AGENTS.md

AGENTS.md13.4 KiBRenderedCodeRaw
1# AGENTS.md — appstore/ (':appstore')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `appstore/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install appstore (dev by default)._
6- Gradle: :appstore / dir: appstore/
7- Package roots present: ui, data, domain, platform, intents, sync
8- Entry files: MainActivity.kt (sole phone/TV launcher; routes watches to WearMainActivity), Route.kt (home/library/search/sources/updates tabs + Detail/Browse/Screenshots/UninstallDialog pushed routes), ui/WearMainActivity.kt
9- Deps: :library:room, :library:network, :library:work, :library:image, :library:tv, :library:wearlink, :library:log, Wear Compose (material + foundation)
10- Metadata: metadata_data/appstore.md (present)
11- Rust: yes / screenshotTest: yes
12
13## Overview
14**Purpose:** Security-first app store — six sources (own repo, curated mirror, F-Droid, GrapheneOS, Accrescent, Play) with every download signature-checked and a plain-language security tier per app (who could push a malicious update).
15**Key features:**
16- Multi-source catalogs: F-Droid (developer-signed reproducible builds only — apps signed with an F-Droid-held per-app key are never imported), Accrescent (Signify trust), anonymous Play (no Google account), GrapheneOS bundle one-tap
17- Top filters filter by source (search/library) or category (home); there is no TV filter chip — catalogue results are limited to TV-compatible apps only when the device itself is a TV (`DeviceAttributesProvider.isTv`, applied by `CatalogRepository` on every read)
18- Install pipeline: `InstallCoordinator` → `SessionInstaller` → `InstallStatusReceiver`, verified by `InstallVerifier` (APK certs, signed-jar index, source stamps) before the system installer sees anything
19- `UpdateCheckWorker` background checks; outdated-target-API apps refused, not hidden
20- OpenAssistant tools (read-only, in `intents/` behind the signature `ACCESS_APPSTORE` permission): `appstore_search_apps` searches the local catalogue (query, limit clamped to 10, summary capped at 120 chars) and `appstore_get_updates` returns an update count plus at most 10 app names; no install/update/uninstall action is exposed
21**Architecture / data-flow:** `ui/` home/search/detail/library/updates/sources (+ `ui/dialogs/` stateless dialog contents for the `Route.UninstallDialog` / TV `UninstallDialog` routes) → `platform/AppStoreViewModel` (+ per-area `*Ops`, `AppStoreUiContract`) → `data/` providers per source (`*Repository`, Play/F-Droid/Accrescent clients) + `data/installer/` + `data/security/`; `domain/SearchRanking` is pure ranking. The F-Droid provider additionally downloads the same repo's signed `index-v1.jar` (`FDroidAllowedSigners` in `data/FDroidVerification.kt`, verified against the descriptor's pinned fingerprint and streamed, not loaded whole) and drops every F-Droid app whose advertised version signer is not one of that package's `allowedAPKSigningKeys` before any row is written — index-v2 alone cannot tell a developer key from an F-Droid-generated per-app key. That gate is F-Droid-only; the other F-Droid-format repos keep their own trust rules.
22**Repo addresses:** our own F-Droid-format repos are consumed from the static R2 bucket — `DefaultRepos.MODERN_APPS` = `https://static.maproj.org/fdroid/repo`, `DefaultRepos.PROPRIETARY` = `https://static.maproj.org/proprietary/repo` (same signed indexes/APKs the server publishes on every build; signing fingerprint pinned as before). The legacy origin addresses (`maproj.org/fdroid/repo`, `maproj.org/proprietary/repo`) keep serving external F-Droid clients and are named only as `LEGACY_*_ORIGIN_URL` constants: stored repo records and cached rows are keyed by URL, so `CatalogRepository.ensureDefaultRepos` prunes rows written under the old addresses and the next sync re-imports under the static ones (no double-added repos).
23**Entry points + reading order:** `MainActivity.kt` → `Route.kt` → `ui/AppRoot.kt` → `ui/HomePage.kt` → `platform/AppStoreViewModel.kt` → `data/CatalogRepository.kt` → `data/installer/InstallCoordinator.kt` → `data/security/InstallVerifier.kt`.
24## One APK, three form factors (phone + TV + watch)
25This module is the single App Store APK for phones, TVs and watches: same
26`applicationId = "com.vayunmathur.appstore"` and signing on all three, as the
27conduit signature check requires. The manifest deliberately declares no
28`android.hardware.type.watch` feature (required=true would block
29phones; required=false is disallowed for this feature), plus
30leanback/touchscreen not-required and
31`com.google.android.wearable.standalone=false`; distribution is
32sideload/F-Droid, not Play's watch channel, so the APK installs on
33phones, TVs and watches alike. `platform/FormFactor.kt`
34reads `PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the
35sole phone/TV launcher entry) forwards watches to `ui/WearMainActivity`
36before any phone state loads; phones/TVs get the store UI (TV via
37`ui/tv/TvMainActivity`). Form-factor receivers gate the same way —
38`data/installer/InstallStatusReceiver` (phone/TV) and
39`platform/InstallResultReceiver` (watch) each early-return on the wrong
40form factor.
41
42## Wear sync (Watch conduit client)
43**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.appstore.WearSyncProtocol`; the golden-JSON test in `domain/WearSyncProtocolTest` pins the shared code's wire format.
44- Catalog + watch-state sync: conduit data items (`/appstore/catalog`, `/appstore/watch-state`)
45- Offers / install requests / results: conduit messages; APK bytes: conduit stream (`/appstore/apk/<package>`), verified size+SHA-256 against the preceding offer before PackageInstaller ever sees them
46- **Transport: Watch conduit client** — phone side `sync/WearSyncManager` and watch side `sync/WearLinkBridge` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `appstore`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reports `NotInstalled`/`Unavailable` and the sync stays idle; the catalog and watch state republish on conduit `Connected`. Catalog delivery is app-lifecycle-bound, but the watch open-on-phone request is not: `sync/OpenOnPhoneReceiver` (manifest, `CONDUIT` signature permission) launches the main activity when the conduit host broadcasts it for an app with no live registration. `FormFactor` picks the side at runtime.
47
48## Watch experience (in this module)
49- `ui/WearMainActivity` (a `WearShellActivity`, `exported=false`, entered only via `MainActivity`'s watch routing) is the whole watch store: one scrolling catalog/install list reading only the watch's persisted state, so it works standalone with whatever has already been downloaded.
50- Watch state persists in `data/WearStore` (`wear-catalog.json` / `wear-phases.json`, verified APKs under `wear-apks/`); `platform/WearInstaller` hands a verified APK to PackageInstaller and `platform/InstallResultReceiver` forwards the system prompt and reports the verdict.
51- A normal Wear OS app **cannot silently install**: verified APKs wait in app-private storage until the wearer taps Install and confirms the system PackageInstaller prompt. No state may claim otherwise.
52- Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:appstore:metadata` into `metadata_data/photos/appstore/wear/`; phone shots use the `phone` bucket.
53
54**Gotchas:**
55- Signature verification is the product — never shortcut it for UX; trust-profile changes need adversarial review
56- Anonymous Play auth sessions are fragile by nature; isolate Play failures from other sources
57- Upgrades from app versions before v2.6.0 start fresh: the `AppDatabase` floor is DB v3 (the first AppStore database shipped, in app v2.6.4, so no released pre-v2.6.0 database exists), pre-floor DB v1–v2 opens destructively (no data carried over), and DB v3 onward migrates normally
58
59## Key files
60### Root — entry
61- com/vayunmathur/appstore/MainActivity.kt
62- com/vayunmathur/appstore/Route.kt
63### data/ — catalog, providers, installer, security
64- com/vayunmathur/appstore/data/CatalogRepository.kt
65- com/vayunmathur/appstore/data/AppProvider.kt
66- com/vayunmathur/appstore/data/AppModels.kt
67- com/vayunmathur/appstore/data/AppDatabase.kt
68- com/vayunmathur/appstore/data/AppStoreDatabaseRepository.kt
69- com/vayunmathur/appstore/data/AppStoreDbBackupCodec.kt — backup codec: SQLCipher plaintext round-trip with the re-derivable CachedAppEntity catalogue stripped (repos, stamp pins and Accrescent allowlist survive)
70- com/vayunmathur/appstore/platform/AppBackupAgent.kt — key/value BackupAgent (DB via the codec + appstore-settings/accrescent_repodata DataStores; play_auth, all SharedPreferences and wear files excluded); raw DB excluded in res/xml/data_extraction_rules.xml on both channels
71- com/vayunmathur/appstore/data/InstalledAppsRepository.kt
72- com/vayunmathur/appstore/data/SettingsRepository.kt
73- com/vayunmathur/appstore/data/UpdateCheckWorker.kt
74- com/vayunmathur/appstore/data/FDroidRepository.kt
75- com/vayunmathur/appstore/data/FDroidAppProvider.kt
76- com/vayunmathur/appstore/data/FDroidVerification.kt
77- com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt
78- com/vayunmathur/appstore/data/accrescent/AccrescentRepo.kt
79- com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.kt
80- com/vayunmathur/appstore/data/accrescent/AccrescentApi.kt
81- com/vayunmathur/appstore/data/accrescent/AccrescentTrustStore.kt
82- com/vayunmathur/appstore/data/accrescent/DeviceAttributesProvider.kt
83- com/vayunmathur/appstore/data/accrescent/SignifyNative.kt — Rust Signify bridge
84- com/vayunmathur/appstore/data/play/PlayRepository.kt
85- com/vayunmathur/appstore/data/play/PlayStoreApi.kt
86- com/vayunmathur/appstore/data/play/PlayHttpClient.kt
87- com/vayunmathur/appstore/data/play/AnonymousAuthRepository.kt
88- com/vayunmathur/appstore/data/play/DeviceInfoProvider.kt
89- com/vayunmathur/appstore/data/play/GsfVersionProvider.kt
90- com/vayunmathur/appstore/data/play/EglExtensionProvider.kt
91- com/vayunmathur/appstore/data/play/CertUtil.kt
92- com/vayunmathur/appstore/data/play/PlayDownloader.kt
93- com/vayunmathur/appstore/data/installer/InstallCoordinator.kt
94- com/vayunmathur/appstore/data/installer/SessionInstaller.kt
95- com/vayunmathur/appstore/data/installer/InstallStatusReceiver.kt
96- com/vayunmathur/appstore/data/security/InstallVerifier.kt
97- com/vayunmathur/appstore/data/security/ApkCertificates.kt
98- com/vayunmathur/appstore/data/security/SignedJarIndex.kt
99- com/vayunmathur/appstore/data/security/SourceStamp.kt
100- com/vayunmathur/appstore/data/security/TrustProfile.kt
101- com/vayunmathur/appstore/data/security/Signify.kt
102- com/vayunmathur/appstore/data/PlayStoreLinks.kt
103- com/vayunmathur/appstore/data/RestrictedPackages.kt
104### intents/ — validated OpenAssistant contracts (read-only)
105- com/vayunmathur/appstore/intents/SearchAppsIntent.kt
106- com/vayunmathur/appstore/intents/GetUpdatesIntent.kt
107- com/vayunmathur/appstore/intents/AppStoreAssistantBackend.kt — backend seam over `CatalogRepository.searchLocal`/`updatesFor` + the provider-side caps
108### domain/ — pure ranking (no Android)
109- com/vayunmathur/appstore/domain/SearchRanking.kt
110### sync/ — wear sync (both sides)
111- com/vayunmathur/appstore/sync/WearSyncManager.kt — phone side: catalog publish, APK offer/stream, install requests
112- com/vayunmathur/appstore/sync/WearLinkBridge.kt — watch side: catalog/offer/stream receive, watch-state publish, install results
113### platform/ — ViewModel + per-area ops
114- com/vayunmathur/appstore/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)
115- com/vayunmathur/appstore/platform/AppStoreViewModel.kt
116- com/vayunmathur/appstore/platform/AppStoreUiContract.kt
117- com/vayunmathur/appstore/platform/AppStoreHomeOps.kt
118- com/vayunmathur/appstore/platform/AppStoreSearchOps.kt
119- com/vayunmathur/appstore/platform/AppStoreDetailOps.kt
120- com/vayunmathur/appstore/platform/AppStoreUpdateOps.kt
121- com/vayunmathur/appstore/platform/AppStoreActionOps.kt
122### ui/ — store pages
123- com/vayunmathur/appstore/ui/HomePage.kt
124- com/vayunmathur/appstore/ui/SearchPage.kt
125- com/vayunmathur/appstore/ui/AppDetailPage.kt
126- com/vayunmathur/appstore/ui/AppDetailHeader.kt
127- com/vayunmathur/appstore/ui/AppDetailSections.kt
128- com/vayunmathur/appstore/ui/ScreenshotViewerScreen.kt — full-screen swipe/zoom screenshot viewer (`Route.Screenshots`)
129- com/vayunmathur/appstore/ui/AppTile.kt
130- com/vayunmathur/appstore/ui/AppComponents.kt
131- com/vayunmathur/appstore/ui/AppMeta.kt
132- com/vayunmathur/appstore/ui/LibraryPage.kt
133- com/vayunmathur/appstore/ui/UpdatesPage.kt
134- com/vayunmathur/appstore/ui/SourcesPage.kt
135- com/vayunmathur/appstore/ui/SourcesScreen.kt — stateless sources screen (previews/tests)
136- com/vayunmathur/appstore/ui/dialogs/UninstallDialog.kt — `Route.UninstallDialog` content
137- com/vayunmathur/appstore/ui/dialogs/TvUninstallDialog.kt — TV `UninstallDialog` content
138### Watch experience (ui/ + platform/ + data/)
139- com/vayunmathur/appstore/ui/WearMainActivity.kt — watch entry (WearShellActivity, `exported=false`)
140- com/vayunmathur/appstore/platform/WearInstaller.kt — verified-APK PackageInstaller handoff (user confirmation required)
141- com/vayunmathur/appstore/platform/InstallResultReceiver.kt — watch PackageInstaller verdicts (gated to watches)
142- com/vayunmathur/appstore/data/WearStore.kt — watch catalog/phases/APK store
143
144## Verify (this module only)
145```
146./gradlew :appstore:compileDevKotlin
147./gradlew :appstore:lint
148./gradlew :appstore:checkMetadata
149```