A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
feat(hostbridge): add base64 wire helpers for guest host bridge
ExTv4ddb07db60a5
diff --git a/app/src/main/java/com/excp/podroid/engine/hostbridge/HostProtocol.kt b/app/src/main/java/com/excp/podroid/engine/hostbridge/HostProtocol.ktnew file mode 100644index 0000000..3ecdb95--- /dev/null+++ b/app/src/main/java/com/excp/podroid/engine/hostbridge/HostProtocol.kt@@ -0,0 +1,32 @@+/*+ * Podroid - Rootless Podman for Android+ * Copyright (C) 2024-2026 Podroid contributors+ *+ * Shared wire helpers for the guest -> Android host bridge. Free-text fields+ * (notification title/body, the forward listing, error messages) are standard+ * base64 so UTF-8, spaces, and newlines survive the line-oriented protocol.+ * java.util.Base64 (not android.util.Base64) keeps the dispatcher unit-testable.+ */+package com.excp.podroid.engine.hostbridge++import java.util.Base64++object HostProtocol {+ const val PRIO_LOW = "low"+ const val PRIO_NORMAL = "normal"+ const val PRIO_HIGH = "high"+ val VALID_PRIORITIES = setOf(PRIO_LOW, PRIO_NORMAL, PRIO_HIGH)++ fun enc(s: String): String =+ Base64.getEncoder().encodeToString(s.toByteArray(Charsets.UTF_8))++ /** Decodes base64; returns null on malformed input rather than throwing. */+ fun dec(s: String): String? = try {+ String(Base64.getDecoder().decode(s), Charsets.UTF_8)+ } catch (_: IllegalArgumentException) {+ null+ }++ fun ok(payload: String? = null): String = if (payload == null) "OK" else "OK $payload"+ fun err(message: String): String = "ERR ${enc(message)}"+}diff --git a/app/src/test/java/com/excp/podroid/engine/hostbridge/HostRequestDispatcherTest.kt b/app/src/test/java/com/excp/podroid/engine/hostbridge/HostRequestDispatcherTest.ktnew file mode 100644index 0000000..9da606c--- /dev/null+++ b/app/src/test/java/com/excp/podroid/engine/hostbridge/HostRequestDispatcherTest.kt@@ -0,0 +1,17 @@+package com.excp.podroid.engine.hostbridge++import org.junit.Assert.assertEquals+import org.junit.Assert.assertNull+import org.junit.Test++class HostProtocolTest {+ @Test fun base64RoundTripsUtf8() {+ // Non-ASCII (CJK) + spaces + newline must survive.+ val original = "构建完成 build done\nline2"+ assertEquals(original, HostProtocol.dec(HostProtocol.enc(original)))+ }++ @Test fun decReturnsNullOnGarbage() {+ assertNull(HostProtocol.dec("!!!not base64!!!"))+ }+}