MAOS.git
Publicgit clone https://git.maproj.org/MAOS.gitMAOS.git / IMPLEMENTATION_README.md
| 1 | # MAOS — Implementation & Build Guide |
| 2 | |
| 3 | > This is the implementation and build documentation for MAOS. For a user-facing overview and |
| 4 | > install instructions, see **[README.md](README.md)**. |
| 5 | |
| 6 | A GrapheneOS-derived Android OS that ships the [Modern Apps](https://github.com/vayun-mathur) |
| 7 | ecosystem (`com.vayunmathur.*`) in place of the stock GrapheneOS/AOSP userspace apps. |
| 8 | |
| 9 | This repository is the **overlay** — the single repo you maintain. It is added to a |
| 10 | GrapheneOS source tree at `vendor/modern-apps/` via a `repo` local manifest. There are |
| 11 | **no long-lived AOSP forks**: additions, removals, and config are all expressed as |
| 12 | overlays. (Full design rationale lives in `GRAPHENEOS_FORK_PLAN.md` in the Modern-Apps |
| 13 | repo.) |
| 14 | |
| 15 | ## Apps swapped |
| 16 | |
| 17 | | Modern App | Package | Replaces | |
| 18 | | --- | --- | --- | |
| 19 | | Web | `com.vayunmathur.web` | Vanadium (browser only; WebView kept) | |
| 20 | | Camera | `com.vayunmathur.camera` | GrapheneOS Camera | |
| 21 | | PDF | `com.vayunmathur.pdf` | PdfViewer | |
| 22 | | Contacts | `com.vayunmathur.contacts` | AOSP Contacts | |
| 23 | | Calculator | `com.vayunmathur.calculator` | AOSP Calculator | |
| 24 | | Clock | `com.vayunmathur.clock` | AOSP DeskClock | |
| 25 | | Files | `com.vayunmathur.files` | **DocumentsUI** (Files also takes over the SAF role — see below) | |
| 26 | | Photos | `com.vayunmathur.photos` | AOSP Gallery | |
| 27 | | App Store | `com.vayunmathur.appstore` | GrapheneOS Apps | |
| 28 | | Keyboard | `com.vayunmathur.keyboard` | AOSP LatinIME (Direct Boot-aware for lock-screen input) | |
| 29 | | Speech | `com.vayunmathur.speech` | GrapheneOS SpeechServices (default STT + TTS) | |
| 30 | | Calendar | `com.vayunmathur.calendar` | AOSP Calendar (uses system CalendarProvider) | |
| 31 | | Music | `com.vayunmathur.music` | AOSP Music (incl. popup single-file player) | |
| 32 | | Communicate | `com.vayunmathur.communicate` | AOSP Dialer **and** Messaging (default dialer + SMS app) | |
| 33 | | Euicc | `com.vayunmathur.euicc` | Google's eSIM LPA **EuiccGoogle** (system LPA; Pixel `EuiccSupportPixel` backend kept — see below) | |
| 34 | | Backup | `com.vayunmathur.backup` | **Seedvault** (`com.stevesoltys.seedvault`) **and** the GrapheneOS contacts backup transport (`app.grapheneos.backup.contacts`) — system app-data backup transport; see below | |
| 35 | | Emergency | `com.vayunmathur.emergency` | AOSP EmergencyInfo (medical info + contacts + SOS countdown; wireless alerts stay stock CellBroadcast) | |
| 36 | | Parental Controls | `com.vayunmathur.parentalcontrols` | n/a (new; AOSP has no supervision app) — system supervision app: bedtime + app limits via the SYSTEM_SUPERVISION role (pinned by `config_systemSupervision`) | |
| 37 | | Screen Time | `com.vayunmathur.screentime` | n/a (new; AOSP has no wellbeing app) — self-managed screen time: dashboard, timers, focus, wind-down via the SYSTEM_WELLBEING role (pinned by `config_systemWellbeing`) | |
| 38 | | Auto | `com.vayunmathur.auto` | n/a (new) — SYSTEM_AUTOMOTIVE_PROJECTION role holder (Android Auto projection) | |
| 39 | | Network Location | `com.vayunmathur.networklocation` | GrapheneOS NetworkLocation — network location provider + offline geocoder | |
| 40 | | Find Family | `com.vayunmathur.findfamily` | n/a (new) — family location sharing (ordinary user app, preinstalled) | |
| 41 | | Share | `com.vayunmathur.share` | n/a (new) — AirDrop-compatible sharing (privileged for the Mosey/AWDL HAL) | |
| 42 | | Cast | `com.vayunmathur.cast` | n/a (new) — Cast / remote-display provider | |
| 43 | | Setup Wizard | `com.vayunmathur.setupwizard` | GrapheneOS SetupWizard2 (first-run setup; see Android.bp warning) | |
| 44 | | Log Viewer | `com.vayunmathur.logviewer` | GrapheneOS LogViewer (error-report viewer, no launcher entry) | |
| 45 | | Updater | `com.vayunmathur.updater` | GrapheneOS Updater (`overrides`) — polls `ro.maos.ota.server`; see `updater/` | |
| 46 | | Health | `com.vayunmathur.health` | n/a (new) — health metrics/medications (ordinary user app, preinstalled) | |
| 47 | |
| 48 | ## Layout |
| 49 | |
| 50 | ``` |
| 51 | Android.bp # android_app_import per app (Files: privileged) |
| 52 | modern_apps.mk # product config: app membership notes, RRO, privapp; branding |
| 53 | maos_branding.mk # PRODUCT_* + ro.maos.* identity (inherited by modern_apps.mk) |
| 54 | privapp-permissions-modern-apps.xml # signature|privileged allowlists for the 12 priv-apps |
| 55 | rro/MaosFrameworkResRRO/ # static platform-signed framework-res RRO (config_* pins) |
| 56 | prebuilts/ # release APKs (git-ignored; populated by script) |
| 57 | scripts/collect-apks.sh # copies Modern-Apps release APKs into prebuilts/ |
| 58 | keys/generate-keys.sh # generates the OS key set (offline; never committed) |
| 59 | ota/ # OTA flow notes (pipeline lives in build-maos.sh) |
| 60 | installer/ # prepare-factory.sh + sparse_split.py for the web installer |
| 61 | updater/ # MA Updater: server URL via ro.maos.ota.server |
| 62 | docs/BUILD_RUNBOOK.md # end-to-end Linux build/sign/OTA/publish |
| 63 | local_manifest.xml # adds this repo to the GrapheneOS tree |
| 64 | ``` |
| 65 | |
| 66 | ## Usage |
| 67 | |
| 68 | 1. Set up a GrapheneOS build environment and choose a release branch. |
| 69 | 2. Before `repo sync`, symlink the local manifest: |
| 70 | ```bash |
| 71 | mkdir -p .repo/local_manifests |
| 72 | ln -s /path/to/MAOS/local_manifest.xml .repo/local_manifests/modern-apps.xml |
| 73 | repo sync |
| 74 | ``` |
| 75 | This lands the overlay at `vendor/modern-apps/`. |
| 76 | 3. Inherit the product config **last** in your device makefile |
| 77 | (`device/.../aosp_<device>.mk`): |
| 78 | ```make |
| 79 | $(call inherit-product, vendor/modern-apps/modern_apps.mk) |
| 80 | ``` |
| 81 | 4. Populate the prebuilt APKs (build them from Modern-Apps first): |
| 82 | ```bash |
| 83 | vendor/modern-apps/scripts/collect-apks.sh /path/to/Modern-Apps |
| 84 | ``` |
| 85 | 5. Generate OS signing keys (offline), build, sign, and rebrand — full sequence in |
| 86 | **[`docs/BUILD_RUNBOOK.md`](docs/BUILD_RUNBOOK.md)**. You cannot ship as "GrapheneOS". |
| 87 | |
| 88 | ## Notes |
| 89 | |
| 90 | - **Vanadium stays installed** as the system WebView provider; only the default *browser* |
| 91 | role moves to Web (via `config_defaultBrowser`). Our Web app relies on system WebView. |
| 92 | - **Files absorbs DocumentsUI.** DocumentsUI is the system Storage Access Framework (SAF) |
| 93 | picker (`OPEN_DOCUMENT` / `CREATE_DOCUMENT` / `OPEN_DOCUMENT_TREE` / `GET_CONTENT`), not |
| 94 | just a file manager. Removing it requires Files to take over that role **in the system |
| 95 | build only**: |
| 96 | - `config_documentsUiPackage` is overlaid to `com.vayunmathur.files`. |
| 97 | - Files ships as a **priv-app** holding `MANAGE_DOCUMENTS` (see the privapp allowlist). |
| 98 | - The SAF picker is implemented in the Files app (Modern-Apps repo) as a |
| 99 | `DocumentPickerActivity`. It is the **same APK** as the F-Droid build — no separate flavor. The |
| 100 | picker component ships disabled and a small `Application` enables it only when `MANAGE_DOCUMENTS` |
| 101 | is granted (i.e. only in MAOS), so the userspace Files app is unchanged. |
| 102 | - **Euicc is the eSIM LPA.** Modern Apps Euicc replaces Google's LPA app **EuiccGoogle** |
| 103 | (`com.google.android.euicc`) and its companion RRO **EuiccGoogleOverlay**. It ships as a |
| 104 | **priv-app** declaring `android.service.euicc.EuiccService`; with the Google LPA removed it is the |
| 105 | sole app resolving that intent with `WRITE_EMBEDDED_SUBSCRIPTIONS`, so the framework selects it as |
| 106 | the LPA automatically (no config pin). Its privileged perms (`WRITE_EMBEDDED_SUBSCRIPTIONS`, |
| 107 | `MODIFY_PHONE_STATE`, `READ_PRIVILEGED_PHONE_STATE`) are in the privapp allowlist. Only the LPA |
| 108 | *app* is swapped — the proprietary Pixel backend **`EuiccSupportPixel`** (`com.google.euiccpixel`) |
| 109 | and the modem firmware are **kept**, since they provide the low-level access to the built-in eUICC. |
| 110 | - **Backup is the app-data backup transport.** Modern Apps Backup replaces GrapheneOS's |
| 111 | **Seedvault** (`com.stevesoltys.seedvault`) and the GrapheneOS contacts backup transport |
| 112 | (`app.grapheneos.backup.contacts`), both removed in `modern_apps.mk`. It ships as a **priv-app** |
| 113 | declaring `android.app.backup.BackupTransport` via a service with the `android.backup.TRANSPORT_HOST` |
| 114 | intent-filter (gated by the system-only `BIND_BACKUP_TRANSPORT`), and is pinned as the default |
| 115 | transport via `config_backup_transport` in the RRO. Its privileged perms (`BACKUP` to act as a |
| 116 | transport, `WRITE_SECURE_SETTINGS` to activate itself) are in the privapp allowlist. Backups are |
| 117 | encrypted end-to-end with a **BIP-39** recovery code and written to a SAF folder or a |
| 118 | WebDAV/Nextcloud remote, so there is no separate account/content-provider backend to keep. |
| 119 | - **APKs are `presigned`** so each keeps its `com.vayunmathur` certificate, preserving the |
| 120 | app-store update chain. The *OS* is signed with your own platform keys. |
| 121 | - **Silent-breakage guard:** `modern_apps.mk` fails the build if any stock module we meant |
| 122 | to drop is still present in `PRODUCT_PACKAGES` (guards against upstream renames). |
| 123 | - Alternative to `filter-out`: AOSP's `overrides:` field on `android_app_import` also |
| 124 | removes a named module. We use `filter-out` for a single, explicit removal list. |
| 125 | |
| 126 | |
| 127 | ## Remote device attestation (one-time, the Auditor model) |
| 128 | |
| 129 | Server-verified hardware attestation lives in two places: |
| 130 | |
| 131 | - **Server** (`location_share_server`, `src/handlers/attest.rs`, served on |
| 132 | `api.maproj.org` under `/attest/v1/*`, with the public result page at |
| 133 | `https://maproj.org/attest`): verifies the Android hardware attestation |
| 134 | certificate chain up to Google's hardware attestation root (embedded; |
| 135 | that Google-root dependency is unavoidable for Pixel hardware |
| 136 | attestation), parses the KeyDescription extension, checks the single-use |
| 137 | server nonce (300 s expiry, consumed on first use) — issued only for a |
| 138 | live session started at `maproj.org/attest` and bound to that session, |
| 139 | so a precomputed chain from another session cannot pass — and checks |
| 140 | the RootOfTrust says Verified with the device locked. That is the whole |
| 141 | verdict: there is no enrollment, no allowlist, no approval, and no |
| 142 | persistent device identity or history — any device presenting valid |
| 143 | hardware evidence gets a verdict. A submit returns one ephemeral result |
| 144 | plus a `verificationId` / `userCode` / `verifyUrl`; the result attaches |
| 145 | to the initiating session's page and the `userCode` stays a read-only |
| 146 | receipt (short code expires in 15 minutes, the stored result within |
| 147 | hours). Rate limiting is abuse |
| 148 | control only, not permission. `ATTEST_STATUS_TOKEN` still gates the |
| 149 | diagnostics status endpoint, and the `/c_password123/attest` console is |
| 150 | a read-only recent-results view. |
| 151 | - **Device** (`patches/packages_apps_Settings_maos_attestation.patch`, |
| 152 | applied by `build-maos.sh`): Settings > Security & privacy > Device |
| 153 | attestation (on the SecuritySettings dashboard, above More security |
| 154 | settings). One-off and user-triggered only — a "Verify" action; |
| 155 | there is no periodic, scheduled, or on-boot verification. The screen |
| 156 | takes the session shown at `maproj.org/attest` — Scan QR (SettingsLib |
| 157 | QrCamera, the Wi-Fi DPP scanner path) or, as a fallback, type/paste |
| 158 | the session code into the Session code field; each Verify sends that |
| 159 | code with its |
| 160 | challenge request and submit, generates a fresh hardware key (StrongBox |
| 161 | where available, TEE otherwise, labelled from the server's chain |
| 162 | reading) in AndroidKeyStore with the session-bound server challenge, |
| 163 | and submits its chain once. When it completes, |
| 164 | the screen keeps the last server verdict and shows "See your |
| 165 | verification: maproj.org/attest — code XXXX" with the full URL (tapping |
| 166 | it opens the page). The status shown is always the server's verdict |
| 167 | from its last response, never a local self-check (which a compromised |
| 168 | OS could lie about). A compromised OS cannot fake a Verified/locked |
| 169 | RootOfTrust or the verified-boot key; it can only refuse, delay, or |
| 170 | attest a good state and compromise itself afterwards — attestation is |
| 171 | a point-in-time verdict. |
| 172 | |
| 173 | No owner steps are needed before a real device can pass: attestation is |
| 174 | open to any user. No on-device verification was performed for this |
| 175 | implementation (no device available); the Settings patch was verified |
| 176 | with `git apply --check` / apply / reverse on the pristine Settings |
| 177 | files, and the server with `cargo test` using a generated fixture chain. |
| 178 | |
| 179 | ## OTA |
| 180 | |
| 181 | MAOS uses the standard A/B OTA flow (`update_engine`) with updates served from |
| 182 | **`https://ota.maproj.org`**, a **Cloudflare R2 bucket** exposed via a custom |
| 183 | domain. The build host uploads signed OTA zips + channel metadata straight to R2 |
| 184 | (the `publish` phase of `build-maos.sh`), and devices download directly from R2 — no GitHub |
| 185 | Release and no server proxy, since the payloads are multi-GB. The OTA flow is documented in |
| 186 | [`ota/`](ota/README.md); how the MA Updater finds the server is covered in |
| 187 | [`updater/`](updater/README.md). Full design rationale is in `GRAPHENEOS_FORK_PLAN.md` |
| 188 | (Modern-Apps repo). |
| 189 | |
| 190 | ## Web installer |
| 191 | |
| 192 | `https://ma.vayunmathur.com/os/install` is a browser-based WebUSB flasher (like |
| 193 | GrapheneOS's `/install/web`) — flash MAOS to a Pixel with no command-line tools. The static |
| 194 | front-end lives in the `location_share_server` repo (`os_installer/`); the build-host side |
| 195 | (turning a factory image into the manifest + images it flashes, and uploading to R2) is in |
| 196 | [`installer/`](installer/README.md). Requires a Chromium desktop browser and an R2 CORS |
| 197 | policy allowing `https://ma.vayunmathur.com`. |
| 198 | |
| 199 | ## Base rebases |
| 200 | |
| 201 | ### 2026080500 → 2026110700 (`d4c1a74`) |
| 202 | |
| 203 | - Only `patches/frameworks_base.patch` needed regenerating: the `config_ext.xml` |
| 204 | hunk re-anchored (`@@ -51,4` → `@@ -58,4`) after upstream appended new |
| 205 | `setting_default_display_color_mode` + `setting_default_allow_clipboard_read` |
| 206 | entries at the end of the file. MAOS content is identical — the first-party |
| 207 | store stays `com.vayunmathur.appstore`. |
| 208 | - App list unchanged: 23 repos removed upstream, all unused Car/TV leftovers none |
| 209 | of which MAOS marks, so `sensor-optout.list` is untouched (the rebase touches |
| 210 | only `build-maos.sh` and `frameworks_base.patch`). |
| 211 | - Upstream behavior deltas to know at the next rebase (hashes are upstream |
| 212 | `~/maos` commits, not re-verified in this repo): |
| 213 | 1. `LocationRequest`/`LastLocationRequest.setCoarse()` coarsened-location API |
| 214 | (upstream `138e17945`; GmsCompat `10f829b` adopted it). |
| 215 | 2. Hibernation exemption set `HIBERNATION_EXEMPT_SYSTEM_PACKAGES` (upstream |
| 216 | `1539b4b9d7`); our store is NOT in it — separate patch in flight. |
| 217 | 3. Secure-paste clipboard policy + per-app toggle (upstream `96d35a691c41`, |
| 218 | default-allow). |
| 219 | 4. Contact Scopes calling-app identity (upstream `4196e9c2`). |
| 220 | 5. Sensors permission now implicitly added via `addImplicitPermission` with a |
| 221 | `hasCode=false` skip (upstream `b1fc9e346db3`); our `SENSORS_OPTOUT` |
| 222 | exemption lives in our own patch. |