From 5d10c8e96db88664881d09f30faa4301a49aba02 Mon Sep 17 00:00:00 2001 From: maxjivi05 <6025299+maxjivi05@users.noreply.github.com> Date: Tue, 3 Nov 2026 13:27:50 -0500 Subject: [PATCH] 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. --- .github/workflows/build.yml | 1 + .github/workflows/playstore.yml | 11 +- AGENTS.md | 5 + PRIVACY.md | 4 +- app/build.gradle | 8 +- .../main/java/com/droiddeck/launcher/App.kt | 4 +- .../droiddeck/launcher/FrontEndActivity.kt | 69 ++++- .../com/droiddeck/launcher/SessionActivity.kt | 7 + .../launcher/core/ComponentDownloads.java | 4 +- .../droiddeck/launcher/core/PlayDelivery.kt | 253 ++++++++++++++++++ .../launcher/runtime/LinuxRuntime.java | 7 +- .../com/droiddeck/launcher/ui/MainScreen.kt | 16 +- .../launcher/core/PlayArchiveFramesTest.kt | 47 ++++ settings.gradle | 7 + .../local/lib/droiddeck/component_delivery.py | 28 +- tools/playstore/DELIVERY.md | 57 ++++ tools/playstore/POLICY.md | 37 +++ tools/playstore/README.md | 4 +- tools/playstore/components.lock.json | 252 ++++++++++++++--- tools/playstore/payloads.py | 135 ++++++++-- tools/playstore/release_assets.py | 54 ++++ tools/playstore/split_archive.py | 223 +++++++++++++++ tools/tests/test_playstore_payloads.py | 82 ++++++ tools/tests/test_playstore_release_assets.py | 34 +++ tools/tests/test_playstore_split_archive.py | 63 +++++ 25 files changed, 1329 insertions(+), 83 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/core/PlayDelivery.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/core/PlayArchiveFramesTest.kt create mode 100644 tools/playstore/DELIVERY.md create mode 100644 tools/playstore/POLICY.md create mode 100644 tools/playstore/release_assets.py create mode 100644 tools/playstore/split_archive.py create mode 100644 tools/tests/test_playstore_release_assets.py create mode 100644 tools/tests/test_playstore_split_archive.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07813cfb36..65ca195758 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -708,6 +708,7 @@ jobs: ./gradlew :app:bundleRelease :app:lintRelease :app:testReleaseUnitTest -PplayDistribution=true \ -PndkVersion="$NDK_VERSION" -PplayVersionCode="$PLAY_VERSION_CODE" --tests com.droiddeck.launcher.core.ComponentPayloadStoreTest \ --tests com.droiddeck.launcher.core.PlayDistributionTest \ + --tests com.droiddeck.launcher.core.PlayArchiveFramesTest \ --tests com.droiddeck.launcher.PlayUpdatesTest \ --tests com.droiddeck.launcher.ui.BuildWatermarkTest --console=plain python3 tools/playstore/payloads.py verify-bundle --play-only --manifest tools/playstore/components.lock.json \ diff --git a/.github/workflows/playstore.yml b/.github/workflows/playstore.yml index bc49baa95d..35e363d453 100644 --- a/.github/workflows/playstore.yml +++ b/.github/workflows/playstore.yml @@ -59,6 +59,8 @@ jobs: - name: Test Play distribution safeguards run: | python3 -m unittest \ + tools.tests.test_playstore_release_assets \ + tools.tests.test_playstore_split_archive \ tools.tests.test_playstore_payloads \ tools.tests.test_playstore_manifest \ tools.tests.test_playstore_signing \ @@ -185,6 +187,13 @@ jobs: exit 1 fi printf 'Signed Android App Bundle for Google Play upload.\n\nSource: `%s` on `playstore`.\nVersion code: `%s`.\n' "$SOURCE_SHA" "$VERSION_CODE" > "$RUNNER_TEMP/play-release.md" - gh release create "$tag" -R "$GITHUB_REPOSITORY" signed/*.aab signed/SHA256SUMS \ + bundles=(signed/*.aab) + [ "${#bundles[@]}" -eq 1 ] && [ -f "${bundles[0]}" ] + python3 tools/playstore/release_assets.py --bundle "${bundles[0]}" --checksums signed/SHA256SUMS --output publish + if compgen -G 'publish/*.part*' >/dev/null; then + name=$(basename "${bundles[0]}") + printf '\nGitHub release assets are split to stay below its per-file limit. Download every part and PART-SHA256SUMS, verify the parts, combine them in numeric order, and verify SHA256SUMS before uploading the resulting AAB to Google Play.\n\nThe complete signed AAB is also available in the droiddeck-play-bundle-signed artifact for this workflow run.\n\n```sh\nsha256sum -c PART-SHA256SUMS\nset -o noclobber\ncat "%s".part??? > "%s"\nsha256sum -c SHA256SUMS\n```\n' "$name" "$name" >> "$RUNNER_TEMP/play-release.md" + fi + gh release create "$tag" -R "$GITHUB_REPOSITORY" publish/* \ --target "$SOURCE_SHA" --title "DroidDeck $VERSION ยท PlayStore" \ --notes-file "$RUNNER_TEMP/play-release.md" --latest=false diff --git a/AGENTS.md b/AGENTS.md index c22c5647c0..d60c740d38 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,3 +1,8 @@ # Rules - Comments should be rare, factual, and explain only non-obvious external constraints or business invariants. + + +## Google Play distribution + +For `playstore` and all changes destined for Google Play, read and enforce [the mandatory distribution policy gate](tools/playstore/POLICY.md) before editing or integrating changes. Refuse known policy violations and hold uncertain changes for authoritative evidence. Review incoming main commits individually; never overwrite Play delivery, permission, updater, signing, versioning, catalog, or release protections. A successful build is not policy clearance. diff --git a/PRIVACY.md b/PRIVACY.md index 9950eaa23a..ba2e5219d7 100644 --- a/PRIVACY.md +++ b/PRIVACY.md @@ -1,6 +1,6 @@ # DroidDeck Privacy Policy -Effective date: 2 November 2026 +Effective date: 3 November 2026 DroidDeck is an open-source game launcher maintained by the Droid-Deck project. A separate DroidDeck online account is not required. DroidDeck does not include advertising analytics or automatically submit usage reports or crash reports to the project maintainers. The maintainers do not operate a central database of users' game libraries or sign-in credentials, and do not sell users' personal data. @@ -27,6 +27,8 @@ You can manage permissions through Android settings. Turning off a permission or DroidDeck connects to the stores, game services, cloud-streaming providers, artwork sources, and download services used by your selected features. Those services can receive information such as your IP address, requests, game identifiers, authentication information, or information you enter directly into their sign-in and purchase pages. Steam, games, and other software running through DroidDeck have their own network activity and privacy policies. Their providers determine how they handle that information. +The Google Play version downloads runtime modules and non-executable resource packs through Google Play. Google's Play Feature Delivery and Play Asset Delivery services process device metadata and the application version to deliver the correct files and preserve them across updates. Google documents encrypted processing and a fixed retention period. See [Play Feature Delivery data handling](https://developer.android.com/guide/playcore/feature-delivery#data-safety) and [Play Asset Delivery data handling](https://developer.android.com/guide/playcore/asset-delivery#terms-of-service). + The Google Play version contacts Google Play to check whether an app update is available. Selecting Update opens the app's Google Play listing. Google handles Play delivery and updates under its own [privacy policy](https://policies.google.com/privacy). Optional Windows prerequisites can be downloaded from the sources identified in the app's pinned component inventory, including GitHub-hosted runtime packages. These providers receive the download request and IP address. DroidDeck verifies the package against the inventory before installing it into the guest runtime. diff --git a/app/build.gradle b/app/build.gradle index 7898b0daa8..ed2f8a53af 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -134,8 +134,8 @@ android { applicationId "com.droiddeck.launcher" minSdkVersion 26 targetSdkVersion 37 - versionCode 18 - versionName "0.6.9.1" + versionCode 19 + versionName "0.6.9.2" buildConfigField "String", "BUILD_LABEL", "\"${escapedBuildLabel}\"" buildConfigField "String", "SOURCE_COMMIT", "\"${sourceCommit}\"" buildConfigField "int", "PR_NUMBER", "${prNumber}" @@ -324,6 +324,8 @@ if (playDistribution) { def payloads = rootProject.file('build/playstore-payloads') def modules = new groovy.json.JsonSlurper().parse(new File(payloads, 'modules.json')) android.dynamicFeatures = modules.collect { ":${it}".toString() }.toSet() + def packs = new groovy.json.JsonSlurper().parse(new File(payloads, 'assetpacks.json')) + android.assetPacks = packs.collect { ":${it}".toString() }.toSet() android.sourceSets.main.assets.srcDir(new File(payloads, 'base/src/main/assets')) android.sourceSets.debug.manifest.srcFile('src/play/AndroidManifest.xml') android.sourceSets.release.manifest.srcFile('src/play/AndroidManifest.xml') @@ -400,6 +402,8 @@ tasks.named('preBuild').configure { dependsOn(buildRustStores) } dependencies { implementation 'com.google.android.play:app-update:2.1.0' + implementation 'com.google.android.play:feature-delivery:2.1.0' + implementation 'com.google.android.play:asset-delivery:2.3.0' implementation "org.opencv:opencv:${trackingPack.OPENCV_VERSION}" implementation 'org.khronos.openxr:openxr_loader_for_android:1.1.49' implementation 'com.github.luben:zstd-jni:1.5.7-4@aar' diff --git a/app/src/main/java/com/droiddeck/launcher/App.kt b/app/src/main/java/com/droiddeck/launcher/App.kt index 59cd56f2c8..cb29dbdf52 100644 --- a/app/src/main/java/com/droiddeck/launcher/App.kt +++ b/app/src/main/java/com/droiddeck/launcher/App.kt @@ -6,8 +6,10 @@ import com.droiddeck.launcher.session.CrashHandler import com.droiddeck.launcher.session.GpuClockPin class App : Application() { - override fun attachBaseContext(base: android.content.Context) = + override fun attachBaseContext(base: android.content.Context) { super.attachBaseContext(com.droiddeck.launcher.core.AppLanguage.wrap(base)) + if (BuildConfig.PLAY_DISTRIBUTION) com.google.android.play.core.splitcompat.SplitCompat.install(this) + } override fun onConfigurationChanged(newConfig: android.content.res.Configuration) { super.onConfigurationChanged(newConfig) diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 543c435947..cd86d81146 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -22,6 +22,7 @@ import android.view.WindowManager import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf @@ -578,6 +579,11 @@ class FrontEndActivity : ComponentActivity() { } override fun startActivity(intent: Intent?) { + if (BuildConfig.PLAY_DISTRIBUTION && !com.droiddeck.launcher.core.PlayDelivery.state.value.ready && + intent?.component?.className == SessionActivity::class.java.name) { + com.droiddeck.launcher.core.PlayDelivery.defer(intent) + return + } val compat = protons.protonBusyId != null || ProtonExtras.installInProgress if (intent?.component?.className == SessionActivity::class.java.name) { if (compatLaunch != null) return @@ -1009,6 +1015,11 @@ class FrontEndActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + if (BuildConfig.PLAY_DISTRIBUTION) { + @Suppress("DEPRECATION") + val pending = savedInstanceState?.getParcelable("play_pending_session") + if (pending?.component?.className == SessionActivity::class.java.name) com.droiddeck.launcher.core.PlayDelivery.defer(pending) + } if (savedInstanceState == null) readIntegrationIntent(intent) readGameIntent(intent) gameSyncFolder = GameFileSync.folder(this) @@ -1043,6 +1054,27 @@ class FrontEndActivity : ComponentActivity() { updates.start() setContent { DroidDeckTheme(theme, appScale = appScale) { + val delivery by com.droiddeck.launcher.core.PlayDelivery.state.collectAsState() + androidx.compose.runtime.LaunchedEffect(delivery.ready) { + if (delivery.ready) { + com.droiddeck.launcher.core.PlayDelivery.takePendingSession()?.let { startActivity(it) } + if (BuildConfig.PLAY_DISTRIBUTION) { + refresh() + refreshDeliveredComponents(force = true) + } + } + } + if (BuildConfig.PLAY_DISTRIBUTION && !delivery.ready) ConfirmDialog( + title = getString(R.string.app_name), + text = if (delivery.busy && delivery.percent >= 0) + getString(R.string.setup_runtime_progress, getString(R.string.rtinst_downloading), delivery.percent) + else getString(if (delivery.failed) R.string.user_apps_download_failed else R.string.rtinst_downloading), + confirm = getString(if (delivery.busy) R.string.common_working else R.string.stores_dl_retry), + onConfirm = { com.droiddeck.launcher.core.PlayDelivery.start(this) }, + onDismiss = { com.droiddeck.launcher.core.PlayDelivery.cancel(); finish() }, + progress = if (delivery.busy) delivery.percent else null, + confirmEnabled = !delivery.busy, closeOnConfirm = false, + ) com.droiddeck.launcher.ui.FocusGlideHost(androidx.compose.ui.Modifier.fillMaxSize().exposeTestTags()) { if (decky.deckyPendingZip != null) com.droiddeck.launcher.ui.DeckyZipWarningDialog( onConfirm = { decky.confirmPluginZip() }, onCancel = { decky.cancelPluginZip() }, @@ -1755,6 +1787,7 @@ class FrontEndActivity : ComponentActivity() { override fun onResume() { super.onResume() + com.droiddeck.launcher.core.PlayDelivery.start(this) compatLaunchVisible = true com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false) com.droiddeck.launcher.ui.DualScreenPanel.ownerPaused(taskId, false) @@ -1774,10 +1807,24 @@ class FrontEndActivity : ComponentActivity() { refreshPhantomStatus() syncLossless() updates.onResume() + catalogFresh = false + oscMode = SessionPrefs.oscMode(this) + refreshController() + refreshHomeAppState() + refreshSecondScreenDisplays() + refresh() + decky.deckyInstalled = DeckyManager.installed(this) + DeckyManager.syncCefMarker(this) + decky.deckySupervisor = DeckyManager.supervisorEnabled(this) + refreshAddedGames() + refreshDeliveredComponents() + } + + private fun refreshDeliveredComponents(force: Boolean = false) { + if (BuildConfig.PLAY_DISTRIBUTION && !com.droiddeck.launcher.core.PlayDelivery.state.value.ready) return drivers.checkOnOpen() resumeInterruptedPackages() - protons.checkUpdates() - catalogFresh = false + protons.checkUpdates(force) if (!SessionState.running && !componentsQueueBusy && !LinuxRuntimeInstaller.isBusy()) { componentsQueueBusy = true Thread({ @@ -1792,15 +1839,6 @@ class FrontEndActivity : ComponentActivity() { } }, "components-queue").start() } else if (showComponents) components.refreshComponents() - oscMode = SessionPrefs.oscMode(this) - refreshController() - refreshHomeAppState() - refreshSecondScreenDisplays() - refresh() - decky.deckyInstalled = DeckyManager.installed(this) - DeckyManager.syncCefMarker(this) - decky.deckySupervisor = DeckyManager.supervisorEnabled(this) - refreshAddedGames() if (catalog == null) loadDesktopCatalog() if (!busy) Thread({ checkCatalog() }, "catalog").start() } @@ -1824,6 +1862,10 @@ class FrontEndActivity : ComponentActivity() { @Suppress("OVERRIDE_DEPRECATION") override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + if (requestCode == 7619 && BuildConfig.PLAY_DISTRIBUTION) { + if (resultCode != RESULT_OK) com.droiddeck.launcher.core.PlayDelivery.cancel() + return + } if (HomeWidgets.onActivityResult(this, requestCode, resultCode)) return @Suppress("DEPRECATION") super.onActivityResult(requestCode, resultCode, data) @@ -1831,6 +1873,9 @@ class FrontEndActivity : ComponentActivity() { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) + if (BuildConfig.PLAY_DISTRIBUTION) com.droiddeck.launcher.core.PlayDelivery.peekPendingSession()?.let { + outState.putParcelable("play_pending_session", it) + } if (slowUsbNever) SessionPrefs.setSlowUsbWarningOff(this) saveCompatLaunch(outState) pendingSwitch?.let { outState.putParcelable(KEY_PENDING_SWITCH, it) } @@ -1845,6 +1890,7 @@ class FrontEndActivity : ComponentActivity() { else @Suppress("DEPRECATION") state.getParcelable(key) override fun onDestroy() { + com.droiddeck.launcher.core.PlayDelivery.detach(this) cancelCompatLaunch() updates.unregister() super.onDestroy() @@ -1940,6 +1986,7 @@ class FrontEndActivity : ComponentActivity() { } private fun loadDesktopCatalog() { + if (BuildConfig.PLAY_DISTRIBUTION && !com.droiddeck.launcher.core.PlayDelivery.state.value.ready) return if (catalogLoading || catalog != null) return catalogLoading = true Thread({ diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 2cc5629227..fbafdb319e 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -566,6 +566,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + if (BuildConfig.PLAY_DISTRIBUTION && !com.droiddeck.launcher.core.PlayDelivery.state.value.ready) { + runtimeRemovalBlocked = true + com.droiddeck.launcher.core.PlayDelivery.defer(intent) + startActivity(Intent(this, FrontEndActivity::class.java)) + finish() + return + } if (com.droiddeck.launcher.runtime.LinuxRuntimeInstaller.isRemoving() || com.droiddeck.launcher.runtime.LinuxRuntimeInstaller.isMaintaining()) { runtimeRemovalBlocked = true diff --git a/app/src/main/java/com/droiddeck/launcher/core/ComponentDownloads.java b/app/src/main/java/com/droiddeck/launcher/core/ComponentDownloads.java index c55df2a787..d8c3f88388 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/ComponentDownloads.java +++ b/app/src/main/java/com/droiddeck/launcher/core/ComponentDownloads.java @@ -16,10 +16,10 @@ public final class ComponentDownloads { public static void init(Context context) { if (BuildConfig.PLAY_DISTRIBUTION) { - Context application = context.getApplicationContext(); + PlayDelivery.INSTANCE.init(context); store = new ComponentPayloadStore(path -> { try { - return application.getAssets().open(path); + return PlayDelivery.INSTANCE.open(path); } catch (IOException error) { throw new java.io.UncheckedIOException(error); } diff --git a/app/src/main/java/com/droiddeck/launcher/core/PlayDelivery.kt b/app/src/main/java/com/droiddeck/launcher/core/PlayDelivery.kt new file mode 100644 index 0000000000..009724e098 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/core/PlayDelivery.kt @@ -0,0 +1,253 @@ +package com.droiddeck.launcher.core + +import android.app.Activity +import android.content.Context +import android.os.Handler +import android.os.Looper +import com.droiddeck.launcher.BuildConfig +import com.google.android.gms.tasks.Tasks +import com.google.android.gms.tasks.Task +import java.util.concurrent.TimeUnit +import com.google.android.play.core.assetpacks.AssetPackManagerFactory +import com.google.android.play.core.assetpacks.model.AssetPackStatus +import com.google.android.play.core.splitcompat.SplitCompat +import com.google.android.play.core.splitinstall.SplitInstallManagerFactory +import com.google.android.play.core.splitinstall.SplitInstallRequest +import com.google.android.play.core.splitinstall.model.SplitInstallSessionStatus +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import org.json.JSONObject +import java.io.File +import java.io.FilterInputStream +import java.io.IOException +import java.io.InputStream +import java.lang.ref.WeakReference +import java.util.concurrent.atomic.AtomicBoolean +import java.util.zip.ZipFile + +internal object PlayDelivery { + data class State(val ready: Boolean = !BuildConfig.PLAY_DISTRIBUTION, val busy: Boolean = false, + val failed: Boolean = false, val percent: Int = -1) + + private val mutableState = MutableStateFlow(State()) + val state = mutableState.asStateFlow() + private lateinit var app: Context + private val handler = Handler(Looper.getMainLooper()) + private val running = AtomicBoolean(false) + private val cancelled = AtomicBoolean(false) + private var activity = WeakReference(null) + @Volatile private var session = 0 + @Volatile private var confirmation = false + @Volatile private var attempt = 0 + private var pendingSession: android.content.Intent? = null + private var server: android.net.LocalServerSocket? = null + private val clients = java.util.concurrent.Semaphore(2) + private val splits by lazy { SplitInstallManagerFactory.create(app) } + private val assets by lazy { AssetPackManagerFactory.getInstance(app) } + private val definition by lazy { + app.assets.open("play-components/delivery.json").bufferedReader().use { JSONObject(it.readText()) } + } + private fun names(key: String): List = definition.getJSONArray(key).let { list -> + (0 until list.length()).map { list.getString(it) } + } + + fun init(context: Context) { + if (!BuildConfig.PLAY_DISTRIBUTION) return + app = context.applicationContext + } + + @Synchronized + fun defer(intent: android.content.Intent) { pendingSession = android.content.Intent(intent) } + + @Synchronized + fun peekPendingSession(): android.content.Intent? = pendingSession?.let { android.content.Intent(it) } + + @Synchronized + fun takePendingSession(): android.content.Intent? = pendingSession.also { pendingSession = null } + + fun start(owner: Activity) { + if (!BuildConfig.PLAY_DISTRIBUTION) return + activity = WeakReference(owner) + if (mutableState.value.ready) return + if (!running.compareAndSet(false, true)) return + cancelled.set(false) + attempt++ + confirmation = false + mutableState.value = State(busy = true) + Thread({ + var completed = State(failed = true) + try { + installModules() + confirmation = false + installAssets() + checkCancelled() + startServer() + completed = State(ready = true, percent = 100) + } catch (error: Exception) { + android.util.Log.w("PlayDelivery", "Play component delivery failed", error) + } finally { + if (cancelled.get()) cancel() + running.set(false) + mutableState.value = completed + } + }, "play-components").start() + } + + fun detach(owner: Activity) { + if (activity.get() === owner) activity.clear() + } + + fun cancel() { + cancelled.set(true) + synchronized(this) { pendingSession = null } + if (session > 0) splits.cancelInstall(session) + if (::app.isInitialized) runCatching { assets.cancel(names("packs")) } + } + + private fun await(task: Task): T = Tasks.await(task, 30, TimeUnit.SECONDS) + + private fun checkCancelled() { + if (cancelled.get() || Thread.currentThread().isInterrupted) throw IOException("Play delivery cancelled") + } + + private fun installModules() { + val missing = names("modules").filterNot { it in splits.installedModules } + if (missing.isEmpty()) return + val previous = await(splits.sessionStates).firstOrNull { + it.moduleNames().containsAll(missing) && it.status() in setOf( + SplitInstallSessionStatus.PENDING, SplitInstallSessionStatus.DOWNLOADING, + SplitInstallSessionStatus.DOWNLOADED, SplitInstallSessionStatus.INSTALLING, + SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION) + } + session = previous?.sessionId() ?: run { + val request = attempt + val task = splits.startInstall(SplitInstallRequest.newBuilder().apply { missing.forEach(::addModule) }.build()) + task.addOnSuccessListener { id -> if (request == attempt && cancelled.get()) splits.cancelInstall(id) } + await(task) + } + while (true) { + checkCancelled() + val current = await(splits.getSessionState(session)) + val request = attempt + when (current.status()) { + SplitInstallSessionStatus.INSTALLED -> { + if (!SplitCompat.install(app) || !splits.installedModules.containsAll(missing)) + throw IOException("Play modules could not be activated") + session = 0 + return + } + SplitInstallSessionStatus.FAILED, SplitInstallSessionStatus.CANCELED -> + throw IOException("Play module delivery failed: ${current.errorCode()}") + SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION -> handler.post { + val owner = activity.get() + if (request == attempt && session == current.sessionId() && running.get() && !cancelled.get() && + !confirmation && owner != null && !owner.isFinishing && !owner.isDestroyed) { + runCatching { splits.startConfirmationDialogForResult(current, owner, 7619) } + .onSuccess { confirmation = it }.onFailure { cancel() } + } + } + } + val total = current.totalBytesToDownload() + mutableState.value = State(busy = true, percent = if (total > 0) + (current.bytesDownloaded() * 80 / total).toInt().coerceIn(0, 80) else -1) + Thread.sleep(350) + } + } + + private fun installAssets() { + val packs = names("packs") + val missing = packs.filter { assets.getPackLocation(it) == null } + if (missing.isEmpty()) return + val requestAttempt = attempt + val fetch = assets.fetch(missing) + fetch.addOnSuccessListener { if (requestAttempt == attempt && cancelled.get()) assets.cancel(missing) } + await(fetch) + while (true) { + checkCancelled() + val states = await(assets.getPackStates(missing)).packStates().values + if (states.any { it.status() == AssetPackStatus.FAILED || it.status() == AssetPackStatus.CANCELED }) + throw IOException("Play data delivery failed") + if (missing.all { assets.getPackLocation(it) != null }) return + val request = attempt + if (states.any { it.status() == AssetPackStatus.WAITING_FOR_WIFI || it.status() == AssetPackStatus.REQUIRES_USER_CONFIRMATION }) + handler.post { + val owner = activity.get() + if (request == attempt && running.get() && !cancelled.get() && + !confirmation && owner != null && !owner.isFinishing && !owner.isDestroyed) { + confirmation = true + assets.showConfirmationDialog(owner).addOnSuccessListener { result -> + if (request == attempt && result != Activity.RESULT_OK) cancel() + }.addOnFailureListener { if (request == attempt) cancel() } + } + } + val total = states.sumOf { it.totalBytesToDownload() } + val downloaded = states.sumOf { it.bytesDownloaded() } + mutableState.value = State(busy = true, percent = if (total > 0) + (80 + downloaded * 19 / total).toInt().coerceIn(80, 99) else -1) + Thread.sleep(500) + } + } + + @Synchronized + private fun startServer() { + if (server != null) return + val listener = android.net.LocalServerSocket(app.packageName + ".play-components") + server = listener + Thread({ + while (true) { + val client = try { listener.accept() } catch (_: IOException) { break } + if (!clients.tryAcquire()) { client.close(); continue } + Thread({ + try { + client.use { + client.soTimeout = 30_000 + if (client.peerCredentials.uid != android.os.Process.myUid()) return@use + val input = java.io.DataInputStream(client.inputStream) + val length = input.readInt() + if (length !in 1..256) return@use + val path = ByteArray(length).also(input::readFully).toString(Charsets.UTF_8) + if (!Regex("play-components/[0-9a-f]{64}/[0-9]{4,}").matches(path)) return@use + val output = client.outputStream + open(path).use { source -> + output.write(1) + source.copyTo(output, 65536) + } + } + } catch (error: IOException) { + android.util.Log.w("PlayDelivery", "Component stream closed", error) + } finally { + clients.release() + } + }, "play-component-reader").apply { isDaemon = true; start() } + } + }, "play-component-server").apply { isDaemon = true; start() } + } + + @Throws(IOException::class) + fun open(path: String): InputStream { + try { + return app.assets.open(path) + } catch (_: java.io.FileNotFoundException) { + val info = app.packageManager.getApplicationInfo(app.packageName, 0) + for (split in info.splitSourceDirs.orEmpty()) { + val archive = ZipFile(split) + val entry = archive.getEntry("assets/$path") + if (entry == null) { + archive.close() + continue + } + return object : FilterInputStream(archive.getInputStream(entry)) { + override fun close() { try { super.close() } finally { archive.close() } } + } + } + for (name in names("packs")) { + val directory = assets.getPackLocation(name)?.assetsPath()?.let(::File) ?: continue + val file = File(directory, path) + if (file.canonicalPath.startsWith(directory.canonicalPath + File.separator) && file.isFile) + return file.inputStream() + } + if (!running.get()) mutableState.value = State(failed = true) + throw IOException("Play component is not installed: $path") + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java index b3e0f689cf..47c9634fbb 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java @@ -292,7 +292,12 @@ public final class LinuxRuntime { if (!BuildConfig.PLAY_DISTRIBUTION) return; java.util.LinkedHashSet directories = new java.util.LinkedHashSet<>(); directories.add(new File(context.getApplicationInfo().sourceDir).getParentFile()); - String[] splits = context.getApplicationInfo().splitSourceDirs; + String[] splits; + try { + splits = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0).splitSourceDirs; + } catch (android.content.pm.PackageManager.NameNotFoundException error) { + throw new IllegalStateException(error); + } if (splits != null) for (String split : splits) directories.add(new File(split).getParentFile()); int index = 0; for (File directory : directories) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/MainScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/MainScreen.kt index aa2b6da6c5..453cfdd684 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/MainScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/MainScreen.kt @@ -57,12 +57,22 @@ fun ChooseAppDisplayDialog( } @Composable -fun ConfirmDialog(title: String, text: String, confirm: String, onConfirm: () -> Unit, onDismiss: () -> Unit) { +fun ConfirmDialog(title: String, text: String, confirm: String, onConfirm: () -> Unit, onDismiss: () -> Unit, + progress: Int? = null, confirmEnabled: Boolean = true, closeOnConfirm: Boolean = true) { AlertDialog( onDismissRequest = onDismiss, title = { Text(title) }, - text = { Text(text) }, - confirmButton = { TextButton(onClick = { onDismiss(); onConfirm() }, modifier = Modifier.focusGlide(CircleShape)) { Text(confirm) } }, + text = { + Column(verticalArrangement = Arrangement.spacedBy(12.dp)) { + Text(text) + if (progress != null) { + if (progress >= 0) androidx.compose.material3.LinearProgressIndicator( + progress = { progress / 100f }, modifier = Modifier.fillMaxWidth().height(4.dp)) + else androidx.compose.material3.LinearProgressIndicator(modifier = Modifier.fillMaxWidth().height(4.dp)) + } + } + }, + confirmButton = { TextButton(enabled = confirmEnabled, onClick = { if (closeOnConfirm) onDismiss(); onConfirm() }, modifier = Modifier.focusGlide(CircleShape)) { Text(confirm) } }, dismissButton = { TextButton(onClick = onDismiss, modifier = Modifier.focusGlide(CircleShape)) { Text(stringResource(R.string.common_cancel)) } }, ) } diff --git a/app/src/test/java/com/droiddeck/launcher/core/PlayArchiveFramesTest.kt b/app/src/test/java/com/droiddeck/launcher/core/PlayArchiveFramesTest.kt new file mode 100644 index 0000000000..ea644b1ca9 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/core/PlayArchiveFramesTest.kt @@ -0,0 +1,47 @@ +package com.droiddeck.launcher.core + +import com.github.luben.zstd.Zstd +import com.github.luben.zstd.ZstdInputStream +import org.apache.commons.compress.archivers.tar.TarArchiveEntry +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream +import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream +import org.junit.Assert.assertArrayEquals +import org.junit.Assert.assertEquals +import org.junit.Test +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream + +class PlayArchiveFramesTest { + private fun tar(name: String, bytes: ByteArray): ByteArray { + val output = ByteArrayOutputStream() + TarArchiveOutputStream(output).use { archive -> + archive.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX) + val entry = TarArchiveEntry(name).apply { size = bytes.size.toLong(); mode = 493 } + archive.putArchiveEntry(entry) + archive.write(bytes) + archive.closeArchiveEntry() + } + return output.toByteArray() + } + + @Test fun runtimeDecoderReadsCodeAndDataFramesAsOneCompleteArchive() { + val code = byteArrayOf(127, 69, 76, 70) + val data = byteArrayOf(0, 1, 0, 0, 4, 5, 6) + val dataName = "usr/share/fonts/" + "directory/".repeat(12) + "font.ttf" + val joined = Zstd.compress(tar("usr/bin/program", code).copyOf(1024), 19) + + Zstd.compress(tar(dataName, data), 19) + val contents = linkedMapOf() + ZstdInputStream(ByteArrayInputStream(joined)).use { decoded -> + TarArchiveInputStream(decoded).use { archive -> + while (true) { + val entry = archive.nextEntry ?: break + assertEquals(493, entry.mode) + contents[entry.name] = archive.readBytes() + } + } + } + assertEquals(listOf("usr/bin/program", dataName), contents.keys.toList()) + assertArrayEquals(code, contents["usr/bin/program"]) + assertArrayEquals(data, contents[dataName]) + } +} diff --git a/settings.gradle b/settings.gradle index 47ec19064b..ef0463dd3d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -25,6 +25,13 @@ if (providers.gradleProperty('playDistribution').getOrElse('false').toBoolean()) if (!(modules instanceof List) || modules.isEmpty() || modules.size() > 10 || modules.unique(false).size() != modules.size()) { throw new GradleException('Invalid Play feature module registry') } + def packs = new groovy.json.JsonSlurper().parse(new File(payloads, 'assetpacks.json')) + if (!(packs instanceof List) || packs.size() > 100 || packs.unique(false).size() != packs.size()) throw new GradleException('Invalid Play asset pack registry') + packs.each { name -> + if (!(name instanceof String) || !(name ==~ /playdata[0-9]{2}/)) throw new GradleException('Invalid Play asset pack name') + include ":${name}" + project(":${name}").projectDir = new File(payloads, name) + } modules.each { name -> if (!(name instanceof String) || !(name ==~ /playpayload[0-9]{2}/)) throw new GradleException('Invalid Play feature module name') include ":${name}" diff --git a/tools/linuxfs/overlay/usr/local/lib/droiddeck/component_delivery.py b/tools/linuxfs/overlay/usr/local/lib/droiddeck/component_delivery.py index 96c25fa610..b0c8b74c15 100644 --- a/tools/linuxfs/overlay/usr/local/lib/droiddeck/component_delivery.py +++ b/tools/linuxfs/overlay/usr/local/lib/droiddeck/component_delivery.py @@ -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) diff --git a/tools/playstore/DELIVERY.md b/tools/playstore/DELIVERY.md new file mode 100644 index 0000000000..3cb176f0b2 --- /dev/null +++ b/tools/playstore/DELIVERY.md @@ -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. diff --git a/tools/playstore/POLICY.md b/tools/playstore/POLICY.md new file mode 100644 index 0000000000..c1146ed694 --- /dev/null +++ b/tools/playstore/POLICY.md @@ -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) diff --git a/tools/playstore/README.md b/tools/playstore/README.md index 557b77c4c7..253f921c22 100644 --- a/tools/playstore/README.md +++ b/tools/playstore/README.md @@ -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. diff --git a/tools/playstore/components.lock.json b/tools/playstore/components.lock.json index 92f66a3f7e..72f10ebafc 100644 --- a/tools/playstore/components.lock.json +++ b/tools/playstore/components.lock.json @@ -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" } diff --git a/tools/playstore/payloads.py b/tools/playstore/payloads.py index a146625a86..a046086028 100644 --- a/tools/playstore/payloads.py +++ b/tools/playstore/payloads.py @@ -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_ '\n' ' \n' - ' ' - '\n' + ' \n' ' \n' ' \n' ' \n' '\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 diff --git a/tools/playstore/release_assets.py b/tools/playstore/release_assets.py new file mode 100644 index 0000000000..7939457166 --- /dev/null +++ b/tools/playstore/release_assets.py @@ -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) diff --git a/tools/playstore/split_archive.py b/tools/playstore/split_archive.py new file mode 100644 index 0000000000..1aa55db5e4 --- /dev/null +++ b/tools/playstore/split_archive.py @@ -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) diff --git a/tools/tests/test_playstore_payloads.py b/tools/tests/test_playstore_payloads.py index 66de5ff2b5..e49c5b8635 100644 --- a/tools/tests/test_playstore_payloads.py +++ b/tools/tests/test_playstore_payloads.py @@ -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('', (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' diff --git a/tools/tests/test_playstore_release_assets.py b/tools/tests/test_playstore_release_assets.py new file mode 100644 index 0000000000..09c22bd148 --- /dev/null +++ b/tools/tests/test_playstore_release_assets.py @@ -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) diff --git a/tools/tests/test_playstore_split_archive.py b/tools/tests/test_playstore_split_archive.py new file mode 100644 index 0000000000..76cfe5b460 --- /dev/null +++ b/tools/tests/test_playstore_split_archive.py @@ -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')