A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
feat(avf): multi-ctor SharedPath matcher + Downloads-share capability probe
ExTvc2663388698e
diff --git a/app/src/main/java/com/excp/podroid/engine/avf/AvfDiagnostics.kt b/app/src/main/java/com/excp/podroid/engine/avf/AvfDiagnostics.ktindex 7519236..95701e1 100644--- a/app/src/main/java/com/excp/podroid/engine/avf/AvfDiagnostics.kt+++ b/app/src/main/java/com/excp/podroid/engine/avf/AvfDiagnostics.kt@@ -34,18 +34,30 @@ data class AvfReport(val activeBackend: String = "?",) {fun pretty(): String = buildString {- appendLine("Active backend: $activeBackend")+ appendLine("Active backend")+ appendLine(" $activeBackend")appendLine()- appendLine("Feature: android.software.virtualization_framework = $featureSupported")- appendLine("Perm: MANAGE_VIRTUAL_MACHINE granted = $managePermissionGranted")- appendLine("Perm: USE_CUSTOM_VIRTUAL_MACHINE granted = $customPermissionGranted")- appendLine("APEX: /apex/com.android.virt present = $virtApexPresent")- appendLine("API: VirtualMachineManager class loadable = $managerClassPresent")- appendLine("Service: reachable via system service = $serviceReachable")+ appendLine("Feature: virtualization_framework")+ appendLine(" supported = $featureSupported")+ appendLine()+ appendLine("Permission: MANAGE_VIRTUAL_MACHINE")+ appendLine(" granted = $managePermissionGranted")+ appendLine()+ appendLine("Permission: USE_CUSTOM_VIRTUAL_MACHINE")+ appendLine(" granted = $customPermissionGranted")+ appendLine()+ appendLine("APEX /apex/com.android.virt")+ appendLine(" present = $virtApexPresent")+ appendLine()+ appendLine("API VirtualMachineManager")+ appendLine(" class loadable = $managerClassPresent")+ appendLine()+ appendLine("Service")+ appendLine(" reachable via system service = $serviceReachable")if (smokeTestResult != null) {appendLine()- appendLine("Smoke test:")- appendLine(smokeTestResult)+ appendLine("Smoke test")+ appendLine(smokeTestResult.prependIndent(" "))}}}@@ -59,6 +71,32 @@ object AvfDiagnostics {private const val CLS_CONFIG = "android.system.virtualmachine.VirtualMachineConfig"private const val CLS_CUSTOM_CFG = "android.system.virtualmachine.VirtualMachineCustomImageConfig"+ /**+ * Probe whether this AVF revision can share external storage paths+ * (e.g. /storage/emulated/.../Download). The 10-param SharedPath ctor+ * that takes a `boolean appDomain` is the prerequisite — without it,+ * crosvm inherits our untrusted_app SELinux domain and the kernel+ * refuses to read external storage (VM dies at start with reason=4).+ *+ * On shipping Pixel mustang beta, only the 9-param ctor ships and this+ * returns false. Google's TerminalApp gets around it by being signed+ * with the platform key and installed under /apex/com.android.virt/+ * priv-app/ — a path no third-party APK can take.+ */+ fun externalStorageShareSupported(): Boolean {+ val spCls = runCatching {+ Class.forName("android.system.virtualmachine.VirtualMachineCustomImageConfig\$SharedPath")+ }.getOrNull() ?: return false+ val intT = Int::class.javaPrimitiveType!!+ val boolT = Boolean::class.javaPrimitiveType!!+ val strT = String::class.java+ return runCatching {+ spCls.getDeclaredConstructor(+ strT, intT, intT, intT, intT, intT, strT, strT, boolT, strT+ )+ }.isSuccess+ }+/*** Read-only probe — never blocks, never touches the system service for* real (just checks reachability). Safe to call from anywhere.diff --git a/app/src/main/java/com/excp/podroid/engine/avf/AvfReflect.kt b/app/src/main/java/com/excp/podroid/engine/avf/AvfReflect.ktindex 7854883..c0b1fc9 100644--- a/app/src/main/java/com/excp/podroid/engine/avf/AvfReflect.kt+++ b/app/src/main/java/com/excp/podroid/engine/avf/AvfReflect.kt@@ -147,15 +147,27 @@ object AvfReflect {/*** Add a host-filesystem path that the guest can mount via virtio-9p- * (`mount -t 9p downloads /mnt/downloads ...`). The `tag` parameter matches- * what the guest passes as the mount source.+ * (`mount -t 9p <tag> /mnt/... -o trans=virtio,...`).*- * SharedPath constructor signature (from dexdump on the Pixel framework jar):- * (String sharedPath, String socket, int hostUid, int hostGid,- * int guestUid, int guestGid, int mask, String tag, String socketPath)+ * `appDomain`: true ⇒ crosvm spins up inside the calling app's SELinux+ * domain (`untrusted_app`), which can only see paths under filesDir.+ * false ⇒ crosvm spins up as a child of virtmgr (system domain), which+ * is the only way to share external storage like `/storage/emulated/...`.*- * `socket` (the abstract-socket name) is empty because we use a- * filesystem socket via `socketPath`.+ * Returns true if the share was added successfully, false if this AVF+ * revision can't honour the request (e.g. needs `appDomain=false` but+ * this device only ships the older 9-param ctor without that param).+ * Callers should treat false as "share is silently unavailable" — the VM+ * still boots without it. NEVER throws on signature mismatch — the VM+ * starting cleanly is more valuable than the share.+ *+ * Known SharedPath constructor shapes:+ * v3 (AOSP main — has `boolean appDomain`):+ * (String, int, int, int, int, int, String, String, boolean, String)+ * v2 (Pixel 10 mustang beta — 9 params, no appDomain):+ * (String, int, int, int, int, int, String, String, String)+ * v1 (older AOSP — 2 Strings up front):+ * (String, String, int, int, int, int, int, String, String)*/fun addSharedPath(customBuilder: Any,@@ -166,24 +178,101 @@ object AvfReflect {guestUid: Int,guestGid: Int,mask: Int,+ socket: String,socketPath: String,- ) {+ appDomain: Boolean,+ ): Boolean {val spCls = Class.forName("$PKG.VirtualMachineCustomImageConfig\$SharedPath")- val spCtor = spCls.getDeclaredConstructor(- String::class.java, String::class.java,- Int::class.javaPrimitiveType!!, Int::class.javaPrimitiveType!!,- Int::class.javaPrimitiveType!!, Int::class.javaPrimitiveType!!,- Int::class.javaPrimitiveType!!,- String::class.java, String::class.java,- ).apply { isAccessible = true }- val sp = spCtor.newInstance(- sharedPath, /* socket = */ "",- hostUid, hostGid, guestUid, guestGid, mask,- tag, socketPath,+ val intT = Int::class.javaPrimitiveType!!+ val boolT = Boolean::class.javaPrimitiveType!!+ val strT = String::class.java++ val sp = runCatching {+ buildSharedPath(spCls, intT, boolT, strT,+ sharedPath, tag, socket, socketPath, appDomain,+ hostUid, hostGid, guestUid, guestGid, mask)+ }.getOrElse { e ->+ android.util.Log.w("AvfReflect",+ "addSharedPath: no compatible SharedPath ctor — share for '$sharedPath' " ++ "(tag=$tag) is unavailable on this AVF revision. " ++ "Reason: ${e.message}")+ return false+ } ?: return false++ return runCatching {+ val addM = customBuilder.javaClass.getDeclaredMethod("addSharedPath", spCls)+ .apply { isAccessible = true }+ addM.invoke(customBuilder, sp)+ }.fold(+ onSuccess = { true },+ onFailure = { e ->+ android.util.Log.w("AvfReflect",+ "addSharedPath: builder rejected SharedPath for '$sharedPath': ${e.message}")+ false+ })- val addM = customBuilder.javaClass.getDeclaredMethod("addSharedPath", spCls)- .apply { isAccessible = true }- addM.invoke(customBuilder, sp)+ }++ /**+ * Try each known SharedPath constructor in order.+ *+ * IMPORTANT: when `appDomain=false` is requested, we MUST find a+ * constructor that accepts it (the v3 10-param shape). Older shapes+ * default to in-app-domain and would surface as a VM startup crash+ * later (crosvm can't cross domains to reach the path). Refuse with+ * null in that case so the caller logs a clear "unavailable" instead+ * of letting the VM die with `reason=4`.+ *+ * Returns null if no compatible ctor was found.+ */+ private fun buildSharedPath(+ spCls: Class<*>, intT: Class<*>, boolT: Class<*>, strT: Class<*>,+ sharedPath: String, tag: String, socket: String, socketPath: String, appDomain: Boolean,+ hostUid: Int, hostGid: Int, guestUid: Int, guestGid: Int, mask: Int,+ ): Any? {+ // Shape v3: (String, 5×int, String, String, boolean, String) — AOSP main+ runCatching {+ val c = spCls.getDeclaredConstructor(+ strT, intT, intT, intT, intT, intT, strT, strT, boolT, strT+ ).apply { isAccessible = true }+ return c.newInstance(+ sharedPath, hostUid, hostGid, guestUid, guestGid, mask,+ tag, socket, appDomain, socketPath,+ )!!+ }+ // Older shapes can't honour `appDomain=false`. Refuse so the caller+ // skips the share cleanly instead of crashing the VM at start time.+ if (!appDomain) {+ val shapes = spCls.declaredConstructors.joinToString("; ") { c ->+ c.parameterTypes.joinToString(prefix = "(", postfix = ")") { it.simpleName }+ }+ android.util.Log.w("AvfReflect",+ "buildSharedPath: appDomain=false needed but device has only legacy " ++ "ctors; share would crash VM. Ctors available: $shapes")+ return null+ }+ // Shape v2: (String, 5×int, String, String, String) — Pixel 10 mustang+ runCatching {+ val c = spCls.getDeclaredConstructor(+ strT, intT, intT, intT, intT, intT, strT, strT, strT+ ).apply { isAccessible = true }+ return c.newInstance(+ sharedPath, hostUid, hostGid, guestUid, guestGid, mask,+ tag, socket, socketPath,+ )!!+ }+ // Shape v1: (String, String, 5×int, String, String) — older AOSP+ runCatching {+ val c = spCls.getDeclaredConstructor(+ strT, strT, intT, intT, intT, intT, intT, strT, strT+ ).apply { isAccessible = true }+ return c.newInstance(+ sharedPath, socket,+ hostUid, hostGid, guestUid, guestGid, mask,+ tag, socketPath,+ )!!+ }+ return null}fun setNetworkSupported(b: Any, value: Boolean) {