PlayStore: deliver runtime modules and resources on demand

Preserve component file inventories, reuse setup controls, and keep Play-managed resources behind a read-only guest stream. Build version 0.6.9.2 with version code 19 and support large signed release assets.
This commit is contained in:
maxjivi05 committed 2026-11-03 13:27:50 -05:00
1 parent d25f6940ee
commit 5d10c8e96d
25 files changed
+1329 -83

No files matched your search

@@ -6,12 +6,16 @@ import os
from pathlib import Path
import re
import sys
import socket
import struct
from contextlib import contextmanager
import tempfile
import zipfile
DIRECTORY = Path('/opt/droiddeck-bundles')
INDEX = 'assets/play-components/index.json'
SOCKET = '\0com.droiddeck.launcher.play-components'
INDEX_LIMIT = 16 * 1024 * 1024
SHA256 = re.compile(r'[0-9a-f]{64}')
ASSET = re.compile(r'play-components/[0-9a-f]{64}/[0-9]{4,}')
@@ -63,6 +67,25 @@ class BundleReader:
with archive.open(entry) as source:
return json.load(source)
@contextmanager
def open_asset(self, path, module, expected_size):
if module.startswith('playdata'):
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
client.settimeout(30)
client.connect(SOCKET)
encoded = path.encode('utf-8')
client.sendall(struct.pack('>I', len(encoded)) + encoded)
with client.makefile('rb') as source:
if source.read(1) != b'\x01':
raise ValueError('Play resource stream is unavailable')
yield source
else:
archive, entry = self.assets['assets/' + path]
if entry.file_size != expected_size:
raise ValueError('Component chunk size mismatch')
with archive.open(entry) as source:
yield source
def copy(self, url, output, limit, expected_sha256=None):
entry = self.entries.get(url)
if entry is None:
@@ -86,12 +109,9 @@ class BundleReader:
raise ValueError('Invalid component chunk metadata')
if not SHA256.fullmatch(chunk_sha256):
raise ValueError('Invalid component chunk digest')
archive, asset = self.assets['assets/' + path]
if asset.file_size != chunk_size:
raise ValueError('Component chunk size mismatch')
chunk_digest = hashlib.sha256()
copied = 0
with archive.open(asset) as source:
with self.open_asset(path, chunk['module'], chunk_size) as source:
for block in iter(lambda: source.read(65536), b''):
copied += len(block)
total += len(block)
+57
View File
@@ -0,0 +1,57 @@
# Staged Play delivery review
Research date: 2026-11-03. Enforce [the distribution gate](POLICY.md) before implementation.
## Supported approach
A small initial app followed by a Play-hosted download is supported. Use Play Feature Delivery for executable runtime components and Play Asset Delivery for separately classified non-executable data. Both are published in one signed app bundle; Google serves the required pieces. Two user-visible stages need not mean two physical modules.
| Delivery | Appropriate contents | Current compressed limits |
| --- | --- | --- |
| Base and feature modules | App and runtime code with associated resources | 500 MB each; all modules plus install-time asset packs share 4 GB |
| Fast-follow or on-demand asset packs | Non-executable assets | 1.5 GB each; combined 30 GB |
Moving code modules to on-demand delivery reduces the initial install but does not increase their 4 GB allowance. The 34 GB overall allowance is not a native-code allowance. ZIP splitting, nested archives, and external component servers do not change these restrictions. Asset packs explicitly exclude executable code. Do not treat scripts, DLLs, ELF binaries, or a whole mixed runtime archive as asset-only data.
The current stager already divides verified archives into chunks across feature modules. Chunks can cross component boundaries. Merely changing their delivery declaration would leave runtime extraction without required inputs. Version 0.6.9.2 adds on-demand module and asset-pack request/recovery integration using the existing dialog controls.
## Measured candidates
A read-only scan of the pinned Ubuntu desktop, legacy KDE desktop, SteamVR, DroidDeck Proton, and Ubuntu runtime archives identified 764,233,949 uncompressed bytes with selected font, image, audio, and localization extensions. Executable/archive signatures were excluded. This is a preliminary classification, not proof of asset eligibility or compressed space savings. Nested payloads, content, licenses, paths, and extraction dependencies still require review. The FEX SquashFS image was not included in this scan.
| Existing archive | Candidate data, uncompressed bytes |
| --- | ---: |
| Ubuntu desktop | 195,752,173 |
| Legacy KDE desktop | 219,560,513 |
| SteamVR | 223,740,281 |
| DroidDeck Proton | 66,142,728 |
| Ubuntu runtime | 59,038,254 |
The existing bundletool reference-device estimate is approximately 3.939 GB. Further compression has already been applied to legacy KDE and Proton without changing their tar contents. Repartitioning only helps capacity if separately classified data leaves the code modules and the recompressed remainder actually fits. Do not promise the complete historical catalog will fit before measuring the resulting bundle.
## Implementation requirements
1. Inventory every payload by file identity, execution type, license, target path, and dependency. Preserve the complete required file set.
2. Separate verified data assets from code, retaining deterministic per-file hashes and metadata. Rebuild the affected frozen catalogs and extraction recipes rather than modifying pinned upstream files in place.
3. Keep code Play-delivered. Request required feature modules through Play Feature Delivery before extraction. Resolve asset locations through Play Asset Delivery; locations and availability can change after updates.
4. Reuse the existing setup/progress flow. Support cancellation, retries, process death, storage exhaustion, interrupted updates, version consistency, and installed/offline sessions. Never launch with partial components or block the UI.
5. Compare complete installed file inventories and behavior before/after, including controller navigation, first launch, upgrades, games, desktop, audio, VR, and each supported device/runtime path.
6. Measure actual per-device compressed delivery, verify module and total limits, test through a Play internal-testing installation, and obtain physical-device evidence before declaring readiness.
Native component downloads must not be restored as a fallback. Guest storefront downloads and payments require their own policy review; Steam is not a blanket exemption.
## Official references
- [Google Play size limits](https://support.google.com/googleplay/android-developer/answer/9859372?hl=en)
- [Asset delivery modes and executable-code exclusion](https://developer.android.com/guide/playcore/asset-delivery)
- [Feature delivery](https://developer.android.com/guide/playcore/feature-delivery)
- [Conditional feature delivery](https://developer.android.com/guide/playcore/feature-delivery/conditional)
- [External-code and self-update restrictions](https://support.google.com/googleplay/android-developer/answer/16559646?hl=en)
## Version 0.6.9.2 packaging
The Ubuntu runtime, both desktop archives, SteamVR, and DroidDeck Proton are now split into code and classified data frames. Preparation verifies the complete installed file inventory and metadata against the pinned inputs. The app and guest installer concatenate verified frames without recompressing on the device.
The five code portions total 2,555,491,572 bytes; their separate data portions total 449,435,399 bytes. This frees 430,798,764 bytes in the code-delivery budget compared with their previous archives, while increasing their combined compressed size by 18,636,635 bytes. All existing component entries remain present. The staged output has eight on-demand feature modules and one on-demand asset pack. The complete pinned set is requested on first launch.
Fresh installation, interrupted delivery, upgrade, Play confirmation, offline reuse, cancellation, and device-specific behavior still require verification through Google Play internal testing. Packaging checks do not establish Google policy approval.
+37
View File
@@ -0,0 +1,37 @@
# Mandatory Play distribution gate
Applies to the `playstore` branch and every change intended for Google Play, including incoming main commits, dependencies, guest integrations, build inputs, workflows, and release artifacts. Last researched: 2026-11-03. Refresh the relevant official requirements before changing affected behavior.
## Decisions
Refuse known violations. Hold uncertain changes until official documentation or a relevant written Google decision establishes the allowed implementation. Record the behavior, source, reasoning, and remaining verification. Public download availability, redistribution rights, open-source status, user acceptance, or another app's behavior does not establish Google Play compliance. Do not describe an unreviewed baseline as compliant.
Review every incoming commit for external executable downloads, storefront payments and links, permissions, updates, privacy, SDK behavior, native-library compatibility, and delivery limits. Preserve contributor credit. Keep unrelated main development and its latest release untouched. Do not bypass this gate to make a build pass.
## Delivery and executable code
- App self-updates must use Google Play. Do not add APK installation or `REQUEST_INSTALL_PACKAGES` to this distribution.
- Native components must remain Play-delivered, with verified inventory and no external native-code fallback. Use only DroidDeck Proton in the bundled Proton catalog. Do not add extra desktop emulators.
- The virtual-machine/interpreter exception requires a specific analysis of actual Android API access and execution. Steam or another guest storefront is not an automatic exemption. Guest package managers, downloaded scripts, plugins, Windows prerequisites, and purchases need their own review.
- Asset packs contain data, not executable code. Never disguise executable files in archives or chunks to place them in asset packs. Classify extracted payload contents before separating data from runtime code.
- Feature modules can deliver code on demand but do not increase the cumulative code-delivery budget. Current limits: base 500 MB, each feature 500 MB, each asset pack 1.5 GB, modules plus install-time asset packs 4 GB, fast-follow/on-demand asset packs 30 GB. Measure compressed per-device delivery with bundletool and confirm in Play Console.
- On-demand delivery requires explicit missing-module handling, progress, retry, cancellation, version consistency, verified extraction, offline behavior, and recovery after interrupted downloads. Never launch a partial runtime or block the UI while downloading.
## Other mandatory reviews
Purchases and purchase links require the applicable Google payments rules and regional/program eligibility. PC-game branding alone does not exempt a purchase. Privacy disclosures and Data safety must reflect actual app, SDK, guest, and third-party behavior. Review sensitive permissions, foreground-service declarations, accessibility consent, account flows, content ratings, security protections, target SDK, and 16 KB compatibility where relevant.
Signing must use the protected workflow environment and the established certificate. Never track keys, passwords, or aliases, print them, pass them as command arguments, or include them in artifacts. Preserve repository-controlled version codes; never substitute timestamps or workflow counters. Play releases must not replace main's latest release.
Build, test, policy review, redistribution rights, and physical-device verification are separate gates. Report unmet gates explicitly. Obtain actual Play review where documentation does not resolve a distribution mechanism. Existing legacy driver alignment and guest-store policy questions remain unresolved until supported by evidence.
## Official sources
- [Size limits](https://support.google.com/googleplay/android-developer/answer/9859372?hl=en)
- [Play Asset Delivery](https://developer.android.com/guide/playcore/asset-delivery)
- [Play Feature Delivery](https://developer.android.com/guide/playcore/feature-delivery)
- [Device and Network Abuse](https://support.google.com/googleplay/android-developer/answer/16559646?hl=en)
- [Payments](https://support.google.com/googleplay/android-developer/answer/9858738?hl=en)
- [User Data](https://support.google.com/googleplay/android-developer/answer/10144311?hl=en)
- [Permissions and APIs that Access Sensitive Information](https://support.google.com/googleplay/android-developer/answer/9888170?hl=en)
- [16 KB page sizes](https://developer.android.com/guide/practices/page-sizes)
+3 -1
View File
@@ -14,6 +14,8 @@ The Windows prerequisite catalog remains intact. Its downloadable packages have
The separate `playstore-inputs-20261103` prerelease preserves inputs that upstream releases can replace or remove. Its payload filenames are content hashes, and `SOURCE-INVENTORY.json` records their original sources. The manifest retains runtime URL aliases separately from build fetch sources. This input prerelease is never Latest.
Staging verifies each input and deduplicates shared chunks across install-time feature modules. The final bundle check verifies the packaged inventory, every payload hash, individual module sizes, and the cumulative 4 GB budget. Bundle validation, 16 KB native-library alignment, and audio verification must also pass before signing.
Staging verifies each input and deduplicates shared chunks across on-demand feature modules. Classified non-executable resources from the largest runtime archives use separate on-demand Play asset packs. Native code never enters asset packs. The app requests the complete pinned delivery set on first launch using its existing dialog, progress, Retry, and Cancel controls. Interrupted Play requests resume on the next attempt; partial runtimes are not launched. The final bundle check verifies the packaged inventory, every payload hash, individual module sizes, and the cumulative 4 GB code-delivery budget and the separate asset-pack budgets. Split archive preparation verifies every file's content and metadata against its pinned source before accepting a new archive identity. Bundle validation, 16 KB native-library alignment, and audio verification must also pass before signing.
Build checks establish artifact integrity. Device testing and Google Play review remain separate requirements.
GitHub release assets are limited to less than 2 GiB each. Large signed bundles are published as numbered parts with full-bundle and per-part checksums and reconstruction instructions. The workflow artifact always retains the complete signed AAB for direct Play upload.
+214 -38
View File
@@ -22,8 +22,8 @@
"urls": [
"https://github.com/Droid-Deck/DroidDeck-Components/releases/download/ubuntu-r1-rc4/ubuntu-r1-rc4.tar.zst"
],
"size": 291531733,
"sha256": "a90882efc4b0fc308887f8719c21825f0d17d51698296cd3047b6da2491c4396",
"size": 292945191,
"sha256": "8c0607cb6fc524467d6a68d3116c0e910b1238aab38430132a7b5b127464712c",
"provides": [
"runtime-ubuntu"
],
@@ -34,6 +34,41 @@
"url": "https://github.com/Droid-Deck/DroidDeck/tree/e3c3471d2fbe5be37a5f0b7f6243f969a86f03ce/tools/ubuntu",
"approved": true,
"redistribution_review": "Project owner confirmed runtime redistribution permission. Original vendor terms and included notices remain applicable."
},
"layout": {
"zstd_version": "1.5.5",
"inventory_sha256": "568bdaa85f29b8a17c2ddd2b13fc8044ac61bee3dcf8354470980a7387525c7c",
"segments": [
{
"sha256": "6e9440a9ee6c9c72756686754081fd9c9a64ee7e54a219ac4b06456eb689b335",
"size": 266830319,
"kind": "code"
},
{
"sha256": "3b3876bab93bf511c91f9ad09231123a98a45495c4ea607b6f29b39ec438108c",
"size": 26114872,
"kind": "data"
}
],
"source": {
"id": "runtime-ubuntu",
"urls": [
"https://github.com/Droid-Deck/DroidDeck-Components/releases/download/ubuntu-r1-rc4/ubuntu-r1-rc4.tar.zst"
],
"size": 291531733,
"sha256": "a90882efc4b0fc308887f8719c21825f0d17d51698296cd3047b6da2491c4396",
"provides": [
"runtime-ubuntu"
],
"source": "https://github.com/Droid-Deck/DroidDeck/tree/e3c3471d2fbe5be37a5f0b7f6243f969a86f03ce/tools/ubuntu",
"source_commit": "e3c3471d2fbe5be37a5f0b7f6243f969a86f03ce",
"license": {
"expression": "LicenseRef-Runtime-Redistribution",
"url": "https://github.com/Droid-Deck/DroidDeck/tree/e3c3471d2fbe5be37a5f0b7f6243f969a86f03ce/tools/ubuntu",
"approved": true,
"redistribution_review": "Project owner confirmed runtime redistribution permission. Original vendor terms and included notices remain applicable."
}
}
}
},
{
@@ -41,8 +76,8 @@
"urls": [
"https://github.com/Droid-Deck/DroidDeck-Components/releases/download/ubuntu-r1-rc4/ubuntu-r1-rc4-desktop.tar.zst"
],
"size": 898214853,
"sha256": "09792f8470978907ad482bdce7f83ff8488fcc2176d34b63b663b54604208554",
"size": 900173937,
"sha256": "36a94b31582fc1f2294d208265aa2b7b8931be85854b4071e14018f5baa685f6",
"provides": [
"desktop-ubuntu"
],
@@ -53,6 +88,41 @@
"url": "https://github.com/Droid-Deck/DroidDeck/tree/e3c3471d2fbe5be37a5f0b7f6243f969a86f03ce/tools/ubuntu",
"approved": true,
"redistribution_review": "Project owner confirmed runtime redistribution permission. Original vendor terms and included notices remain applicable."
},
"layout": {
"zstd_version": "1.5.5",
"inventory_sha256": "63740fea4a377941a6a4805476def88cf1f76f169f33c29a8a21838f0ee30ed6",
"segments": [
{
"sha256": "535b6ede3260627b8eaeb080e3a2e9f3b2bdb89347e02f2ffc40eecd340a5a2c",
"size": 797670278,
"kind": "code"
},
{
"sha256": "ad34c61295a8a4d7825737d7940242332ef07496fe02103a533e131add936eec",
"size": 102503659,
"kind": "data"
}
],
"source": {
"id": "desktop-ubuntu",
"urls": [
"https://github.com/Droid-Deck/DroidDeck-Components/releases/download/ubuntu-r1-rc4/ubuntu-r1-rc4-desktop.tar.zst"
],
"size": 898214853,
"sha256": "09792f8470978907ad482bdce7f83ff8488fcc2176d34b63b663b54604208554",
"provides": [
"desktop-ubuntu"
],
"source": "https://github.com/Droid-Deck/DroidDeck/tree/e3c3471d2fbe5be37a5f0b7f6243f969a86f03ce/tools/ubuntu",
"source_commit": "e3c3471d2fbe5be37a5f0b7f6243f969a86f03ce",
"license": {
"expression": "LicenseRef-Runtime-Redistribution",
"url": "https://github.com/Droid-Deck/DroidDeck/tree/e3c3471d2fbe5be37a5f0b7f6243f969a86f03ce/tools/ubuntu",
"approved": true,
"redistribution_review": "Project owner confirmed runtime redistribution permission. Original vendor terms and included notices remain applicable."
}
}
}
},
{
@@ -101,8 +171,8 @@
"urls": [
"https://steamdeck-packages.steamos.cloud/archlinux-deckard-hotfixes/release/0.3.x/deckard-steamvr-rel-r25358740%2B28b72a4f-1-aarch64.pkg.tar.zst"
],
"size": 571309057,
"sha256": "90a600775eb3e8856dc475f83166a93a290a0b1f3b4e82a69c8e2a8f06b9ddc9",
"size": 586728368,
"sha256": "f63540644dc7015844233ad92a46a275fed32bece015eccccd99af605e5af2e0",
"provides": [
"steamvr"
],
@@ -116,15 +186,53 @@
},
"fetch_urls": [
"https://github.com/Droid-Deck/DroidDeck/releases/download/playstore-inputs-20261103/90a600775eb3e8856dc475f83166a93a290a0b1f3b4e82a69c8e2a8f06b9ddc9.payload"
]
],
"layout": {
"zstd_version": "1.5.5",
"inventory_sha256": "a567011543a228a98a0f9bded4380937b2a609b6dc4c24a14c550cd6ac76da6d",
"segments": [
{
"sha256": "189a03b41d5ea333eb78f16c42ec72d5288def7b873af2bb93598e22f983983c",
"size": 395927049,
"kind": "code"
},
{
"sha256": "f444316c520865e4bda6e20c75734089244648495034ea3b6af5d7faa54546f8",
"size": 190801319,
"kind": "data"
}
],
"source": {
"id": "steamvr",
"urls": [
"https://steamdeck-packages.steamos.cloud/archlinux-deckard-hotfixes/release/0.3.x/deckard-steamvr-rel-r25358740%2B28b72a4f-1-aarch64.pkg.tar.zst"
],
"size": 571309057,
"sha256": "90a600775eb3e8856dc475f83166a93a290a0b1f3b4e82a69c8e2a8f06b9ddc9",
"provides": [
"steamvr"
],
"source": "https://github.com/Droid-Deck/DroidDeck-Components/blob/b9f52fcc335f2e5e627aadfb4b5cd2a7d027eacb/fex.json",
"source_commit": "b9f52fcc335f2e5e627aadfb4b5cd2a7d027eacb",
"license": {
"expression": "LicenseRef-Runtime-Redistribution",
"url": "https://github.com/Droid-Deck/DroidDeck-Components/blob/b9f52fcc335f2e5e627aadfb4b5cd2a7d027eacb/fex.json",
"approved": true,
"redistribution_review": "Project owner confirmed runtime redistribution permission. Original vendor terms and included notices remain applicable."
},
"fetch_urls": [
"https://github.com/Droid-Deck/DroidDeck/releases/download/playstore-inputs-20261103/90a600775eb3e8856dc475f83166a93a290a0b1f3b4e82a69c8e2a8f06b9ddc9.payload"
]
}
}
},
{
"id": "droiddeck-proton",
"urls": [
"droiddeck-bundle://droiddeck-proton/DroidDeck-Proton-11-11.11-aarch64.tar.zst"
],
"size": 433732447,
"sha256": "5cb7d4135758d7a71cc17cd66c358b61309223be28c428292365b0643ee3f2fd",
"size": 433780446,
"sha256": "0a024e2818150554c6acb2719bf163bad51c3f306479c11cb73c7a5acd4f59fc",
"provides": [
"proton:droiddeck"
],
@@ -136,18 +244,51 @@
"approved": true,
"redistribution_review": "Project owner confirmed runtime redistribution permission. Original vendor terms and included notices remain applicable."
},
"upstream": {
"size": 625578225,
"sha256": "d1d358ea48a040abb2b50b13dd35e952907e62e6cca38e3e575f4cd357876a4e",
"urls": [
"https://github.com/Droid-Deck/DroidDeck-Proton/releases/download/DroidDeck-Proton-11-11.11/DroidDeck-Proton-11-11.11-aarch64.tar.gz"
]
},
"prepare": {
"method": "gzip-to-zstd-19",
"layout": {
"zstd_version": "1.5.5",
"tar_sha256": "4073cc3e82463a315b47aad2a77aa06e5561a786e1c3743d6ca24bd5209a8fe9",
"tar_size": 2098657280
"inventory_sha256": "654f083ecc807aad9d039d2ae7b5d4cad8e0492031eec138fb2e4cbf4469b6ed",
"segments": [
{
"sha256": "b806baf5935af02d49567728634e2356e53887671fe4180ebf1a7b77e7208622",
"size": 411117904,
"kind": "code"
},
{
"sha256": "82dc230ebf0b4c3016802e88987493feea70927337cae30e9e1b95445f8d3013",
"size": 22662542,
"kind": "data"
}
],
"source": {
"id": "droiddeck-proton",
"urls": [],
"size": 433732447,
"sha256": "5cb7d4135758d7a71cc17cd66c358b61309223be28c428292365b0643ee3f2fd",
"provides": [
"proton:droiddeck"
],
"source": "https://github.com/Droid-Deck/DroidDeck-Proton/tree/e0de7fb0f240be559412d7ddf4eaacb2e9390c52",
"source_commit": "e0de7fb0f240be559412d7ddf4eaacb2e9390c52",
"license": {
"expression": "LicenseRef-Runtime-Redistribution",
"url": "https://github.com/Droid-Deck/DroidDeck-Proton/tree/e0de7fb0f240be559412d7ddf4eaacb2e9390c52",
"approved": true,
"redistribution_review": "Project owner confirmed runtime redistribution permission. Original vendor terms and included notices remain applicable."
},
"upstream": {
"size": 625578225,
"sha256": "d1d358ea48a040abb2b50b13dd35e952907e62e6cca38e3e575f4cd357876a4e",
"urls": [
"https://github.com/Droid-Deck/DroidDeck-Proton/releases/download/DroidDeck-Proton-11-11.11/DroidDeck-Proton-11-11.11-aarch64.tar.gz"
]
},
"prepare": {
"method": "gzip-to-zstd-19",
"zstd_version": "1.5.5",
"tar_sha256": "4073cc3e82463a315b47aad2a77aa06e5561a786e1c3743d6ca24bd5209a8fe9",
"tar_size": 2098657280
}
}
}
},
{
@@ -155,8 +296,8 @@
"urls": [
"https://github.com/Droid-Deck/DroidDeck-Components/releases/download/desktop-kde-r3/desktop-kde.tar.zst"
],
"size": 791502246,
"sha256": "319bf9dc8c128877de80ff76ac9485ef443cd5eed75ae28646d346c5c82156f1",
"size": 791299029,
"sha256": "f2f8ee3349b356400df93dc9c12e8be5220eab88c63f8b9fcbcd927b7219cacb",
"provides": [
"desktop-legacy-kde"
],
@@ -168,18 +309,53 @@
"approved": true,
"redistribution_review": "Project owner confirmed runtime redistribution permission. Original vendor terms and included notices remain applicable."
},
"prepare": {
"method": "zstd-to-zstd-19",
"layout": {
"zstd_version": "1.5.5",
"tar_size": 2865295360,
"tar_sha256": "8f2196516d043b1e0a1c5aacb42030bd349c53c38dee4d67efa2581addd3aa3f"
},
"upstream": {
"urls": [
"https://github.com/Droid-Deck/DroidDeck-Components/releases/download/desktop-kde-r3/desktop-kde.tar.zst"
"inventory_sha256": "5b3d6904f6243128a5f6cdf9d4d80aaf7d7634800ed39587479848bbd84b7d5d",
"segments": [
{
"sha256": "136879b98c8aa919f60d1c0ae43b698bdced569016a7ab4fa6f1cfdacabadbb0",
"size": 683946022,
"kind": "code"
},
{
"sha256": "4ac719249db32d419aaef97662db79ad612a8b831dfd254abea34e46adbe0953",
"size": 107353007,
"kind": "data"
}
],
"sha256": "8b7142fcec8d86143ae39fc14ffc86907d30d9a5b5a45f49cb1b55109d6fc4eb",
"size": 972598429
"source": {
"id": "desktop-legacy-kde",
"urls": [
"https://github.com/Droid-Deck/DroidDeck-Components/releases/download/desktop-kde-r3/desktop-kde.tar.zst"
],
"size": 791502246,
"sha256": "319bf9dc8c128877de80ff76ac9485ef443cd5eed75ae28646d346c5c82156f1",
"provides": [
"desktop-legacy-kde"
],
"source": "https://github.com/Droid-Deck/DroidDeck-Components/blob/b9f52fcc335f2e5e627aadfb4b5cd2a7d027eacb/components.json",
"source_commit": "b9f52fcc335f2e5e627aadfb4b5cd2a7d027eacb",
"license": {
"expression": "LicenseRef-Runtime-Redistribution",
"url": "https://github.com/Droid-Deck/DroidDeck-Components/blob/b9f52fcc335f2e5e627aadfb4b5cd2a7d027eacb/components.json",
"approved": true,
"redistribution_review": "Project owner confirmed runtime redistribution permission. Original vendor terms and included notices remain applicable."
},
"prepare": {
"method": "zstd-to-zstd-19",
"zstd_version": "1.5.5",
"tar_size": 2865295360,
"tar_sha256": "8f2196516d043b1e0a1c5aacb42030bd349c53c38dee4d67efa2581addd3aa3f"
},
"upstream": {
"urls": [
"https://github.com/Droid-Deck/DroidDeck-Components/releases/download/desktop-kde-r3/desktop-kde.tar.zst"
],
"sha256": "8b7142fcec8d86143ae39fc14ffc86907d30d9a5b5a45f49cb1b55109d6fc4eb",
"size": 972598429
}
}
}
},
{
@@ -188,7 +364,7 @@
"https://raw.githubusercontent.com/Droid-Deck/DroidDeck-Components/main/linuxfs-ubuntu.json"
],
"size": 961,
"sha256": "71ee77b177a58d2249585e2de30502f5387e99cbf93c31ad12a76466ae270792",
"sha256": "24e6efe411cbbdde345236d6ea9a09ceb50e4c4920634731996150216956c2b2",
"provides": [
"catalog:linuxfs-ubuntu"
],
@@ -207,8 +383,8 @@
"name": "Linux runtime (Ubuntu 26.04 LTS)",
"version": "ubuntu-r1-rc4",
"url": "https://github.com/Droid-Deck/DroidDeck-Components/releases/download/ubuntu-r1-rc4/ubuntu-r1-rc4.tar.zst",
"sha256": "a90882efc4b0fc308887f8719c21825f0d17d51698296cd3047b6da2491c4396",
"size": 291531733,
"sha256": "8c0607cb6fc524467d6a68d3116c0e910b1238aab38430132a7b5b127464712c",
"size": 292945191,
"file_size": 291531733,
"note": "Ubuntu 26.04 LTS arm64 runtime for DroidDeck, built by tools/ubuntu in Droid-Deck/DroidDeck (PR #1733); rc2 adds libxcb-keysyms1 so the DD-Turnip driver loads (PR #1773); rc3 adds libva-drm2 and libva-x11-2 so Proton's media decoder loads and game cutscenes play (PR #1823); rc4 adds liblzo2-2 so FEX's unsquashfs runs and the x86-64 Steam client starts (PR #1825). Its Kubuntu Plasma desktop pack is ubuntu-r1-rc4-desktop.tar.zst in the same release, named inside the runtime at usr/share/droiddeck/desktop-pack.json. Release candidate: only test builds of PR #1733 read this file."
}
@@ -9065,7 +9241,7 @@
"https://api.github.com/repos/Droid-Deck/DroidDeck-Proton/releases"
],
"size": 486,
"sha256": "b8590d6dfb988689ae17e8cde38e333d744e2a7898af95e25bcf67c922df3c78",
"sha256": "7572817b4efca8bf0c2e34897c69b5703b25cd704b9b2b2a39fb8f402ccbb72f",
"provides": [
"catalog:proton"
],
@@ -9088,8 +9264,8 @@
"assets": [
{
"name": "DroidDeck-Proton-11-11.11-aarch64.tar.zst",
"size": 433732447,
"digest": "sha256:5cb7d4135758d7a71cc17cd66c358b61309223be28c428292365b0643ee3f2fd",
"size": 433780446,
"digest": "sha256:0a024e2818150554c6acb2719bf163bad51c3f306479c11cb73c7a5acd4f59fc",
"browser_download_url": "droiddeck-bundle://droiddeck-proton/DroidDeck-Proton-11-11.11-aarch64.tar.zst",
"content_type": "application/zstd"
}
+117 -18
View File
@@ -1,6 +1,7 @@
import argparse
import hashlib
import json
import os
import re
import ssl
import sys
@@ -55,6 +56,7 @@ def load_manifest(path):
raise ValueError('Payload manifest is empty')
urls = set()
identities = {}
data_identities = {}
ids = set()
for entry in entries:
identity = entry.get('id', '')
@@ -80,7 +82,24 @@ def load_manifest(path):
if 'content' in entry or entry.get('prepare'):
raise ValueError('External Windows prerequisites cannot replace bundled catalogs')
else:
identities[digest] = size
layout = entry.get('layout')
if layout is None:
identities[digest] = size
else:
parts = layout.get('segments', [])
if len(parts) != 2 or [part.get('kind') for part in parts] != ['code', 'data'] or sum(part.get('size', 0) for part in parts) != size:
raise ValueError('Invalid split component layout: ' + identity)
if not re.fullmatch(r'[a-f0-9]{64}', layout.get('inventory_sha256', '')) or layout.get('zstd_version') != '1.5.5':
raise ValueError('Split component inventory is unpinned')
source = layout.get('source', {})
if not re.fullmatch(r'[a-f0-9]{64}', source.get('sha256', '')) or type(source.get('size')) is not int or source['size'] <= 0 or 'layout' in source:
raise ValueError('Split component source is unpinned')
for url in source.get('fetch_urls', source.get('urls', [])):
https_url(url)
for part in parts:
if not re.fullmatch(r'[a-f0-9]{64}', part.get('sha256', '')) or type(part.get('size')) is not int or part['size'] <= 0:
raise ValueError('Split component segment is unpinned')
(identities if part['kind'] == 'code' else data_identities)[part['sha256']] = part['size']
if 'storage_chunk_bytes' in entry and (type(entry['storage_chunk_bytes']) is not int or
not 65536 <= entry['storage_chunk_bytes'] <= CHUNK_BYTES):
raise ValueError('Invalid component storage chunk size: ' + identity)
@@ -94,7 +113,7 @@ def load_manifest(path):
https_url(url)
for url in aliases:
if url.startswith('droiddeck-bundle://'):
if not re.fullmatch(r'droiddeck-bundle://[a-z0-9][a-z0-9._-]*/[A-Za-z0-9._+-]+', url) or not entry.get('prepare'):
if not re.fullmatch(r'droiddeck-bundle://[a-z0-9][a-z0-9._-]*/[A-Za-z0-9._+-]+', url) or not (entry.get('prepare') or entry.get('layout')):
raise ValueError('Invalid prepared component alias: ' + identity)
else:
https_url(url)
@@ -134,6 +153,8 @@ def load_manifest(path):
missing = set(required) - provided
if missing:
raise ValueError('Missing component coverage: ' + ', '.join(sorted(missing)))
if sum(data_identities.values()) > 30_000_000_000:
raise ValueError('Play data asset budget exceeded')
total = sum(identities.values())
if total + RESERVED_BYTES > TOTAL_BYTES:
raise ValueError(f'Payload size budget exceeded: {total} + {RESERVED_BYTES} reserved > {TOTAL_BYTES}')
@@ -154,7 +175,8 @@ def validate_play_engines(manifest):
engines = {name for name in entry.get('provides', []) if name.startswith('proton:')}
if engines - {'proton:droiddeck'}:
raise ValueError('Play distribution permits only DroidDeck Proton')
source_urls = entry.get('upstream', {}).get('urls', entry['urls'])
original = entry.get('layout', {}).get('source', entry)
source_urls = original.get('upstream', {}).get('urls', original['urls'])
for url in [*entry['urls'], *source_urls]:
lower = url.lower()
parsed = urllib.parse.urlsplit(url)
@@ -190,6 +212,23 @@ def fetch(entry, cache):
output.write(data)
temporary.rename(target)
return target
if entry.get('layout'):
from tools.playstore.split_archive import prepare, combine, inventory
layout = entry['layout']
original = fetch(layout['source'], cache)
code, data = [cache / (entry['sha256'] + '.' + name + '.part') for name in ['code', 'data']]
prepared = prepare(original, code, data, layout['zstd_version'])
if any(prepared[key] != layout[key] for key in ['segments', 'inventory_sha256', 'zstd_version']):
raise ValueError('Split archive identity changed')
combine([code, data], temporary)
if temporary.stat().st_size != entry['size'] or sha256(temporary) != entry['sha256'] or inventory(temporary, os.environ.get('DROIDDECK_ZSTD', 'zstd'))[0] != layout['inventory_sha256']:
raise ValueError('Split archive failed reconstruction verification')
temporary.rename(target)
for source, segment in zip([code, data], layout['segments']):
destination = cache / segment['sha256']
if not destination.exists():
source.rename(destination)
return target
if entry.get('prepare'):
from tools.playstore.prepare_archive import prepare
upstream = fetch(dict(entry['upstream'], id='upstream-' + entry['id']), cache)
@@ -222,11 +261,41 @@ def stage(manifest, cache, output, chunk_bytes=CHUNK_BYTES, module_bytes=MODULE_
if output.exists():
raise ValueError('Output must be a new directory: ' + str(output))
payloads = {}
data_payloads = set()
layouts = {}
for entry in manifest['entries']:
if entry.get('delivery') == 'windows-guest':
continue
if entry['sha256'] not in payloads:
payloads[entry['sha256']] = fetch(entry, cache)
if entry['sha256'] in layouts:
continue
original = fetch(entry, cache)
if entry.get('layout'):
parts = entry['layout']['segments']
with original.open('rb') as source:
for part in parts:
destination = cache / part['sha256']
if not destination.exists():
with destination.open('xb') as target:
remaining = part['size']
while remaining:
block = source.read(min(1024 * 1024, remaining))
if not block:
raise ValueError('Truncated split archive')
target.write(block)
remaining -= len(block)
else:
source.seek(part['size'], 1)
if destination.stat().st_size != part['size'] or sha256(destination) != part['sha256']:
raise ValueError('Split archive segment failed verification')
payloads[part['sha256']] = destination
if part['kind'] == 'data':
from tools.playstore.split_archive import validate_data
validate_data(destination)
data_payloads.add(part['sha256'])
layouts[entry['sha256']] = [part['sha256'] for part in parts]
else:
payloads[entry['sha256']] = original
layouts[entry['sha256']] = [entry['sha256']]
output.mkdir(parents=True)
index = {'schema': 1, 'manifest_sha256': hashlib.sha256(
json.dumps(manifest, sort_keys=True, separators=(',', ':')).encode()).hexdigest(), 'entries': {}}
@@ -234,6 +303,8 @@ def stage(manifest, cache, output, chunk_bytes=CHUNK_BYTES, module_bytes=MODULE_
used = 0
chunks = {}
shared = {}
data_module = 1
data_used = 0
for digest, path in sorted(payloads.items()):
pieces = []
block_bytes = min([chunk_bytes] + [entry.get('storage_chunk_bytes', chunk_bytes) for entry in manifest['entries']
@@ -242,14 +313,23 @@ def stage(manifest, cache, output, chunk_bytes=CHUNK_BYTES, module_bytes=MODULE_
number = 0
for block in iter(lambda: stream.read(block_bytes), b''):
chunk_digest = hashlib.sha256(block).hexdigest()
if chunk_digest in shared:
pieces.append(shared[chunk_digest])
shared_key = (digest in data_payloads, chunk_digest)
if shared_key in shared:
pieces.append(shared[shared_key])
number += 1
continue
if used + len(block) > module_bytes:
module += 1
used = 0
name = f'playpayload{module:02d}'
if digest in data_payloads:
if data_used + len(block) > 1_400_000_000:
data_module += 1
data_used = 0
name = f'playdata{data_module:02d}'
data_used += len(block)
else:
if used + len(block) > module_bytes:
module += 1
used = 0
name = f'playpayload{module:02d}'
used += len(block)
asset = f'play-components/{digest}/{number:04d}'
target = output / name / 'src/main/assets' / asset
target.parent.mkdir(parents=True, exist_ok=True)
@@ -257,14 +337,14 @@ def stage(manifest, cache, output, chunk_bytes=CHUNK_BYTES, module_bytes=MODULE_
destination.write(block)
piece = {'asset': asset, 'module': name, 'size': len(block), 'sha256': chunk_digest}
pieces.append(piece)
shared[chunk_digest] = piece
used += len(block)
shared[shared_key] = piece
number += 1
chunks[digest] = pieces
base = output / 'base/src/main/assets/play-components'
recipes = base / 'recipes'
recipes.mkdir(parents=True)
for digest, pieces in chunks.items():
for digest, sources in layouts.items():
pieces = [piece for source in sources for piece in chunks[source]]
(recipes / (digest + '.json')).write_text(json.dumps({'chunks': pieces}, separators=(',', ':')) + '\n')
for entry in manifest['entries']:
for url in entry['urls']:
@@ -292,12 +372,18 @@ def stage(manifest, cache, output, chunk_bytes=CHUNK_BYTES, module_bytes=MODULE_
'<manifest xmlns:android="http://schemas.android.com/apk/res/android" '
'xmlns:dist="http://schemas.android.com/apk/distribution">\n'
' <dist:module dist:instant="false" dist:title="@string/app_name">\n'
' <dist:delivery><dist:install-time><dist:removable dist:value="true" />'
'</dist:install-time></dist:delivery>\n'
' <dist:delivery><dist:on-demand /></dist:delivery>\n'
' <dist:fusing dist:include="true" />\n'
' </dist:module>\n'
' <application android:hasCode="false" />\n'
'</manifest>\n')
packs = [f'playdata{number:02d}' for number in range(1, data_module + 1)] if data_payloads else []
for name in packs:
(output / name / 'build.gradle').write_text(
"plugins { id 'com.android.asset-pack' }\n"
f"assetPack {{ packName = '{name}'; dynamicDelivery {{ deliveryType = 'on-demand' }} }}\n")
(base / 'delivery.json').write_text(json.dumps({'modules': modules, 'packs': packs}, separators=(',', ':')) + '\n')
(output / 'assetpacks.json').write_text(json.dumps(packs) + '\n')
(output / 'modules.json').write_text(json.dumps(modules) + '\n')
return index
@@ -340,8 +426,14 @@ def verify_bundle(manifest, bundle):
digest = hashlib.sha256()
size = 0
identity = json.dumps(entry, sort_keys=True)
logical_size = 0
for chunk in pieces:
if not re.fullmatch(r'playpayload[0-9]{2}', chunk['module']) or not re.fullmatch(
boundary = pinned.get('layout', {}).get('segments', [{'size': pinned['size']}])[0]['size']
expected_module = 'playpayload' if logical_size < boundary else 'playdata'
if not chunk['module'].startswith(expected_module) or logical_size < boundary < logical_size + chunk['size']:
raise ValueError('Executable and data component delivery are mixed')
logical_size += chunk['size']
if not re.fullmatch(r'(?:playpayload|playdata)[0-9]{2}', chunk['module']) or not re.fullmatch(
r'play-components/[0-9a-f]{64}/[0-9]{4,}', chunk['asset']):
raise ValueError('Invalid bundle chunk path')
path = chunk['module'] + '/assets/' + chunk['asset']
@@ -367,13 +459,20 @@ def verify_bundle(manifest, bundle):
if delivered != referenced:
raise ValueError('Bundle contains unreferenced component chunks')
base_assets = {name for name in package.namelist() if name.startswith('base/assets/play-components/')}
if base_assets != referenced_recipes | {'base/assets/play-components/index.json', 'base/assets/play-components/provenance.json'}:
if base_assets != referenced_recipes | {'base/assets/play-components/index.json', 'base/assets/play-components/provenance.json', 'base/assets/play-components/delivery.json'}:
raise ValueError('Bundle contains unreferenced component recipes')
sizes = {}
for info in package.infolist():
module = info.filename.split('/')[0]
if module == 'base' or module.startswith('playpayload'):
sizes[module] = sizes.get(module, 0) + info.compress_size
asset_sizes = {}
for info in package.infolist():
name = info.filename.split('/')[0]
if re.fullmatch(r'playdata[0-9]{2}', name):
asset_sizes[name] = asset_sizes.get(name, 0) + info.compress_size
if any(size > 1_500_000_000 for size in asset_sizes.values()) or sum(asset_sizes.values()) > 30_000_000_000:
raise ValueError('Bundle exceeds the Play asset pack budget')
if any(size > 500_000_000 for size in sizes.values()) or sum(sizes.values()) > TOTAL_BYTES:
raise ValueError('Bundle exceeds the conservative module download-size budget')
return sizes
+54
View File
@@ -0,0 +1,54 @@
import argparse
import hashlib
from pathlib import Path
def prepare(bundle, checksums, output, limit=2_000_000_000):
bundle, checksums, output = Path(bundle), Path(checksums), Path(output)
if limit <= 0 or limit >= 2_147_483_648 or output.exists() or bundle.is_symlink():
raise ValueError('Release assets require a new directory and a safe file limit')
expected = None
for line in checksums.read_text().splitlines():
fields = line.split()
if len(fields) == 2 and fields[1].lstrip('*') == bundle.name:
if expected is not None:
raise ValueError('Duplicate bundle checksum')
expected = fields[0]
if expected is None:
raise ValueError('Signed bundle checksum is missing')
output.mkdir(parents=True)
digest = hashlib.sha256()
parts = []
remaining = bundle.stat().st_size
split = remaining > limit
with bundle.open('rb') as source:
while remaining:
name = bundle.name + f'.part{len(parts) + 1:03d}' if split else bundle.name
part_digest = hashlib.sha256()
with (output / name).open('xb') as destination:
size = min(remaining, limit)
while size:
block = source.read(min(size, 1024 * 1024))
if not block:
raise ValueError('Signed bundle was truncated')
destination.write(block)
digest.update(block)
part_digest.update(block)
size -= len(block)
remaining -= len(block)
parts.append((name, part_digest.hexdigest()))
if source.read(1) or digest.hexdigest() != expected:
raise ValueError('Signed bundle failed checksum verification')
(output / 'SHA256SUMS').write_text(expected + ' ' + bundle.name + '\n')
if split:
(output / 'PART-SHA256SUMS').write_text(''.join(digest + ' ' + name + '\n' for name, digest in parts))
return [name for name, _ in parts]
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--bundle', type=Path, required=True)
parser.add_argument('--checksums', type=Path, required=True)
parser.add_argument('--output', type=Path, required=True)
args = parser.parse_args()
prepare(args.bundle, args.checksums, args.output)
+223
View File
@@ -0,0 +1,223 @@
import hashlib
import json
import os
from pathlib import Path, PurePosixPath
import subprocess
import tarfile
def identity(path):
digest = hashlib.sha256()
with Path(path).open('rb') as source:
for block in iter(lambda: source.read(1024 * 1024), b''):
digest.update(block)
return {'sha256': digest.hexdigest(), 'size': Path(path).stat().st_size}
def data_file(member, magic):
if not member.isfile():
return False
extension = PurePosixPath(member.name).suffix.lower()
signatures = {
'.png': (b'\x89PNG\r\n\x1a\n',), '.jpg': (b'\xff\xd8\xff',),
'.jpeg': (b'\xff\xd8\xff',), '.ttf': (b'\x00\x01\x00\x00', b'ttcf', b'true'),
'.otf': (b'OTTO',), '.woff': (b'wOFF',), '.woff2': (b'wOF2',),
'.ogg': (b'OggS',), '.flac': (b'fLaC',),
'.mo': (b'\xde\x12\x04\x95', b'\x95\x04\x12\xde'),
}
if extension in signatures:
return magic.startswith(signatures[extension])
if extension == '.webp':
return magic.startswith(b'RIFF') and magic[8:12] == b'WEBP'
if extension == '.wav':
return magic.startswith(b'RIFF') and magic[8:12] == b'WAVE'
return False
def inventory(source, zstd):
process = subprocess.Popen([zstd, '-dc', str(source)], stdout=subprocess.PIPE)
records = []
links = set()
names = set()
candidates = set()
try:
with tarfile.open(fileobj=process.stdout, mode='r|') as archive:
for member in archive:
path = PurePosixPath(member.name)
if path.is_absolute() or '..' in path.parts or member.name in names:
raise ValueError('Archive contains an unsafe or repeated path: ' + member.name)
names.add(member.name)
digest = hashlib.sha256()
magic = b''
if member.isfile():
stream = archive.extractfile(member)
for block in iter(lambda: stream.read(1024 * 1024), b''):
if not magic:
magic = block[:16]
digest.update(block)
if data_file(member, magic):
candidates.add(member.name)
if member.islnk():
links.add(member.linkname)
records.append([member.name, member.type.decode('ascii'), member.size, member.mode,
member.uid, member.gid, member.uname, member.gname, member.mtime,
member.linkname, member.devmajor, member.devminor,
{key: value for key, value in member.pax_headers.items() if key not in
{'path', 'linkpath', 'mtime', 'size', 'uid', 'gid', 'uname', 'gname'}},
digest.hexdigest() if member.isfile() else None])
if process.wait():
raise ValueError('Archive decompression failed')
finally:
process.stdout.close()
if process.poll() is None:
process.terminate()
process.wait()
candidates -= links
records.sort(key=lambda item: item[0])
digest = hashlib.sha256(json.dumps(records, sort_keys=True, separators=(',', ':')).encode()).hexdigest()
return digest, candidates
def prepare(source, code, data, zstd_version='1.5.5'):
zstd = os.environ.get('DROIDDECK_ZSTD', 'zstd')
if 'v' + zstd_version + ',' not in subprocess.check_output([zstd, '--version'], text=True):
raise ValueError('Split archives require the pinned zstd version')
original, candidates = inventory(source, zstd)
if not candidates:
raise ValueError('Archive has no classified data assets')
segments = []
for kind, destination in [('code', code), ('data', data)]:
decoder = subprocess.Popen([zstd, '-dc', str(source)], stdout=subprocess.PIPE)
with Path(destination).open('xb') as output:
encoder = subprocess.Popen([zstd, '-19', '-T4', '-c'], stdin=subprocess.PIPE, stdout=output)
try:
with tarfile.open(fileobj=decoder.stdout, mode='r|') as archive:
for member in archive:
if (member.name in candidates) != (kind == 'data'):
continue
encoder.stdin.write(member.tobuf(format=tarfile.PAX_FORMAT))
if member.isfile():
stream = archive.extractfile(member)
remaining = member.size
while remaining:
block = stream.read(min(1024 * 1024, remaining))
if not block:
raise ValueError('Truncated archive member')
encoder.stdin.write(block)
remaining -= len(block)
encoder.stdin.write(b'\0' * (-member.size % 512))
if kind == 'data':
encoder.stdin.write(b'\0' * 10240)
encoder.stdin.close()
if decoder.wait() or encoder.wait():
raise ValueError('Split archive preparation failed')
finally:
decoder.stdout.close()
if not encoder.stdin.closed:
encoder.stdin.close()
for process in [decoder, encoder]:
if process.poll() is None:
process.terminate()
process.wait()
segments.append(dict(identity(destination), kind=kind))
return {'zstd_version': zstd_version, 'inventory_sha256': original, 'segments': segments}
def combine(paths, destination):
with Path(destination).open('xb') as output:
for path in paths:
with Path(path).open('rb') as source:
for block in iter(lambda: source.read(1024 * 1024), b''):
output.write(block)
def validate_data(source):
process = subprocess.Popen([os.environ.get('DROIDDECK_ZSTD', 'zstd'), '-dc', str(source)], stdout=subprocess.PIPE)
found = False
try:
with tarfile.open(fileobj=process.stdout, mode='r|') as archive:
for member in archive:
if not member.isfile() or not data_file(member, archive.extractfile(member).read(16)):
raise ValueError('Executable or unclassified content in a Play data segment')
found = True
if process.wait() or not found:
raise ValueError('Invalid Play data segment')
finally:
process.stdout.close()
if process.poll() is None:
process.terminate()
process.wait()
def build_manifest(manifest_path, cache, work, output):
from tools.playstore.payloads import catalog_bytes, fetch
manifest = json.loads(Path(manifest_path).read_text())
work = Path(work)
work.mkdir(parents=True, exist_ok=True)
changes = {}
selected = {'desktop-ubuntu', 'desktop-legacy-kde', 'steamvr', 'droiddeck-proton', 'runtime-ubuntu'}
for entry in manifest['entries']:
if entry['id'] not in selected:
continue
source = dict(entry)
if 'layout' in source:
raise ValueError('Component is already split')
original = fetch(source, Path(cache))
code, data, combined = [work / (entry['id'] + '.' + part) for part in ['code.zst', 'data.zst', 'tar.zst']]
result_path = work / (entry['id'] + '.json')
if result_path.exists():
result = json.loads(result_path.read_text())
for path, part in zip([code, data], result['segments']):
if identity(path) != {key: part[key] for key in ['size', 'sha256']}:
raise ValueError('Existing prepared segment changed')
else:
result = prepare(original, code, data)
combine([code, data], combined)
if inventory(combined, os.environ.get('DROIDDECK_ZSTD', 'zstd'))[0] != result['inventory_sha256']:
raise ValueError('Split component changed its installed files')
result_path.write_text(json.dumps(result, indent=2) + '\n')
canonical = identity(combined)
changes[entry['sha256']] = canonical
entry.update(canonical)
source['urls'] = [url for url in source['urls'] if url.startswith('https://')]
entry['layout'] = dict(result, source=source)
entry.pop('prepare', None)
entry.pop('upstream', None)
print(entry['id'], json.dumps(canonical), flush=True)
def update(value):
if isinstance(value, dict):
digest = value.get('sha256') or str(value.get('digest', '')).removeprefix('sha256:')
if digest in changes and 'size' in value:
value['size'] = changes[digest]['size']
for key in value:
value[key] = update(value[key])
elif isinstance(value, list):
value = [update(item) for item in value]
elif isinstance(value, str):
for digest, replacement in changes.items():
if value == digest:
return replacement['sha256']
if value == 'sha256:' + digest:
return 'sha256:' + replacement['sha256']
return value
for entry in manifest['entries']:
if 'content' not in entry:
continue
entry['content'] = update(entry['content'])
content = catalog_bytes(entry['content'])
entry['sha256'] = hashlib.sha256(content).hexdigest()
entry['size'] = len(content)
Path(output).write_text(json.dumps(manifest, indent=2, ensure_ascii=False) + '\n')
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--manifest', type=Path, required=True)
parser.add_argument('--cache', type=Path, required=True)
parser.add_argument('--work', type=Path, required=True)
parser.add_argument('--output', type=Path, required=True)
args = parser.parse_args()
build_manifest(args.manifest, args.cache, args.work, args.output)
+82
View File
@@ -1,6 +1,7 @@
import hashlib
import importlib.util
import json
import re
from pathlib import Path
import tempfile
import unittest
@@ -18,6 +19,77 @@ READER_SPEC.loader.exec_module(delivery)
class PlaystorePayloadsTest(unittest.TestCase):
def test_split_data_is_play_hosted_and_guest_reassembles_the_exact_archive(self):
import io
import subprocess
import tarfile
from tools.playstore.split_archive import prepare, combine, identity
content = io.BytesIO()
with tarfile.open(fileobj=content, mode='w') as archive:
for name, body in [('program', b'\x7fELFprogram'), ('font.ttf', b'\x00\x01\x00\x00font')]:
member = tarfile.TarInfo(name)
member.size = len(body)
archive.addfile(member, io.BytesIO(body))
original = self.root / 'original'
original.write_bytes(subprocess.check_output(['zstd', '-c'], input=content.getvalue()))
code, data, combined = [self.root / name for name in ['code', 'data', 'combined']]
version = re.search(r'v([0-9.]+),', subprocess.check_output(['zstd', '--version'], text=True)).group(1)
layout = prepare(original, code, data, version)
layout['zstd_version'] = '1.5.5'
combine([code, data], combined)
entry = self.manifest['entries'][0]
source = dict(entry, **identity(original))
(self.cache / source['sha256']).write_bytes(original.read_bytes())
entry.update(identity(combined))
entry['layout'] = dict(layout, source=source)
(self.cache / entry['sha256']).write_bytes(combined.read_bytes())
staged = self.root / 'staged'
index = payloads.stage(self.validate(), self.cache, staged, chunk_bytes=64, module_bytes=256)
packs = json.loads((staged / 'assetpacks.json').read_text())
self.assertEqual(['playdata01'], packs)
for module in json.loads((staged / 'modules.json').read_text()):
self.assertIn('<dist:on-demand />', (staged / module / 'src/main/AndroidManifest.xml').read_text())
bundled = self.root / 'installed'
(bundled / '0').mkdir(parents=True)
for module in ['base'] + json.loads((staged / 'modules.json').read_text()):
with zipfile.ZipFile(bundled / '0' / (module + '.apk'), 'w') as archive:
root = staged / module / 'src/main'
for file in root.rglob('*'):
if file.is_file():
archive.write(file, str(file.relative_to(root)))
import socket
import struct
import threading
endpoint = str(self.root / 'resource-socket')
listener = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.addCleanup(listener.close)
listener.bind(endpoint)
listener.listen()
listener.settimeout(5)
count = sum(chunk['module'] == packs[0] for chunk in self.chunks(index['entries'][entry['urls'][0]]))
errors = []
def serve():
try:
for _ in range(count):
client, _ = listener.accept()
with client, client.makefile('rb') as source:
length = struct.unpack('>I', source.read(4))[0]
path = source.read(length).decode('utf-8')
client.sendall(b'\x01' + (staged / packs[0] / 'src/main/assets' / path).read_bytes())
except Exception as error:
errors.append(error)
server = threading.Thread(target=serve, daemon=True)
server.start()
with patch.object(delivery, 'SOCKET', endpoint), delivery.BundleReader(bundled) as reader:
restored = io.BytesIO()
reader.copy(entry['urls'][0], restored, entry['size'])
server.join(timeout=5)
self.assertFalse(server.is_alive())
self.assertFalse(errors)
self.assertEqual(combined.read_bytes(), restored.getvalue())
chunks = self.chunks(index['entries'][entry['urls'][0]])
self.assertTrue(any(chunk['module'] == packs[0] for chunk in chunks))
def setUp(self):
directory = tempfile.TemporaryDirectory()
self.addCleanup(directory.cleanup)
@@ -318,6 +390,16 @@ class PlaystorePayloadsTest(unittest.TestCase):
with self.assertRaisesRegex(ValueError, 'digest mismatch'):
payloads.verify_bundle(self.validate(), self.bundle(corrupt))
def test_native_payload_cannot_be_relabelled_as_a_data_asset_pack(self):
def relabel(staged, index):
entry = next(iter(index['entries'].values()))
recipe = staged / 'base/src/main/assets' / entry['recipe']
definition = json.loads(recipe.read_text())
definition['chunks'][0]['module'] = 'playdata01'
recipe.write_text(json.dumps(definition))
with self.assertRaisesRegex(ValueError, 'delivery are mixed'):
payloads.verify_bundle(self.validate(), self.bundle(relabel))
def test_final_bundle_cannot_silently_include_stale_unreferenced_components(self):
def add_stale(staged, index):
path = staged / 'playpayload01/src/main/assets/play-components/stale'
@@ -0,0 +1,34 @@
import hashlib
from pathlib import Path
import tempfile
import unittest
from tools.playstore.release_assets import prepare
class PlayReleaseAssetsTest(unittest.TestCase):
def test_large_signed_bundle_is_reassembled_without_changing_a_byte(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
bundle = root / 'DroidDeck.aab'
content = bytes(range(256)) * 4
bundle.write_bytes(content)
checksum = root / 'SHA256SUMS'
checksum.write_text(hashlib.sha256(content).hexdigest() + ' ' + bundle.name + '\n')
output = root / 'release'
parts = prepare(bundle, checksum, output, limit=300)
self.assertEqual(content, b''.join((output / name).read_bytes() for name in parts))
self.assertTrue(all((output / name).stat().st_size <= 300 for name in parts))
self.assertEqual(checksum.read_text(), (output / 'SHA256SUMS').read_text())
self.assertEqual(content, bundle.read_bytes())
self.assertEqual(4, len((output / 'PART-SHA256SUMS').read_text().splitlines()))
def test_changed_signed_bundle_cannot_be_published(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
bundle = root / 'bundle.aab'
bundle.write_bytes(b'changed')
checksum = root / 'SHA256SUMS'
checksum.write_text('0' * 64 + ' bundle.aab\n')
with self.assertRaisesRegex(ValueError, 'checksum verification'):
prepare(bundle, checksum, root / 'release', limit=4)
@@ -0,0 +1,63 @@
import io
import re
from pathlib import Path
import subprocess
import tarfile
import tempfile
import unittest
from tools.playstore.split_archive import combine, data_file, inventory, prepare, validate_data
class PlaySplitArchiveTest(unittest.TestCase):
def setUp(self):
self.directory = tempfile.TemporaryDirectory()
self.addCleanup(self.directory.cleanup)
self.root = Path(self.directory.name)
self.zstd_version = re.search(r'v([0-9.]+),', subprocess.check_output(['zstd', '--version'], text=True)).group(1)
def archive(self, entries, name='source'):
content = io.BytesIO()
with tarfile.open(fileobj=content, mode='w', format=tarfile.GNU_FORMAT) as archive:
for path, body, mode in entries:
member = tarfile.TarInfo(path)
member.size, member.mode = len(body), mode
member.uid, member.gid, member.mtime = 1000, 1001, 1234567
archive.addfile(member, io.BytesIO(body))
target = self.root / name
target.write_bytes(subprocess.check_output(['zstd', '-19', '-T4', '-c'], input=content.getvalue()))
return target
def test_split_preserves_all_file_content_and_metadata_across_tar_encodings(self):
font = 'usr/share/fonts/' + 'long-directory/' * 8 + 'example.ttf'
source = self.archive([('usr/bin/program', b'\x7fELF' + b'code' * 100, 0o755),
(font, b'\x00\x01\x00\x00' + b'font' * 100, 0o755),
('usr/share/config.json', b'{"enabled":true}', 0o644)])
code, data, combined = [self.root / name for name in ['code', 'data', 'combined']]
result = prepare(source, code, data, self.zstd_version)
combine([code, data], combined)
self.assertEqual(result['inventory_sha256'], inventory(combined, 'zstd')[0])
self.assertEqual(inventory(source, 'zstd')[0], inventory(combined, 'zstd')[0])
validate_data(data)
raw = subprocess.check_output(['zstd', '-dc', str(combined)])
with tarfile.open(fileobj=io.BytesIO(raw)) as archive:
self.assertEqual(archive.getnames(), ['usr/bin/program', 'usr/share/config.json', font])
self.assertEqual(archive.getmember(font).mode, 0o755)
def test_data_validation_rejects_executables_and_scripts_with_resource_names(self):
for content in [b'\x7fELF' + b'library', b'MZ' + b'program', b'#!/bin/sh\necho bad']:
member = tarfile.TarInfo('image.png')
self.assertFalse(data_file(member, content))
source = self.archive([('image.png', content, 0o644)], name=str(len(content)))
with self.assertRaisesRegex(ValueError, 'unclassified'):
validate_data(source)
def test_missing_assets_do_not_silently_produce_an_empty_pack(self):
source = self.archive([('program', b'\x7fELFcode', 0o755)])
with self.assertRaisesRegex(ValueError, 'no classified'):
prepare(source, self.root / 'code', self.root / 'data', self.zstd_version)
def test_archive_paths_cannot_escape_the_runtime(self):
source = self.archive([('../font.ttf', b'\x00\x01\x00\x00font', 0o644)])
with self.assertRaisesRegex(ValueError, 'unsafe'):
inventory(source, 'zstd')