maos: fix cast bootloop NPE, drop external camera, split README
- Commit
46162d5cc820691b2719d005da7daa462abedff0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-09-10 01:09 UTC (2 months ago)
- Parents
abaeb60
Diff
IMPLEMENTATION_README.md
diff --git a/IMPLEMENTATION_README.md b/IMPLEMENTATION_README.mdnew file mode 100755index 0000000..f91355f--- /dev/null+++ b/IMPLEMENTATION_README.md@@ -0,0 +1,134 @@+# MAOS — Implementation & Build Guide++> This is the implementation and build documentation for MAOS. For a user-facing overview and+> install instructions, see **[README.md](README.md)**.++A GrapheneOS-derived Android OS that ships the [Modern Apps](https://github.com/vayun-mathur)+ecosystem (`com.vayunmathur.*`) in place of the stock GrapheneOS/AOSP userspace apps.++This repository is the **overlay** — the single repo you maintain. It is added to a+GrapheneOS source tree at `vendor/modern-apps/` via a `repo` local manifest. There are+**no long-lived AOSP forks**: additions, removals, and config are all expressed as+overlays. (Full design rationale lives in `GRAPHENEOS_FORK_PLAN.md` in the Modern-Apps+repo.)++## Apps swapped++| Modern App | Package | Replaces |+| --- | --- | --- |+| Web | `com.vayunmathur.web` | Vanadium (browser only; WebView kept) |+| Camera | `com.vayunmathur.camera` | GrapheneOS Camera |+| PDF | `com.vayunmathur.pdf` | PdfViewer |+| Contacts | `com.vayunmathur.contacts` | AOSP Contacts |+| Calculator | `com.vayunmathur.calculator` | AOSP Calculator |+| Clock | `com.vayunmathur.clock` | AOSP DeskClock |+| Files | `com.vayunmathur.files` | **DocumentsUI** (Files also takes over the SAF role — see below) |+| Photos | `com.vayunmathur.photos` | AOSP Gallery |+| App Store | `com.vayunmathur.appstore` | GrapheneOS Apps |+| Keyboard | `com.vayunmathur.keyboard` | AOSP LatinIME (Direct Boot-aware for lock-screen input) |+| Speech | `com.vayunmathur.speech` | GrapheneOS SpeechServices (default STT + TTS) |+| Calendar | `com.vayunmathur.calendar` | AOSP Calendar (uses system CalendarProvider) |+| Music | `com.vayunmathur.music` | AOSP Music (incl. popup single-file player) |+| Communicate | `com.vayunmathur.communicate` | AOSP Dialer **and** Messaging (default dialer + SMS app) |+| Euicc | `com.vayunmathur.euicc` | Google's eSIM LPA **EuiccGoogle** (system LPA; Pixel `EuiccSupportPixel` backend kept — see below) |+| 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 |++## Layout++```+Android.bp # android_app_import per app (Files: privileged)+modern_apps.mk # PRODUCT_PACKAGES += ours; filter-out stock; overlays; privapp; branding+maos_branding.mk # PRODUCT_* + ro.maos.* identity (inherited by modern_apps.mk)+privapp-permissions-modern-apps.xml # MANAGE_DOCUMENTS for Files+overlay/ # static overlays+ frameworks/base/.../config.xml # config_defaultBrowser, config_documentsUiPackage+ packages/apps/Updater/.../config.xml # OTA server URL (verify resource name)+prebuilts/ # release APKs (git-ignored; populated by script)+scripts/collect-apks.sh # copies Modern-Apps release APKs into prebuilts/+keys/generate-keys.sh # generates the OS key set (offline; never committed)+ota/ # build-ota.sh + publish-ota.sh (+ README)+installer/ # prepare-factory.sh + sparse_split.py for the web installer+updater/ # how to point the Updater at ota.ma.vayunmathur.com+docs/BUILD_RUNBOOK.md # end-to-end Linux build/sign/OTA/publish+local_manifest.xml # adds this repo to the GrapheneOS tree+```++## Usage++1. Set up a GrapheneOS build environment and choose a release branch.+2. Before `repo sync`, symlink the local manifest:+ ```bash+ mkdir -p .repo/local_manifests+ ln -s /path/to/MAOS/local_manifest.xml .repo/local_manifests/modern-apps.xml+ repo sync+ ```+ This lands the overlay at `vendor/modern-apps/`.+3. Inherit the product config **last** in your device makefile+ (`device/.../aosp_<device>.mk`):+ ```make+ $(call inherit-product, vendor/modern-apps/modern_apps.mk)+ ```+4. Populate the prebuilt APKs (build them from Modern-Apps first):+ ```bash+ vendor/modern-apps/scripts/collect-apks.sh /path/to/Modern-Apps+ ```+5. Generate OS signing keys (offline), build, sign, and rebrand — full sequence in+ **[`docs/BUILD_RUNBOOK.md`](docs/BUILD_RUNBOOK.md)**. You cannot ship as "GrapheneOS".++## Notes++- **Vanadium stays installed** as the system WebView provider; only the default *browser*+ role moves to Web (via `config_defaultBrowser`). Our Web app relies on system WebView.+- **Files absorbs DocumentsUI.** DocumentsUI is the system Storage Access Framework (SAF)+ picker (`OPEN_DOCUMENT` / `CREATE_DOCUMENT` / `OPEN_DOCUMENT_TREE` / `GET_CONTENT`), not+ just a file manager. Removing it requires Files to take over that role **in the system+ build only**:+ - `config_documentsUiPackage` is overlaid to `com.vayunmathur.files`.+ - Files ships as a **priv-app** holding `MANAGE_DOCUMENTS` (see the privapp allowlist).+ - The SAF picker is implemented in the Files app (Modern-Apps repo) as a+ `DocumentPickerActivity`. It is the **same APK** as the F-Droid build — no separate flavor. The+ picker component ships disabled and a small `Application` enables it only when `MANAGE_DOCUMENTS`+ is granted (i.e. only in MAOS), so the userspace Files app is unchanged.+- **Euicc is the eSIM LPA.** Modern Apps Euicc replaces Google's LPA app **EuiccGoogle**+ (`com.google.android.euicc`) and its companion RRO **EuiccGoogleOverlay**. It ships as a+ **priv-app** declaring `android.service.euicc.EuiccService`; with the Google LPA removed it is the+ sole app resolving that intent with `WRITE_EMBEDDED_SUBSCRIPTIONS`, so the framework selects it as+ the LPA automatically (no config pin). Its privileged perms (`WRITE_EMBEDDED_SUBSCRIPTIONS`,+ `MODIFY_PHONE_STATE`, `READ_PRIVILEGED_PHONE_STATE`) are in the privapp allowlist. Only the LPA+ *app* is swapped — the proprietary Pixel backend **`EuiccSupportPixel`** (`com.google.euiccpixel`)+ and the modem firmware are **kept**, since they provide the low-level access to the built-in eUICC.+- **Backup is the app-data backup transport.** Modern Apps Backup replaces GrapheneOS's+ **Seedvault** (`com.stevesoltys.seedvault`) and the GrapheneOS contacts backup transport+ (`app.grapheneos.backup.contacts`), both removed in `modern_apps.mk`. It ships as a **priv-app**+ declaring `android.app.backup.BackupTransport` via a service with the `android.backup.TRANSPORT_HOST`+ intent-filter (gated by the system-only `BIND_BACKUP_TRANSPORT`), and is pinned as the default+ transport via `config_backup_transport` in the RRO. Its privileged perms (`BACKUP` to act as a+ transport, `WRITE_SECURE_SETTINGS` to activate itself) are in the privapp allowlist. Backups are+ encrypted end-to-end with a **BIP-39** recovery code and written to a SAF folder or a+ WebDAV/Nextcloud remote, so there is no separate account/content-provider backend to keep.+- **APKs are `presigned`** so each keeps its `com.vayunmathur` certificate, preserving the+ app-store update chain. The *OS* is signed with your own platform keys.+- **Silent-breakage guard:** `modern_apps.mk` fails the build if any stock module we meant+ to drop is still present in `PRODUCT_PACKAGES` (guards against upstream renames).+- Alternative to `filter-out`: AOSP's `overrides:` field on `android_app_import` also+ removes a named module. We use `filter-out` for a single, explicit removal list.++## OTA++MAOS uses the standard A/B OTA flow (`update_engine`) with updates served from+**`https://ota.ma.vayunmathur.com`**, a **Cloudflare R2 bucket** exposed via a custom+domain. The build host uploads signed OTA zips + channel metadata straight to R2+(`ota/publish-ota.sh`), and devices download directly from R2 — no GitHub Release and no+server proxy, since the payloads are multi-GB. Build/publish scripts are in+[`ota/`](ota/README.md); pointing the Updater at the server is covered in+[`updater/`](updater/README.md). Full design rationale is in `GRAPHENEOS_FORK_PLAN.md`+(Modern-Apps repo).++## Web installer++`https://ma.vayunmathur.com/os/install` is a browser-based WebUSB flasher (like+GrapheneOS's `/install/web`) — flash MAOS to a Pixel with no command-line tools. The static+front-end lives in the `location_share_server` repo (`os_installer/`); the build-host side+(turning a factory image into the manifest + images it flashes, and uploading to R2) is in+[`installer/`](installer/README.md). Requires a Chromium desktop browser and an R2 CORS+policy allowing `https://ma.vayunmathur.com`.
README.md
diff --git a/README.md b/README.mdindex 658cf97..d5b4e6f 100644--- a/README.md+++ b/README.md@@ -1,131 +1,61 @@ # MAOS — Modern Apps OS -A GrapheneOS-derived Android OS that ships the [Modern Apps](https://github.com/vayun-mathur)-ecosystem (`com.vayunmathur.*`) in place of the stock GrapheneOS/AOSP userspace apps.+MAOS is a private, de-Googled Android OS for Pixel phones. It's derived from+[GrapheneOS](https://grapheneos.org) and replaces the stock system apps with the+first-party [Modern Apps](https://github.com/vayun-mathur) suite (`com.vayunmathur.*`) —+a clean, cohesive set of everyday apps built to work together. -This repository is the **overlay** — the single repo you maintain. It is added to a-GrapheneOS source tree at `vendor/modern-apps/` via a `repo` local manifest. There are-**no long-lived AOSP forks**: additions, removals, and config are all expressed as-overlays. (Full design rationale lives in `GRAPHENEOS_FORK_PLAN.md` in the Modern-Apps-repo.)+## Install -## Apps swapped+Flash MAOS straight from your browser with the WebUSB installer: -| Modern App | Package | Replaces |-| --- | --- | --- |-| Web | `com.vayunmathur.web` | Vanadium (browser only; WebView kept) |-| Camera | `com.vayunmathur.camera` | GrapheneOS Camera |-| PDF | `com.vayunmathur.pdf` | PdfViewer |-| Contacts | `com.vayunmathur.contacts` | AOSP Contacts |-| Calculator | `com.vayunmathur.calculator` | AOSP Calculator |-| Clock | `com.vayunmathur.clock` | AOSP DeskClock |-| Files | `com.vayunmathur.files` | **DocumentsUI** (Files also takes over the SAF role — see below) |-| Photos | `com.vayunmathur.photos` | AOSP Gallery |-| App Store | `com.vayunmathur.appstore` | GrapheneOS Apps |-| Keyboard | `com.vayunmathur.keyboard` | AOSP LatinIME (Direct Boot-aware for lock-screen input) |-| Speech | `com.vayunmathur.speech` | GrapheneOS SpeechServices (default STT + TTS) |-| Calendar | `com.vayunmathur.calendar` | AOSP Calendar (uses system CalendarProvider) |-| Music | `com.vayunmathur.music` | AOSP Music (incl. popup single-file player) |-| Communicate | `com.vayunmathur.communicate` | AOSP Dialer **and** Messaging (default dialer + SMS app) |-| Euicc | `com.vayunmathur.euicc` | Google's eSIM LPA **EuiccGoogle** (system LPA; Pixel `EuiccSupportPixel` backend kept — see below) |-| 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 |+**→ https://ma.vayunmathur.com/os/install** -## Layout+You'll need a supported Pixel and a Chromium-based desktop browser (Chrome, Edge). No+command-line tools required. Once installed, MAOS keeps itself up to date automatically+over the air. -```-Android.bp # android_app_import per app (Files: privileged)-modern_apps.mk # PRODUCT_PACKAGES += ours; filter-out stock; overlays; privapp; branding-maos_branding.mk # PRODUCT_* + ro.maos.* identity (inherited by modern_apps.mk)-privapp-permissions-modern-apps.xml # MANAGE_DOCUMENTS for Files-overlay/ # static overlays- frameworks/base/.../config.xml # config_defaultBrowser, config_documentsUiPackage- packages/apps/Updater/.../config.xml # OTA server URL (verify resource name)-prebuilts/ # release APKs (git-ignored; populated by script)-scripts/collect-apks.sh # copies Modern-Apps release APKs into prebuilts/-keys/generate-keys.sh # generates the OS key set (offline; never committed)-ota/ # build-ota.sh + publish-ota.sh (+ README)-installer/ # prepare-factory.sh + sparse_split.py for the web installer-updater/ # how to point the Updater at ota.ma.vayunmathur.com-docs/BUILD_RUNBOOK.md # end-to-end Linux build/sign/OTA/publish-local_manifest.xml # adds this repo to the GrapheneOS tree-```+## What's included -## Usage+MAOS ships Modern Apps in place of the stock apps, including a **Web** browser, **Camera**,+**Photos**, **PDF** viewer, **Files**, **Contacts**, **Calendar**, **Clock**, **Calculator**,+**Communicate** (calls + texts), **Music**, **Keyboard**, **Speech**, **App Store**, and+**Backup**. Everything else you expect from a GrapheneOS-based OS — the security and privacy+hardening, sandboxed Google Play compatibility, and per-app permissions — is still there. -1. Set up a GrapheneOS build environment and choose a release branch.-2. Before `repo sync`, symlink the local manifest:- ```bash- mkdir -p .repo/local_manifests- ln -s /path/to/MAOS/local_manifest.xml .repo/local_manifests/modern-apps.xml- repo sync- ```- This lands the overlay at `vendor/modern-apps/`.-3. Inherit the product config **last** in your device makefile- (`device/.../aosp_<device>.mk`):- ```make- $(call inherit-product, vendor/modern-apps/modern_apps.mk)- ```-4. Populate the prebuilt APKs (build them from Modern-Apps first):- ```bash- vendor/modern-apps/scripts/collect-apks.sh /path/to/Modern-Apps- ```-5. Generate OS signing keys (offline), build, sign, and rebrand — full sequence in- **[`docs/BUILD_RUNBOOK.md`](docs/BUILD_RUNBOOK.md)**. You cannot ship as "GrapheneOS".+## What the apps can do on MAOS -## Notes+Because MAOS ships these apps as part of the OS, several of them do things a normal+app installed from an app store simply can't: -- **Vanadium stays installed** as the system WebView provider; only the default *browser*- role moves to Web (via `config_defaultBrowser`). Our Web app relies on system WebView.-- **Files absorbs DocumentsUI.** DocumentsUI is the system Storage Access Framework (SAF)- picker (`OPEN_DOCUMENT` / `CREATE_DOCUMENT` / `OPEN_DOCUMENT_TREE` / `GET_CONTENT`), not- just a file manager. Removing it requires Files to take over that role **in the system- build only**:- - `config_documentsUiPackage` is overlaid to `com.vayunmathur.files`.- - Files ships as a **priv-app** holding `MANAGE_DOCUMENTS` (see the privapp allowlist).- - The SAF picker is implemented in the Files app (Modern-Apps repo) as a- `DocumentPickerActivity`. It is the **same APK** as the F-Droid build — no separate flavor. The- picker component ships disabled and a small `Application` enables it only when `MANAGE_DOCUMENTS`- is granted (i.e. only in MAOS), so the userspace Files app is unchanged.-- **Euicc is the eSIM LPA.** Modern Apps Euicc replaces Google's LPA app **EuiccGoogle**- (`com.google.android.euicc`) and its companion RRO **EuiccGoogleOverlay**. It ships as a- **priv-app** declaring `android.service.euicc.EuiccService`; with the Google LPA removed it is the- sole app resolving that intent with `WRITE_EMBEDDED_SUBSCRIPTIONS`, so the framework selects it as- the LPA automatically (no config pin). Its privileged perms (`WRITE_EMBEDDED_SUBSCRIPTIONS`,- `MODIFY_PHONE_STATE`, `READ_PRIVILEGED_PHONE_STATE`) are in the privapp allowlist. Only the LPA- *app* is swapped — the proprietary Pixel backend **`EuiccSupportPixel`** (`com.google.euiccpixel`)- and the modem firmware are **kept**, since they provide the low-level access to the built-in eUICC.-- **Backup is the app-data backup transport.** Modern Apps Backup replaces GrapheneOS's- **Seedvault** (`com.stevesoltys.seedvault`) and the GrapheneOS contacts backup transport- (`app.grapheneos.backup.contacts`), both removed in `modern_apps.mk`. It ships as a **priv-app**- declaring `android.app.backup.BackupTransport` via a service with the `android.backup.TRANSPORT_HOST`- intent-filter (gated by the system-only `BIND_BACKUP_TRANSPORT`), and is pinned as the default- transport via `config_backup_transport` in the RRO. Its privileged perms (`BACKUP` to act as a- transport, `WRITE_SECURE_SETTINGS` to activate itself) are in the privapp allowlist. Backups are- encrypted end-to-end with a **BIP-39** recovery code and written to a SAF folder or a- WebDAV/Nextcloud remote, so there is no separate account/content-provider backend to keep.-- **APKs are `presigned`** so each keeps its `com.vayunmathur` certificate, preserving the- app-store update chain. The *OS* is signed with your own platform keys.-- **Silent-breakage guard:** `modern_apps.mk` fails the build if any stock module we meant- to drop is still present in `PRODUCT_PACKAGES` (guards against upstream renames).-- Alternative to `filter-out`: AOSP's `overrides:` field on `android_app_import` also- removes a named module. We use `filter-out` for a single, explicit removal list.+- **Cast** — cast to a TV in **desktop mode**, using the TV as a separate, extended screen+ rather than just mirroring your phone. You get a mirror-or-desktop chooser when you connect,+ it picks the TV's best resolution automatically, and it shows up directly in+ **Settings › Cast** (no need to open the app).+- **Find Family** — locate your phone even when it's **powered off** or the battery has died,+ and see its location before the phone is unlocked.+- **Files** — is the **system file picker**: whenever any app asks you to open or save a+ file, you browse with Files, with full access to your storage.+- **Communicate** — is your default **phone and text-messaging** app, handling calls and+ SMS/MMS.+- **eSIM** — set up and manage **eSIMs** natively, built into the OS.+- **Backup** — makes **encrypted backups** of your apps and data to a folder or your own+ cloud (WebDAV/Nextcloud), protected by a recovery phrase.+- **Speech** — provides **offline** voice typing (speech-to-text) and text-to-speech to+ every app on the device.+- **Keyboard** — is available on the **lock screen** and during first-time setup. -## OTA+The remaining apps (Camera, Photos, PDF, Contacts, Calculator, Clock, Calendar, Music,+App Store, Web) are simply the built-in defaults — the same apps you'd get from the store. -MAOS uses the standard A/B OTA flow (`update_engine`) with updates served from-**`https://ota.ma.vayunmathur.com`**, a **Cloudflare R2 bucket** exposed via a custom-domain. The build host uploads signed OTA zips + channel metadata straight to R2-(`ota/publish-ota.sh`), and devices download directly from R2 — no GitHub Release and no-server proxy, since the payloads are multi-GB. Build/publish scripts are in-[`ota/`](ota/README.md); pointing the Updater at the server is covered in-[`updater/`](updater/README.md). Full design rationale is in `GRAPHENEOS_FORK_PLAN.md`-(Modern-Apps repo).+## Building it yourself / technical details -## Web installer+This repository is the build overlay applied on top of GrapheneOS, not the OS source+itself. Build instructions, the full list of app swaps, signing, and OTA details are in+**[IMPLEMENTATION_README.md](IMPLEMENTATION_README.md)**. -`https://ma.vayunmathur.com/os/install` is a browser-based WebUSB flasher (like-GrapheneOS's `/install/web`) — flash MAOS to a Pixel with no command-line tools. The static-front-end lives in the `location_share_server` repo (`os_installer/`); the build-host side-(turning a factory image into the manifest + images it flashes, and uploading to R2) is in-[`installer/`](installer/README.md). Requires a Chromium desktop browser and an R2 CORS-policy allowing `https://ma.vayunmathur.com`.+---++_This is not the source code for the OS. This is a build script, which contains a collection+of patches which are then applied to GrapheneOS. You may view all relevant source code and+licenses [here](https://github.com/grapheneos)._
camera/Android.bp
diff --git a/camera/Android.bp b/camera/Android.bpdeleted file mode 100644index a2ef19b..0000000--- a/camera/Android.bp+++ /dev/null@@ -1,18 +0,0 @@-// VINTF declaration for the AOSP external (USB/UVC) camera provider.-//-// cameraserver discovers camera providers ONLY through-// ServiceManager::getDeclaredInstances (CameraProviderManager::tryToAddAidlProvidersLocked),-// so shipping the binary without this fragment produces a running service nobody talks to.-//-// This is a standalone fragment rather than a DEVICE_MANIFEST_FILE entry so that nothing in-// the base /vendor/etc/vintf/manifest.xml is modified or reordered. shiba's own vendor-// manifest declares no camera HAL at all - internal/0 comes from the-// com.google.pixel.camera.hal APEX - so this adds an instance and displaces nothing.-//-// soc_specific installs to /vendor/etc/vintf/manifest/, matching adevtool's 39 fragments.-// The installed filename is the src basename, not the module name (vintf_fragment.go).-vintf_fragment {- name: "maos_vintf_fragment_camera_provider_external",- src: "android.hardware.camera.provider-V1-external-service.xml",- soc_specific: true,-}
camera/android.hardware.camera.provider-V1-external-service.xml
diff --git a/camera/android.hardware.camera.provider-V1-external-service.xml b/camera/android.hardware.camera.provider-V1-external-service.xmldeleted file mode 100644index cf7b21e..0000000--- a/camera/android.hardware.camera.provider-V1-external-service.xml+++ /dev/null@@ -1,10 +0,0 @@-<manifest version="1.0" type="device">- <hal format="aidl">- <name>android.hardware.camera.provider</name>- <version>1</version>- <interface>- <name>ICameraProvider</name>- <instance>external/0</instance>- </interface>- </hal>-</manifest>
camera/external_camera_config.xml
diff --git a/camera/external_camera_config.xml b/camera/external_camera_config.xmldeleted file mode 100644index 315c6ad..0000000--- a/camera/external_camera_config.xml+++ /dev/null@@ -1,45 +0,0 @@-<ExternalCamera>- <Provider>- <!-- Ignored /dev/videoN. The id is the numeric suffix of the node name as a- string (ExternalCameraProvider.cpp deviceAdded/inotify paths), NOT the minor- number. On shiba 6-11 are the MFC codec nodes (mediacodec:mediadrm, so the- HAL gets EACCES) and 12 is the JPEG device (labelled hw_jpg_device, which- hal_camera has no rule for, so it gets an avc denial). Names 0-5 are free,- which is where a hot-plugged UVC camera lands - and 0-3 are the only nodes- /vendor/etc/ueventd.rc chowns to system:camera. -->- <ignore>- <id>6</id>- <id>7</id>- <id>8</id>- <id>9</id>- <id>10</id>- <id>11</id>- <id>12</id>- </ignore>- </Provider>- <Device>- <MaxJpegBufferSize bytes="3145728"/>- <NumVideoBuffers count="4"/>- <NumStillBuffers count="2"/>- <!-- Each fpsBound is an inclusive upper-bound FILTER, not a target: any rate the- camera advertises above it is discarded, and a size whose rates are ALL- discarded is dropped from the supported-format list entirely- (ExternalCameraDevice::updateFpsBounds). So a bound that is too low removes- the resolution rather than slowing it down. The last entry also caps the- maximum supported size.-- Sizes must strictly increase and fpsBound must strictly decrease- (ExternalCameraConfig::updateFpsList) - a violation rejects the whole list- AND abandons the rest of this file, silently reverting to the built-in- defaults of [email protected] / 1080p@5. Hence 60/45/30 rather than a flat 30: it- admits 30fps at every size while satisfying the ordering rule.-- 1080p is the cap because MJPEG is decoded in software on the CPU- (libyuv::MJPGToI420 in ExternalCameraDeviceSession). -->- <FpsList>- <Limit width="640" height="480" fpsBound="60.0"/>- <Limit width="1280" height="720" fpsBound="45.0"/>- <Limit width="1920" height="1080" fpsBound="30.0"/>- </FpsList>- </Device>-</ExternalCamera>
modern_apps.mk
diff --git a/modern_apps.mk b/modern_apps.mkindex 1e17e82..105e335 100644--- a/modern_apps.mk+++ b/modern_apps.mk@@ -136,30 +136,3 @@ $(call inherit-product-if-exists, vendor/modern-apps/maos_branding.mk) # removal above, so it was always empty and never fired - which is why a build that # shipped zero MAOS apps still reported success. Removal is now a patch, and a patch # that no longer applies fails loudly in phase_overlay.--# 7. External USB (UVC) camera support, so a webcam is a real system camera visible to every-# camera2 client rather than to one app via UsbManager. Kernel support is already present-# (CONFIG_USB_VIDEO_CLASS=y) and android.hardware.usb.host is already a device feature.-#-# No sepolicy is needed. system/sepolicy/vendor/file_contexts:42 already labels-# /vendor/bin/hw/...-external-service as hal_camera_default_exec, hal_camera_default.te-# gives it a domain via init_daemon_domain, and hal_camera.te:12-13 already allows-# read/write on video_device (which /dev/video[0-9]* is labelled). The extra cameraserver-# rules the AOSP docs mention are for passthrough HIDL mode; this is a binderized AIDL-# daemon in its own domain.-#-# The non-lazy binary is deliberate: the lazy variant is oneshot+disabled and only starts-# on demand, whereas the eager one runs the inotify hotplug thread that notices a camera-# plugged in after boot. Note the lazy module `overrides` this one, so never add both.-PRODUCT_PACKAGES += \- android.hardware.camera.provider-V1-external-service \- maos_vintf_fragment_camera_provider_external--# external_camera_config.xml must be at exactly this path - it is hardcoded as-# ExternalCameraConfig::kDefaultCfgPath. The feature file also re-declares-# android.hardware.camera.any, which four already-installed-# /vendor/etc/permissions/android.hardware.camera.*.prebuilt.xml files declare too;-# SystemConfig.addFeature merges duplicates, so that is harmless.-PRODUCT_COPY_FILES += \- frameworks/native/data/etc/android.hardware.camera.external.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.external.xml \- vendor/modern-apps/camera/external_camera_config.xml:$(TARGET_COPY_OUT_VENDOR)/etc/external_camera_config.xml
patches/frameworks_base.patch
diff --git a/patches/frameworks_base.patch b/patches/frameworks_base.patchindex 6577c84..392c348 100644--- a/patches/frameworks_base.patch+++ b/patches/frameworks_base.patch@@ -1,3 +1,31 @@+diff --git a/core/api/system-current.txt b/core/api/system-current.txt+index a21a30f5b415..38bce179e9fc 100644+--- a/core/api/system-current.txt++++ b/core/api/system-current.txt+@@ -6710,6 +6710,7 @@ package android.hardware.display {+ method @RequiresPermission(android.Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS) public void setBrightnessConfigurationForDisplay(@NonNull android.hardware.display.BrightnessConfiguration, @NonNull String);+ method @Deprecated @RequiresPermission(android.Manifest.permission.CONTROL_DISPLAY_SATURATION) public void setSaturationLevel(float);+ field @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") public static final int VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH = 131072; // 0x20000++ field @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") public static final int VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING = 262144; // 0x40000+ field public static final int VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT = 128; // 0x80+ field public static final int VIRTUAL_DISPLAY_FLAG_STEAL_TOP_FOCUS_DISABLED = 65536; // 0x10000+ field public static final int VIRTUAL_DISPLAY_FLAG_TRUSTED = 1024; // 0x400+@@ -6717,6 +6718,7 @@ package android.hardware.display {+ + public final class VirtualDisplayConfig implements android.os.Parcelable {+ method @Nullable public android.view.DisplayCutout getDisplayCutout();++ method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @NonNull public java.util.List<android.view.Display.Mode> getSupportedModes();+ method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @Nullable public String getUniqueId();+ method public boolean isHomeSupported();+ method @FlaggedApi("com.android.window.flags.vdm_force_app_universal_resizable_api") public boolean isIgnoreActivitySizeRestrictions();+@@ -6726,6 +6728,7 @@ package android.hardware.display {+ method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDisplayCutout(@Nullable android.view.DisplayCutout);+ method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setHomeSupported(boolean);+ method @FlaggedApi("com.android.window.flags.vdm_force_app_universal_resizable_api") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setIgnoreActivitySizeRestrictions(boolean);++ method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @NonNull @RequiresPermission(android.Manifest.permission.ADD_TRUSTED_DISPLAY) public android.hardware.display.VirtualDisplayConfig.Builder setSupportedModes(@NonNull java.util.List<android.view.Display.Mode>);+ method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @NonNull @RequiresPermission(android.Manifest.permission.ADD_TRUSTED_DISPLAY) public android.hardware.display.VirtualDisplayConfig.Builder setUniqueId(@Nullable String);+ }+ diff --git a/core/java/android/ext/KnownSystemPackages.java b/core/java/android/ext/KnownSystemPackages.java index 839f04c0773b..e962c3bc4f64 100644 --- a/core/java/android/ext/KnownSystemPackages.java@@ -24,6 +52,197 @@ index 0eb6239bc279..fa975ab112b9 100644 public static final String ACTION_ERROR_REPORT = PACKAGE_NAME + ".ERROR_REPORT"; public static final String ACTION_LOGCAT = PACKAGE_NAME + ".LOGCAT";+diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java+index ce3cfd9fc85d..f2ad0bf8a278 100644+--- a/core/java/android/hardware/display/DisplayManager.java++++ b/core/java/android/hardware/display/DisplayManager.java+@@ -225,6 +225,7 @@ public final class DisplayManager {+ VIRTUAL_DISPLAY_FLAG_OWN_FOCUS,+ VIRTUAL_DISPLAY_FLAG_STEAL_TOP_FOCUS_DISABLED,+ VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH,++ VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING,+ })+ @Retention(RetentionPolicy.SOURCE)+ public @interface VirtualDisplayFlag {}+@@ -556,6 +557,27 @@ public final class DisplayManager {+ @SystemApi+ public static final int VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH = 1 << 17;+ ++ /**++ * Virtual display flag: Create the display in the connected-but-disabled state, rather than++ * enabled and composing immediately.++ *++ * <p>A display created this way is reported as a pending connection, the same state a++ * physical display occupies between being plugged in and the user deciding what to do with++ * it. Nothing is composed to it and no activity is placed on it until++ * {@link #enableConnectedDisplay(int)} is called - which is what lets the system ask whether++ * the display should mirror or extend before anything is shown on it.</p>++ *++ * <p>Note that this flag requires {@link #VIRTUAL_DISPLAY_FLAG_TRUSTED}; a display the system++ * would not place activities on has nothing to ask about, so it is ignored otherwise.</p>++ *++ * @see #createVirtualDisplay++ * @hide++ */++ @FlaggedApi(com.android.server++ .display.feature.flags.Flags.FLAG_VIRTUAL_DISPLAYS_SUPPORT_DESKTOP_MODE)++ @SystemApi++ public static final int VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING = 1 << 18;+++ /** @hide */+ @IntDef(prefix = {"MATCH_CONTENT_FRAMERATE_"}, value = {+ MATCH_CONTENT_FRAMERATE_UNKNOWN,+diff --git a/core/java/android/hardware/display/VirtualDisplayConfig.java b/core/java/android/hardware/display/VirtualDisplayConfig.java+index b6fa05f754ac..182b9cbdced3 100644+--- a/core/java/android/hardware/display/VirtualDisplayConfig.java++++ b/core/java/android/hardware/display/VirtualDisplayConfig.java+@@ -40,6 +40,7 @@ import android.view.DisplayCutout;+ import android.view.Surface;+ + import java.util.Collections;++import java.util.List;+ import java.util.Objects;+ import java.util.Set;+ import java.util.concurrent.Executor;+@@ -70,6 +71,7 @@ public final class VirtualDisplayConfig implements Parcelable {+ private final float mDefaultBrightness;+ private final float mDimBrightness;+ private final IBrightnessListener mBrightnessListener;++ private final List<Display.Mode> mSupportedModes;+ + private VirtualDisplayConfig(+ @NonNull String name,+@@ -88,7 +90,8 @@ public final class VirtualDisplayConfig implements Parcelable {+ boolean ignoreActivitySizeRestrictions,+ @FloatRange(from = 0.0f, to = 1.0f) float defaultBrightness,+ @FloatRange(from = 0.0f, to = 1.0f) float dimBrightness,+- IBrightnessListener brightnessListener) {++ IBrightnessListener brightnessListener,++ @NonNull List<Display.Mode> supportedModes) {+ mName = name;+ mWidth = width;+ mHeight = height;+@@ -106,6 +109,7 @@ public final class VirtualDisplayConfig implements Parcelable {+ mDefaultBrightness = defaultBrightness;+ mDimBrightness = dimBrightness;+ mBrightnessListener = brightnessListener;++ mSupportedModes = supportedModes;+ }+ + /**+@@ -203,6 +207,20 @@ public final class VirtualDisplayConfig implements Parcelable {+ return mBrightnessListener;+ }+ ++ /**++ * Returns the modes this display can be shown at, or an empty list when the owner declared++ * none and the display therefore has only the one it was created with.++ *++ * @hide++ */++ @SystemApi++ @NonNull++ @FlaggedApi(com.android.server.display.feature.flags.Flags++ .FLAG_VIRTUAL_DISPLAYS_SUPPORT_DESKTOP_MODE)++ public List<Display.Mode> getSupportedModes() {++ return mSupportedModes == null ? Collections.emptyList() : mSupportedModes;++ }+++ /**+ * Returns the unique identifier for the display. Shouldn't be displayed to the user.+ * @hide+@@ -299,6 +317,7 @@ public final class VirtualDisplayConfig implements Parcelable {+ dest.writeFloat(mDefaultBrightness);+ dest.writeFloat(mDimBrightness);+ dest.writeStrongBinder(mBrightnessListener != null ? mBrightnessListener.asBinder() : null);++ dest.writeTypedList(mSupportedModes);+ }+ + @Override+@@ -329,7 +348,8 @@ public final class VirtualDisplayConfig implements Parcelable {+ && Objects.equals(mDisplayCutout, that.mDisplayCutout)+ && mDefaultBrightness == that.mDefaultBrightness+ && mDimBrightness == that.mDimBrightness+- && Objects.equals(mBrightnessListener, that.mBrightnessListener);++ && Objects.equals(mBrightnessListener, that.mBrightnessListener)++ && Objects.equals(mSupportedModes, that.mSupportedModes);+ }+ + @Override+@@ -339,7 +359,8 @@ public final class VirtualDisplayConfig implements Parcelable {+ mDisplayIdToMirror, mWindowManagerMirroringEnabled, mDisplayCategories,+ mRequestedRefreshRate, mIsHomeSupported, mDisplayCutout,+ mIgnoreActivitySizeRestrictions, mDefaultBrightness, mDimBrightness,+- mBrightnessListener);++ mBrightnessListener,++ mSupportedModes);+ return hashCode;+ }+ +@@ -363,6 +384,7 @@ public final class VirtualDisplayConfig implements Parcelable {+ + " mIgnoreActivitySizeRestrictions=" + mIgnoreActivitySizeRestrictions+ + " mDefaultBrightness=" + mDefaultBrightness+ + " mDimBrightness=" + mDimBrightness++ + " mSupportedModes=" + mSupportedModes+ + ")";+ }+ +@@ -384,6 +406,7 @@ public final class VirtualDisplayConfig implements Parcelable {+ mDefaultBrightness = in.readFloat();+ mDimBrightness = in.readFloat();+ mBrightnessListener = IBrightnessListener.Stub.asInterface(in.readStrongBinder());++ mSupportedModes = in.createTypedArrayList(Display.Mode.CREATOR);+ }+ + /**+@@ -455,6 +478,7 @@ public final class VirtualDisplayConfig implements Parcelable {+ private float mDefaultBrightness = 0.0f;+ private float mDimBrightness = PowerManager.BRIGHTNESS_INVALID;+ private IBrightnessListener mBrightnessListener = null;++ private List<Display.Mode> mSupportedModes = Collections.emptyList();+ + /**+ * Creates a new Builder.+@@ -530,6 +554,29 @@ public final class VirtualDisplayConfig implements Parcelable {+ return this;+ }+ ++ /**++ * Sets the modes this display can be shown at.++ *++ * <p>A virtual display otherwise advertises only the single mode it was created with,++ * which leaves nothing for the connected-display resolution picker to offer. An owner that++ * knows the real sink - a cast receiver that has been told the television's panel modes,++ * say - can declare them here, and the mode with the most pixels becomes the default.</p>++ *++ * <p>Note: honoured only on a trusted display. The modes must all be positive in both++ * dimensions; anything else is dropped.</p>++ *++ * @hide++ */++ @NonNull++ @SystemApi++ @RequiresPermission(Manifest.permission.ADD_TRUSTED_DISPLAY)++ @FlaggedApi(com.android.server.display.feature.flags.Flags++ .FLAG_VIRTUAL_DISPLAYS_SUPPORT_DESKTOP_MODE)++ public Builder setSupportedModes(@NonNull List<Display.Mode> supportedModes) {++ mSupportedModes = supportedModes;++ return this;++ }+++ /**+ * Sets the id of the display that the virtual display should mirror.+ * @hide+@@ -751,7 +798,8 @@ public final class VirtualDisplayConfig implements Parcelable {+ mIgnoreActivitySizeRestrictions,+ mDefaultBrightness,+ mDimBrightness,+- mBrightnessListener);++ mBrightnessListener,++ mSupportedModes);+ }+ }+ } diff --git a/core/res/res/values/config_ext.xml b/core/res/res/values/config_ext.xml index 9f66d22bca1a..6dd6906f4e34 100644 --- a/core/res/res/values/config_ext.xml@@ -216,6 +435,232 @@ index 8cbc3000c250..a453346df82e 100644 <family lang="und-Arab" variant="elegant"> <font weight="400" style="normal" postScriptName="NotoNaskhArabic"> NotoNaskhArabic-Regular.ttf+diff --git a/packages/SystemUI/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractor.kt b/packages/SystemUI/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractor.kt+index 72f92bd65473..42969f418d96 100644+--- a/packages/SystemUI/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractor.kt++++ b/packages/SystemUI/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractor.kt+@@ -192,7 +192,15 @@ constructor(+ }+ + private fun isExternalDisplay(display: Display): Boolean {+- return display.type == Display.TYPE_EXTERNAL++ if (display.type == Display.TYPE_EXTERNAL) {++ return true++ }++ // A virtual display that can switch content mode is one an owner created for a real sink++ // it is streaming to, so it is external as far as the user is concerned even though no++ // cable is involved. Matches DisplayRepository.isExternallyPresented and Settings'++ // ConnectedDisplayInjector.isVirtualDisplayAllowed.++ return display.type == Display.TYPE_VIRTUAL &&++ (display.flags and Display.FLAG_ALLOWS_CONTENT_MODE_SWITCH) != 0+ }+ + private fun isSecureDisplay(display: Display): Boolean {+diff --git a/services/core/java/com/android/server/display/DisplayDeviceInfo.java b/services/core/java/com/android/server/display/DisplayDeviceInfo.java+index a5eb85f87b80..e3f767d2594a 100644+--- a/services/core/java/com/android/server/display/DisplayDeviceInfo.java++++ b/services/core/java/com/android/server/display/DisplayDeviceInfo.java+@@ -204,6 +204,14 @@ final class DisplayDeviceInfo {+ */+ public static final int FLAG_ALLOWS_CONTENT_MODE_SWITCH = 1 << 20;+ ++ /**++ * Flag: The display should be created in the connected-but-disabled state, so that it is++ * offered as a pending connection rather than composing straight away.++ *++ * @see android.hardware.display.DisplayManager#VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING++ */++ public static final int FLAG_CONNECTION_PENDING = 1 << 21;+++ /**+ * Touch attachment: Display does not receive touch.+ */+@@ -820,6 +828,9 @@ final class DisplayDeviceInfo {+ if ((flags & FLAG_STEAL_TOP_FOCUS_DISABLED) != 0) {+ msg.append(", FLAG_STEAL_TOP_FOCUS_DISABLED");+ }++ if ((flags & FLAG_CONNECTION_PENDING) != 0) {++ msg.append(", FLAG_CONNECTION_PENDING");++ }+ return msg.toString();+ }+ }+diff --git a/services/core/java/com/android/server/display/LogicalDisplayMapper.java b/services/core/java/com/android/server/display/LogicalDisplayMapper.java+index ad113a2513f3..be7aa912a7a2 100644+--- a/services/core/java/com/android/server/display/LogicalDisplayMapper.java++++ b/services/core/java/com/android/server/display/LogicalDisplayMapper.java+@@ -1433,6 +1433,12 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {+ // the display should be disabled as later we will receive a device state update, which+ // will tell us which internal displays should be enabled and which should be disabled.+ display.setEnabledLocked(false);++ } else if (device != null && (device.getDisplayDeviceInfoLocked().flags++ & DisplayDeviceInfo.FLAG_CONNECTION_PENDING) != 0) {++ // The owner asked for this display to arrive as a pending connection rather than++ // composing immediately, so that the system can ask what it should be used for++ // first. It stays disabled until enableConnectedDisplay resolves that.++ display.setEnabledLocked(false);+ }+ + mLogicalDisplays.put(displayId, display);+diff --git a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java+index 0d4ae75b428f..55006db8a39b 100644+--- a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java++++ b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java+@@ -20,6 +20,7 @@ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_ALLOW+ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED;+ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;+ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD;++import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING;+ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL;+ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_DEVICE_DISPLAY_GROUP;+ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_DISPLAY_GROUP;+@@ -69,6 +70,8 @@ import com.android.server.display.feature.flags.Flags;+ import com.android.server.display.utils.DebugTransactionDetails;+ + import java.io.PrintWriter;++import java.util.ArrayList;++import java.util.List;+ import java.util.concurrent.atomic.AtomicInteger;+ + /**+@@ -366,6 +369,15 @@ public class VirtualDisplayAdapter extends DisplayAdapter {+ private float mCurrentBrightness;+ private final IBrightnessListener mBrightnessListener;+ private final boolean mHasUniqueId;++ /**++ * Every mode the owner declared, each with its own globally unique id.++ *++ * Built once, because {@code createMode} allocates a fresh id on every call and the++ * picker in Settings selects by id - regenerating them on resize would invalidate the++ * user's choice the moment it was applied. Empty when nothing was declared, which is++ * every caller that is not deliberately driving a real external sink.++ */++ private final List<Display.Mode> mDeclaredModes = new ArrayList<>();+ + public VirtualDisplayDevice(IBinder displayToken, IBinder appToken,+ int ownerUid, String ownerPackageName, Surface surface, int flags,+@@ -386,7 +398,13 @@ public class VirtualDisplayAdapter extends DisplayAdapter {+ mDimBrightness = virtualDisplayConfig.getDimBrightness();+ mCurrentBrightness = PowerManager.BRIGHTNESS_INVALID;+ mBrightnessListener = virtualDisplayConfig.getBrightnessListener();+- mMode = createMode(mWidth, mHeight, getRefreshRate());++ for (Display.Mode declared : virtualDisplayConfig.getSupportedModes()) {++ if (declared.getPhysicalWidth() > 0 && declared.getPhysicalHeight() > 0) {++ mDeclaredModes.add(createMode(declared.getPhysicalWidth(),++ declared.getPhysicalHeight(), getRefreshRate()));++ }++ }++ mMode = modeForLocked(mWidth, mHeight);+ mSurface = surface;+ mFlags = flags;+ mCallback = callback;+@@ -580,13 +598,70 @@ public class VirtualDisplayAdapter extends DisplayAdapter {+ sendTraversalRequestLocked();+ mWidth = width;+ mHeight = height;+- mMode = createMode(width, height, getRefreshRate());++ mMode = modeForLocked(width, height);+ mDensityDpi = densityDpi;+ mInfo = null;+ mPendingChanges |= PENDING_RESIZE;+ }+ }+ ++ /**++ * The declared mode of this size, or a fresh one when the size was never declared.++ *++ * Keeps ids stable across a resize: a display that was created from a declared list must++ * keep reporting those same ids in {@code supportedModes}, or the current mode stops++ * matching anything in the list Settings is showing.++ */++ private Display.Mode modeForLocked(int width, int height) {++ for (Display.Mode declared : mDeclaredModes) {++ if (declared.getPhysicalWidth() == width++ && declared.getPhysicalHeight() == height) {++ return declared;++ }++ }++ return createMode(width, height, getRefreshRate());++ }++++ @Override++ public boolean setUserPreferredDisplayModeLocked(Display.Mode mode) {++ if (mDeclaredModes.isEmpty()) {++ // Nothing was declared, so there is no list to have chosen from and the base++ // class's "not supported" answer is the honest one.++ return super.setUserPreferredDisplayModeLocked(mode);++ }++ if (mode == null) {++ // Back to the default, which is the largest thing the owner said the sink can do.++ Display.Mode largest = defaultModeLocked();++ resizeLocked(largest.getPhysicalWidth(), largest.getPhysicalHeight(), mDensityDpi);++ return true;++ }++ for (Display.Mode declared : mDeclaredModes) {++ if (declared.getPhysicalWidth() == mode.getPhysicalWidth()++ && declared.getPhysicalHeight() == mode.getPhysicalHeight()) {++ // Density is deliberately left alone. It was chosen for the sink rather than++ // derived from the frame, and rescaling it here would resize every element on++ // screen as a side effect of a resolution change.++ resizeLocked(declared.getPhysicalWidth(), declared.getPhysicalHeight(),++ mDensityDpi);++ return true;++ }++ }++ Slog.w(TAG, "Virtual Display: " + mName + " was asked for an undeclared mode " + mode);++ return false;++ }++++ /** The largest declared mode, which is what a display with a sink should default to. */++ private Display.Mode defaultModeLocked() {++ Display.Mode best = mDeclaredModes.get(0);++ for (Display.Mode candidate : mDeclaredModes) {++ long area = (long) candidate.getPhysicalWidth() * candidate.getPhysicalHeight();++ if (area > (long) best.getPhysicalWidth() * best.getPhysicalHeight()) {++ best = candidate;++ }++ }++ return best;++ }+++ public void stopLocked() {+ Slog.d(TAG, "Virtual Display: stopping device " + mName);+ setSurfaceLocked(null);+@@ -602,6 +677,7 @@ public class VirtualDisplayAdapter extends DisplayAdapter {+ pw.println("mDisplayIdToMirror=" + mDisplayIdToMirror);+ pw.println("mWindowManagerMirroring=" + mIsWindowManagerMirroring);+ pw.println("mRequestedRefreshRate=" + mRequestedRefreshRate);++ pw.println("mDeclaredModes=" + mDeclaredModes);+ }+ + @Override+@@ -614,8 +690,11 @@ public class VirtualDisplayAdapter extends DisplayAdapter {+ mInfo.height = mHeight;+ mInfo.modeId = mMode.getModeId();+ mInfo.renderFrameRate = mMode.getRefreshRate();+- mInfo.defaultModeId = mMode.getModeId();+- mInfo.supportedModes = new Display.Mode[] { mMode };++ mInfo.defaultModeId = mDeclaredModes.isEmpty()++ ? mMode.getModeId() : defaultModeLocked().getModeId();++ mInfo.supportedModes = mDeclaredModes.isEmpty()++ ? new Display.Mode[] { mMode }++ : mDeclaredModes.toArray(new Display.Mode[0]);+ mInfo.densityDpi = mDensityDpi;+ mInfo.xDpi = mDensityDpi;+ mInfo.yDpi = mDensityDpi;+@@ -631,6 +710,12 @@ public class VirtualDisplayAdapter extends DisplayAdapter {+ if ((mFlags & VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH) != 0) {+ mInfo.flags |= DisplayDeviceInfo.FLAG_ALLOWS_CONTENT_MODE_SWITCH;+ }++ // Trusted only: a display the system will not place activities on has no++ // mirror-or-extend question to ask, so pending would strand it disabled.++ if ((mFlags & VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING) != 0++ && (mFlags & VIRTUAL_DISPLAY_FLAG_TRUSTED) != 0) {++ mInfo.flags |= DisplayDeviceInfo.FLAG_CONNECTION_PENDING;++ }+ if (mNeverBlank) {+ mInfo.flags |= DisplayDeviceInfo.FLAG_NEVER_BLANK;+ } diff --git a/services/core/java/com/android/server/location/LocationManagerService.java b/services/core/java/com/android/server/location/LocationManagerService.java index e6fba2fadd1e..94a93f0e83f5 100644 --- a/services/core/java/com/android/server/location/LocationManagerService.java
patches/frameworks_libs_systemui.patch
diff --git a/patches/frameworks_libs_systemui.patch b/patches/frameworks_libs_systemui.patchindex e69de29..8fe9a5d 100644--- a/patches/frameworks_libs_systemui.patch+++ b/patches/frameworks_libs_systemui.patch@@ -0,0 +1,46 @@+diff --git a/displaylib/src/com/android/app/displaylib/DisplayRepository.kt b/displaylib/src/com/android/app/displaylib/DisplayRepository.kt+index 4617ca3c..cfc04f16 100644+--- a/displaylib/src/com/android/app/displaylib/DisplayRepository.kt++++ b/displaylib/src/com/android/app/displaylib/DisplayRepository.kt+@@ -361,9 +361,7 @@ constructor(+ connectedDisplayIds+ .map { connectedDisplayIds ->+ traceSection("$TAG#filteringExternalDisplays") {+- connectedDisplayIds+- .filter { id -> getDisplayType(id) == Display.TYPE_EXTERNAL }+- .toSet()++ connectedDisplayIds.filter { id -> isExternallyPresented(id) }.toSet()+ }+ }+ .flowOn(backgroundCoroutineDispatcher)+@@ -372,6 +370,30 @@ constructor(+ private fun getDisplayType(displayId: Int): Int? =+ traceSection("$TAG#getDisplayType") { displayManager.getDisplay(displayId)?.type }+ ++ /**++ * Whether this display is shown to the user on something other than the built-in screen, and++ * so is worth asking about when it connects.++ *++ * [Display.TYPE_EXTERNAL] is the physical case. A virtual display counts when it carries++ * `FLAG_ALLOWS_CONTENT_MODE_SWITCH`, which means its owner is driving a real sink - a cast++ * receiver, say - and the display can genuinely be either a mirror or a second desktop. That++ * is exactly the question the connection dialog exists to ask, and without this it was only++ * ever asked about displays with a cable.++ *++ * Deliberately narrow: an ordinary virtual display, of which there are many and most of them++ * invisible, does not carry that flag and is not offered.++ */++ private fun isExternallyPresented(displayId: Int): Boolean =++ traceSection("$TAG#isExternallyPresented") {++ val display = displayManager.getDisplay(displayId) ?: return@traceSection false++ when (display.type) {++ Display.TYPE_EXTERNAL -> true++ Display.TYPE_VIRTUAL ->++ (display.flags and Display.FLAG_ALLOWS_CONTENT_MODE_SWITCH) != 0++ else -> false++ }++ }+++ private fun getDisplayFromDisplayManager(displayId: Int): Display? =+ traceSection("$TAG#getDisplay") { displayManager.getDisplay(displayId) }+
patches/wip/README.md
diff --git a/patches/wip/README.md b/patches/wip/README.mddeleted file mode 100644index 46cc388..0000000--- a/patches/wip/README.md+++ /dev/null@@ -1,39 +0,0 @@-# Work-in-progress patches (NOT applied by build-maos.sh)--`apply_maos_patches()` in build-maos.sh iterates an explicit `repo:patchfile` list.-Nothing in this directory is on that list, so nothing here is applied automatically.--## cast-desktop-mode-*.patch--The cast desktop-mode framework work. **These bootloop the device** and are parked here-until the fault is found.--Established by bisection on shiba:--| tree state | result |-|---|---|-| all cast patches applied | bootloop (animation, then reset) |-| SystemUI cast patches reverted only | bootloop |-| SystemUI **and** framework cast patches reverted | **boots** |--So the fault is in the framework half — one of `DisplayManager.java`,-`VirtualDisplayConfig.java`, `DisplayDeviceInfo.java`, `LogicalDisplayMapper.java`,-`VirtualDisplayAdapter.java` — not SystemUI.--Two independent features are mixed together in that patch, and they can be re-applied-separately to narrow it further:--1. **Declared display modes** - `VirtualDisplayConfig.setSupportedModes()` plus- `VirtualDisplayAdapter`'s `mDeclaredModes` / `modeForLocked()` /- `setUserPreferredDisplayModeLocked()`. Lets the TV's real resolutions appear in- Settings. Touches only virtual-display code paths.-2. **Connection-pending displays** - `VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING`,- `DisplayDeviceInfo.FLAG_CONNECTION_PENDING`, and the `LogicalDisplayMapper` branch- that starts such displays **disabled**. This is the one that touches- `createNewLogicalDisplayLocked`, which runs for every display at boot including the- built-in panel, so it is the stronger suspect.--Ruled out already: flag-bit collisions in all three flag namespaces,-`VirtualDisplayConfig` parcel symmetry (write and read orders match), and the-`virtual_displays_support_desktop_mode` aconfig flag (no aconfig storage file differs-between the booting and bootlooping images).
patches/wip/cast-desktop-mode-framework.patch
diff --git a/patches/wip/cast-desktop-mode-framework.patch b/patches/wip/cast-desktop-mode-framework.patchdeleted file mode 100755index 5e44916..0000000--- a/patches/wip/cast-desktop-mode-framework.patch+++ /dev/null@@ -1,424 +0,0 @@-diff --git a/core/api/system-current.txt b/core/api/system-current.txt-index a21a30f5b415..38bce179e9fc 100644---- a/core/api/system-current.txt-+++ b/core/api/system-current.txt-@@ -6710,6 +6710,7 @@ package android.hardware.display {- method @RequiresPermission(android.Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS) public void setBrightnessConfigurationForDisplay(@NonNull android.hardware.display.BrightnessConfiguration, @NonNull String);- method @Deprecated @RequiresPermission(android.Manifest.permission.CONTROL_DISPLAY_SATURATION) public void setSaturationLevel(float);- field @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") public static final int VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH = 131072; // 0x20000-+ field @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") public static final int VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING = 262144; // 0x40000- field public static final int VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT = 128; // 0x80- field public static final int VIRTUAL_DISPLAY_FLAG_STEAL_TOP_FOCUS_DISABLED = 65536; // 0x10000- field public static final int VIRTUAL_DISPLAY_FLAG_TRUSTED = 1024; // 0x400-@@ -6717,6 +6718,7 @@ package android.hardware.display {- - public final class VirtualDisplayConfig implements android.os.Parcelable {- method @Nullable public android.view.DisplayCutout getDisplayCutout();-+ method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @NonNull public java.util.List<android.view.Display.Mode> getSupportedModes();- method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @Nullable public String getUniqueId();- method public boolean isHomeSupported();- method @FlaggedApi("com.android.window.flags.vdm_force_app_universal_resizable_api") public boolean isIgnoreActivitySizeRestrictions();-@@ -6726,6 +6728,7 @@ package android.hardware.display {- method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDisplayCutout(@Nullable android.view.DisplayCutout);- method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setHomeSupported(boolean);- method @FlaggedApi("com.android.window.flags.vdm_force_app_universal_resizable_api") @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setIgnoreActivitySizeRestrictions(boolean);-+ method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @NonNull @RequiresPermission(android.Manifest.permission.ADD_TRUSTED_DISPLAY) public android.hardware.display.VirtualDisplayConfig.Builder setSupportedModes(@NonNull java.util.List<android.view.Display.Mode>);- method @FlaggedApi("com.android.server.display.feature.flags.virtual_displays_support_desktop_mode") @NonNull @RequiresPermission(android.Manifest.permission.ADD_TRUSTED_DISPLAY) public android.hardware.display.VirtualDisplayConfig.Builder setUniqueId(@Nullable String);- }- -diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java-index ce3cfd9fc85d..f2ad0bf8a278 100644---- a/core/java/android/hardware/display/DisplayManager.java-+++ b/core/java/android/hardware/display/DisplayManager.java-@@ -225,6 +225,7 @@ public final class DisplayManager {- VIRTUAL_DISPLAY_FLAG_OWN_FOCUS,- VIRTUAL_DISPLAY_FLAG_STEAL_TOP_FOCUS_DISABLED,- VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH,-+ VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING,- })- @Retention(RetentionPolicy.SOURCE)- public @interface VirtualDisplayFlag {}-@@ -556,6 +557,27 @@ public final class DisplayManager {- @SystemApi- public static final int VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH = 1 << 17;- -+ /**-+ * Virtual display flag: Create the display in the connected-but-disabled state, rather than-+ * enabled and composing immediately.-+ *-+ * <p>A display created this way is reported as a pending connection, the same state a-+ * physical display occupies between being plugged in and the user deciding what to do with-+ * it. Nothing is composed to it and no activity is placed on it until-+ * {@link #enableConnectedDisplay(int)} is called - which is what lets the system ask whether-+ * the display should mirror or extend before anything is shown on it.</p>-+ *-+ * <p>Note that this flag requires {@link #VIRTUAL_DISPLAY_FLAG_TRUSTED}; a display the system-+ * would not place activities on has nothing to ask about, so it is ignored otherwise.</p>-+ *-+ * @see #createVirtualDisplay-+ * @hide-+ */-+ @FlaggedApi(com.android.server-+ .display.feature.flags.Flags.FLAG_VIRTUAL_DISPLAYS_SUPPORT_DESKTOP_MODE)-+ @SystemApi-+ public static final int VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING = 1 << 18;-+- /** @hide */- @IntDef(prefix = {"MATCH_CONTENT_FRAMERATE_"}, value = {- MATCH_CONTENT_FRAMERATE_UNKNOWN,-diff --git a/core/java/android/hardware/display/VirtualDisplayConfig.java b/core/java/android/hardware/display/VirtualDisplayConfig.java-index b6fa05f754ac..182b9cbdced3 100644---- a/core/java/android/hardware/display/VirtualDisplayConfig.java-+++ b/core/java/android/hardware/display/VirtualDisplayConfig.java-@@ -40,6 +40,7 @@ import android.view.DisplayCutout;- import android.view.Surface;- - import java.util.Collections;-+import java.util.List;- import java.util.Objects;- import java.util.Set;- import java.util.concurrent.Executor;-@@ -70,6 +71,7 @@ public final class VirtualDisplayConfig implements Parcelable {- private final float mDefaultBrightness;- private final float mDimBrightness;- private final IBrightnessListener mBrightnessListener;-+ private final List<Display.Mode> mSupportedModes;- - private VirtualDisplayConfig(- @NonNull String name,-@@ -88,7 +90,8 @@ public final class VirtualDisplayConfig implements Parcelable {- boolean ignoreActivitySizeRestrictions,- @FloatRange(from = 0.0f, to = 1.0f) float defaultBrightness,- @FloatRange(from = 0.0f, to = 1.0f) float dimBrightness,-- IBrightnessListener brightnessListener) {-+ IBrightnessListener brightnessListener,-+ @NonNull List<Display.Mode> supportedModes) {- mName = name;- mWidth = width;- mHeight = height;-@@ -106,6 +109,7 @@ public final class VirtualDisplayConfig implements Parcelable {- mDefaultBrightness = defaultBrightness;- mDimBrightness = dimBrightness;- mBrightnessListener = brightnessListener;-+ mSupportedModes = supportedModes;- }- - /**-@@ -203,6 +207,20 @@ public final class VirtualDisplayConfig implements Parcelable {- return mBrightnessListener;- }- -+ /**-+ * Returns the modes this display can be shown at, or an empty list when the owner declared-+ * none and the display therefore has only the one it was created with.-+ *-+ * @hide-+ */-+ @SystemApi-+ @NonNull-+ @FlaggedApi(com.android.server.display.feature.flags.Flags-+ .FLAG_VIRTUAL_DISPLAYS_SUPPORT_DESKTOP_MODE)-+ public List<Display.Mode> getSupportedModes() {-+ return mSupportedModes == null ? Collections.emptyList() : mSupportedModes;-+ }-+- /**- * Returns the unique identifier for the display. Shouldn't be displayed to the user.- * @hide-@@ -299,6 +317,7 @@ public final class VirtualDisplayConfig implements Parcelable {- dest.writeFloat(mDefaultBrightness);- dest.writeFloat(mDimBrightness);- dest.writeStrongBinder(mBrightnessListener != null ? mBrightnessListener.asBinder() : null);-+ dest.writeTypedList(mSupportedModes);- }- - @Override-@@ -329,7 +348,8 @@ public final class VirtualDisplayConfig implements Parcelable {- && Objects.equals(mDisplayCutout, that.mDisplayCutout)- && mDefaultBrightness == that.mDefaultBrightness- && mDimBrightness == that.mDimBrightness-- && Objects.equals(mBrightnessListener, that.mBrightnessListener);-+ && Objects.equals(mBrightnessListener, that.mBrightnessListener)-+ && Objects.equals(mSupportedModes, that.mSupportedModes);- }- - @Override-@@ -339,7 +359,8 @@ public final class VirtualDisplayConfig implements Parcelable {- mDisplayIdToMirror, mWindowManagerMirroringEnabled, mDisplayCategories,- mRequestedRefreshRate, mIsHomeSupported, mDisplayCutout,- mIgnoreActivitySizeRestrictions, mDefaultBrightness, mDimBrightness,-- mBrightnessListener);-+ mBrightnessListener,-+ mSupportedModes);- return hashCode;- }- -@@ -363,6 +384,7 @@ public final class VirtualDisplayConfig implements Parcelable {- + " mIgnoreActivitySizeRestrictions=" + mIgnoreActivitySizeRestrictions- + " mDefaultBrightness=" + mDefaultBrightness- + " mDimBrightness=" + mDimBrightness-+ + " mSupportedModes=" + mSupportedModes- + ")";- }- -@@ -384,6 +406,7 @@ public final class VirtualDisplayConfig implements Parcelable {- mDefaultBrightness = in.readFloat();- mDimBrightness = in.readFloat();- mBrightnessListener = IBrightnessListener.Stub.asInterface(in.readStrongBinder());-+ mSupportedModes = in.createTypedArrayList(Display.Mode.CREATOR);- }- - /**-@@ -455,6 +478,7 @@ public final class VirtualDisplayConfig implements Parcelable {- private float mDefaultBrightness = 0.0f;- private float mDimBrightness = PowerManager.BRIGHTNESS_INVALID;- private IBrightnessListener mBrightnessListener = null;-+ private List<Display.Mode> mSupportedModes = Collections.emptyList();- - /**- * Creates a new Builder.-@@ -530,6 +554,29 @@ public final class VirtualDisplayConfig implements Parcelable {- return this;- }- -+ /**-+ * Sets the modes this display can be shown at.-+ *-+ * <p>A virtual display otherwise advertises only the single mode it was created with,-+ * which leaves nothing for the connected-display resolution picker to offer. An owner that-+ * knows the real sink - a cast receiver that has been told the television's panel modes,-+ * say - can declare them here, and the mode with the most pixels becomes the default.</p>-+ *-+ * <p>Note: honoured only on a trusted display. The modes must all be positive in both-+ * dimensions; anything else is dropped.</p>-+ *-+ * @hide-+ */-+ @NonNull-+ @SystemApi-+ @RequiresPermission(Manifest.permission.ADD_TRUSTED_DISPLAY)-+ @FlaggedApi(com.android.server.display.feature.flags.Flags-+ .FLAG_VIRTUAL_DISPLAYS_SUPPORT_DESKTOP_MODE)-+ public Builder setSupportedModes(@NonNull List<Display.Mode> supportedModes) {-+ mSupportedModes = supportedModes;-+ return this;-+ }-+- /**- * Sets the id of the display that the virtual display should mirror.- * @hide-@@ -751,7 +798,8 @@ public final class VirtualDisplayConfig implements Parcelable {- mIgnoreActivitySizeRestrictions,- mDefaultBrightness,- mDimBrightness,-- mBrightnessListener);-+ mBrightnessListener,-+ mSupportedModes);- }- }- }-diff --git a/services/core/java/com/android/server/display/DisplayDeviceInfo.java b/services/core/java/com/android/server/display/DisplayDeviceInfo.java-index a5eb85f87b80..e3f767d2594a 100644---- a/services/core/java/com/android/server/display/DisplayDeviceInfo.java-+++ b/services/core/java/com/android/server/display/DisplayDeviceInfo.java-@@ -204,6 +204,14 @@ final class DisplayDeviceInfo {- */- public static final int FLAG_ALLOWS_CONTENT_MODE_SWITCH = 1 << 20;- -+ /**-+ * Flag: The display should be created in the connected-but-disabled state, so that it is-+ * offered as a pending connection rather than composing straight away.-+ *-+ * @see android.hardware.display.DisplayManager#VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING-+ */-+ public static final int FLAG_CONNECTION_PENDING = 1 << 21;-+- /**- * Touch attachment: Display does not receive touch.- */-@@ -820,6 +828,9 @@ final class DisplayDeviceInfo {- if ((flags & FLAG_STEAL_TOP_FOCUS_DISABLED) != 0) {- msg.append(", FLAG_STEAL_TOP_FOCUS_DISABLED");- }-+ if ((flags & FLAG_CONNECTION_PENDING) != 0) {-+ msg.append(", FLAG_CONNECTION_PENDING");-+ }- return msg.toString();- }- }-diff --git a/services/core/java/com/android/server/display/LogicalDisplayMapper.java b/services/core/java/com/android/server/display/LogicalDisplayMapper.java-index ad113a2513f3..1b6c0f405ca8 100644---- a/services/core/java/com/android/server/display/LogicalDisplayMapper.java-+++ b/services/core/java/com/android/server/display/LogicalDisplayMapper.java-@@ -1433,6 +1433,12 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {- // the display should be disabled as later we will receive a device state update, which- // will tell us which internal displays should be enabled and which should be disabled.- display.setEnabledLocked(false);-+ } else if ((device.getDisplayDeviceInfoLocked().flags-+ & DisplayDeviceInfo.FLAG_CONNECTION_PENDING) != 0) {-+ // The owner asked for this display to arrive as a pending connection rather than-+ // composing immediately, so that the system can ask what it should be used for-+ // first. It stays disabled until enableConnectedDisplay resolves that.-+ display.setEnabledLocked(false);- }- - mLogicalDisplays.put(displayId, display);-diff --git a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java-index 0d4ae75b428f..55006db8a39b 100644---- a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java-+++ b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java-@@ -20,6 +20,7 @@ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_ALLOW- import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED;- import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;- import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD;-+import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING;- import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL;- import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_DEVICE_DISPLAY_GROUP;- import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_DISPLAY_GROUP;-@@ -69,6 +70,8 @@ import com.android.server.display.feature.flags.Flags;- import com.android.server.display.utils.DebugTransactionDetails;- - import java.io.PrintWriter;-+import java.util.ArrayList;-+import java.util.List;- import java.util.concurrent.atomic.AtomicInteger;- - /**-@@ -366,6 +369,15 @@ public class VirtualDisplayAdapter extends DisplayAdapter {- private float mCurrentBrightness;- private final IBrightnessListener mBrightnessListener;- private final boolean mHasUniqueId;-+ /**-+ * Every mode the owner declared, each with its own globally unique id.-+ *-+ * Built once, because {@code createMode} allocates a fresh id on every call and the-+ * picker in Settings selects by id - regenerating them on resize would invalidate the-+ * user's choice the moment it was applied. Empty when nothing was declared, which is-+ * every caller that is not deliberately driving a real external sink.-+ */-+ private final List<Display.Mode> mDeclaredModes = new ArrayList<>();- - public VirtualDisplayDevice(IBinder displayToken, IBinder appToken,- int ownerUid, String ownerPackageName, Surface surface, int flags,-@@ -386,7 +398,13 @@ public class VirtualDisplayAdapter extends DisplayAdapter {- mDimBrightness = virtualDisplayConfig.getDimBrightness();- mCurrentBrightness = PowerManager.BRIGHTNESS_INVALID;- mBrightnessListener = virtualDisplayConfig.getBrightnessListener();-- mMode = createMode(mWidth, mHeight, getRefreshRate());-+ for (Display.Mode declared : virtualDisplayConfig.getSupportedModes()) {-+ if (declared.getPhysicalWidth() > 0 && declared.getPhysicalHeight() > 0) {-+ mDeclaredModes.add(createMode(declared.getPhysicalWidth(),-+ declared.getPhysicalHeight(), getRefreshRate()));-+ }-+ }-+ mMode = modeForLocked(mWidth, mHeight);- mSurface = surface;- mFlags = flags;- mCallback = callback;-@@ -580,13 +598,70 @@ public class VirtualDisplayAdapter extends DisplayAdapter {- sendTraversalRequestLocked();- mWidth = width;- mHeight = height;-- mMode = createMode(width, height, getRefreshRate());-+ mMode = modeForLocked(width, height);- mDensityDpi = densityDpi;- mInfo = null;- mPendingChanges |= PENDING_RESIZE;- }- }- -+ /**-+ * The declared mode of this size, or a fresh one when the size was never declared.-+ *-+ * Keeps ids stable across a resize: a display that was created from a declared list must-+ * keep reporting those same ids in {@code supportedModes}, or the current mode stops-+ * matching anything in the list Settings is showing.-+ */-+ private Display.Mode modeForLocked(int width, int height) {-+ for (Display.Mode declared : mDeclaredModes) {-+ if (declared.getPhysicalWidth() == width-+ && declared.getPhysicalHeight() == height) {-+ return declared;-+ }-+ }-+ return createMode(width, height, getRefreshRate());-+ }-+-+ @Override-+ public boolean setUserPreferredDisplayModeLocked(Display.Mode mode) {-+ if (mDeclaredModes.isEmpty()) {-+ // Nothing was declared, so there is no list to have chosen from and the base-+ // class's "not supported" answer is the honest one.-+ return super.setUserPreferredDisplayModeLocked(mode);-+ }-+ if (mode == null) {-+ // Back to the default, which is the largest thing the owner said the sink can do.-+ Display.Mode largest = defaultModeLocked();-+ resizeLocked(largest.getPhysicalWidth(), largest.getPhysicalHeight(), mDensityDpi);-+ return true;-+ }-+ for (Display.Mode declared : mDeclaredModes) {-+ if (declared.getPhysicalWidth() == mode.getPhysicalWidth()-+ && declared.getPhysicalHeight() == mode.getPhysicalHeight()) {-+ // Density is deliberately left alone. It was chosen for the sink rather than-+ // derived from the frame, and rescaling it here would resize every element on-+ // screen as a side effect of a resolution change.-+ resizeLocked(declared.getPhysicalWidth(), declared.getPhysicalHeight(),-+ mDensityDpi);-+ return true;-+ }-+ }-+ Slog.w(TAG, "Virtual Display: " + mName + " was asked for an undeclared mode " + mode);-+ return false;-+ }-+-+ /** The largest declared mode, which is what a display with a sink should default to. */-+ private Display.Mode defaultModeLocked() {-+ Display.Mode best = mDeclaredModes.get(0);-+ for (Display.Mode candidate : mDeclaredModes) {-+ long area = (long) candidate.getPhysicalWidth() * candidate.getPhysicalHeight();-+ if (area > (long) best.getPhysicalWidth() * best.getPhysicalHeight()) {-+ best = candidate;-+ }-+ }-+ return best;-+ }-+- public void stopLocked() {- Slog.d(TAG, "Virtual Display: stopping device " + mName);- setSurfaceLocked(null);-@@ -602,6 +677,7 @@ public class VirtualDisplayAdapter extends DisplayAdapter {- pw.println("mDisplayIdToMirror=" + mDisplayIdToMirror);- pw.println("mWindowManagerMirroring=" + mIsWindowManagerMirroring);- pw.println("mRequestedRefreshRate=" + mRequestedRefreshRate);-+ pw.println("mDeclaredModes=" + mDeclaredModes);- }- - @Override-@@ -614,8 +690,11 @@ public class VirtualDisplayAdapter extends DisplayAdapter {- mInfo.height = mHeight;- mInfo.modeId = mMode.getModeId();- mInfo.renderFrameRate = mMode.getRefreshRate();-- mInfo.defaultModeId = mMode.getModeId();-- mInfo.supportedModes = new Display.Mode[] { mMode };-+ mInfo.defaultModeId = mDeclaredModes.isEmpty()-+ ? mMode.getModeId() : defaultModeLocked().getModeId();-+ mInfo.supportedModes = mDeclaredModes.isEmpty()-+ ? new Display.Mode[] { mMode }-+ : mDeclaredModes.toArray(new Display.Mode[0]);- mInfo.densityDpi = mDensityDpi;- mInfo.xDpi = mDensityDpi;- mInfo.yDpi = mDensityDpi;-@@ -631,6 +710,12 @@ public class VirtualDisplayAdapter extends DisplayAdapter {- if ((mFlags & VIRTUAL_DISPLAY_FLAG_ALLOWS_CONTENT_MODE_SWITCH) != 0) {- mInfo.flags |= DisplayDeviceInfo.FLAG_ALLOWS_CONTENT_MODE_SWITCH;- }-+ // Trusted only: a display the system will not place activities on has no-+ // mirror-or-extend question to ask, so pending would strand it disabled.-+ if ((mFlags & VIRTUAL_DISPLAY_FLAG_CONNECTION_PENDING) != 0-+ && (mFlags & VIRTUAL_DISPLAY_FLAG_TRUSTED) != 0) {-+ mInfo.flags |= DisplayDeviceInfo.FLAG_CONNECTION_PENDING;-+ }- if (mNeverBlank) {- mInfo.flags |= DisplayDeviceInfo.FLAG_NEVER_BLANK;- }
patches/wip/cast-desktop-mode-systemui-displaylib.patch
diff --git a/patches/wip/cast-desktop-mode-systemui-displaylib.patch b/patches/wip/cast-desktop-mode-systemui-displaylib.patchdeleted file mode 100755index 8fe9a5d..0000000--- a/patches/wip/cast-desktop-mode-systemui-displaylib.patch+++ /dev/null@@ -1,46 +0,0 @@-diff --git a/displaylib/src/com/android/app/displaylib/DisplayRepository.kt b/displaylib/src/com/android/app/displaylib/DisplayRepository.kt-index 4617ca3c..cfc04f16 100644---- a/displaylib/src/com/android/app/displaylib/DisplayRepository.kt-+++ b/displaylib/src/com/android/app/displaylib/DisplayRepository.kt-@@ -361,9 +361,7 @@ constructor(- connectedDisplayIds- .map { connectedDisplayIds ->- traceSection("$TAG#filteringExternalDisplays") {-- connectedDisplayIds-- .filter { id -> getDisplayType(id) == Display.TYPE_EXTERNAL }-- .toSet()-+ connectedDisplayIds.filter { id -> isExternallyPresented(id) }.toSet()- }- }- .flowOn(backgroundCoroutineDispatcher)-@@ -372,6 +370,30 @@ constructor(- private fun getDisplayType(displayId: Int): Int? =- traceSection("$TAG#getDisplayType") { displayManager.getDisplay(displayId)?.type }- -+ /**-+ * Whether this display is shown to the user on something other than the built-in screen, and-+ * so is worth asking about when it connects.-+ *-+ * [Display.TYPE_EXTERNAL] is the physical case. A virtual display counts when it carries-+ * `FLAG_ALLOWS_CONTENT_MODE_SWITCH`, which means its owner is driving a real sink - a cast-+ * receiver, say - and the display can genuinely be either a mirror or a second desktop. That-+ * is exactly the question the connection dialog exists to ask, and without this it was only-+ * ever asked about displays with a cable.-+ *-+ * Deliberately narrow: an ordinary virtual display, of which there are many and most of them-+ * invisible, does not carry that flag and is not offered.-+ */-+ private fun isExternallyPresented(displayId: Int): Boolean =-+ traceSection("$TAG#isExternallyPresented") {-+ val display = displayManager.getDisplay(displayId) ?: return@traceSection false-+ when (display.type) {-+ Display.TYPE_EXTERNAL -> true-+ Display.TYPE_VIRTUAL ->-+ (display.flags and Display.FLAG_ALLOWS_CONTENT_MODE_SWITCH) != 0-+ else -> false-+ }-+ }-+- private fun getDisplayFromDisplayManager(displayId: Int): Display? =- traceSection("$TAG#getDisplay") { displayManager.getDisplay(displayId) }-
patches/wip/cast-desktop-mode-systemui-interactor.patch
diff --git a/patches/wip/cast-desktop-mode-systemui-interactor.patch b/patches/wip/cast-desktop-mode-systemui-interactor.patchdeleted file mode 100755index b57f659..0000000--- a/patches/wip/cast-desktop-mode-systemui-interactor.patch+++ /dev/null@@ -1,21 +0,0 @@-diff --git a/packages/SystemUI/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractor.kt b/packages/SystemUI/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractor.kt-index 72f92bd65473..42969f418d96 100644---- a/packages/SystemUI/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractor.kt-+++ b/packages/SystemUI/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractor.kt-@@ -192,7 +192,15 @@ constructor(- }- - private fun isExternalDisplay(display: Display): Boolean {-- return display.type == Display.TYPE_EXTERNAL-+ if (display.type == Display.TYPE_EXTERNAL) {-+ return true-+ }-+ // A virtual display that can switch content mode is one an owner created for a real sink-+ // it is streaming to, so it is external as far as the user is concerned even though no-+ // cable is involved. Matches DisplayRepository.isExternallyPresented and Settings'-+ // ConnectedDisplayInjector.isVirtualDisplayAllowed.-+ return display.type == Display.TYPE_VIRTUAL &&-+ (display.flags and Display.FLAG_ALLOWS_CONTENT_MODE_SWITCH) != 0- }- - private fun isSecureDisplay(display: Display): Boolean {