Android AVF Terminal: pKVM hypervisor, ForwarderHost JNI and 24h wake bounds
Offline APK, ELF, RRO, and JS teardown of Android Virtualization Framework Terminal (versionCode 37): pKVM and crosvm primitives, new2 Compose refactor, ForwarderHost vsock JNI exports, gfxstream overlay config, 24h KeepAwakeDuration ceiling, StorageBalloonWorker, and zero USB passthrough.
- pKVM + ConfigJson -> VirtualMachineConfig
- ForwarderHost JNI vsock + gfxstream + ttyd bridge
- 1,440m KeepAwakeDuration cap + zero USB passthrough
Investigation question
How does Android’s stock AVF Linux Terminal boot a Debian ARM64 VM on pKVM, forward guest TCP ports across vsock via libforwarder_host_jni.so, accelerate GUI sessions with gfxstream, and constrain background persistence and USB passthrough?
Observed
Offline static inspection of Android’s stock AVF Linux Terminal APK (com.android.virtualization.terminal, versionCode 37, targetSdk 37, 5,201 DEX classes), its hardware overlay RRO (TerminalOverlay.apk), extracted libforwarder_host_jni.so (256,800 B ELF64 AArch64), WebView assets/js/ (7 files), and public AOSP Virtualization docs maps the full VM boundary. Underneath Android’s protected hypervisor (kvm.arm-protected over /dev/kvm and /dev/vhost-vsock), VmTerminalAppGoogle.apk holds privileged USE_CUSTOM_VIRTUAL_MACHINE alongside MANAGE_VIRTUAL_MACHINE (third-party apps only receive non-custom microdroid VMs). Android 17’s new2 Compose package splits orchestration across VmService (foreground specialUse wake-lock manager), VmController (23-field ConfigJson to VirtualMachineConfig.Builder), and GuestAgentController (gRPC/AIDL port forwarding and clipboard sync), while TerminalOverlay.apk sets gfxstream_supported=true for GraphicsManager. Native libforwarder_host_jni.so (NX, RELRO, BIND_NOW hardened) exports exactly three JNI symbols (run, shutdown, updateListeningPorts) bridging guest ports across vsock alongside ttyd WebSocket proxy hooks in assets/js/. Critically, KeepAwakeDuration defines finite enum steps capping at ONE_DAY (1,440 minutes = 24 hours) with zero indefinite mode, and exhaustive class and manifest inspection confirms zero USB host permissions or passthrough classes.
Inferred
Four operational boundaries govern persistent workloads inside Android’s stock Debian Terminal: (1) after 24 hours (1,440 minutes), wakeLockTimeoutJob fires releaseWakeLock(), exposing the guest VM to Android Doze unless a host-side supervisor renews wake leases or maintains charging wake policy; (2) pure CLI/daemon workflows can rely on VmService and ForwarderHost vsock forwarding without keeping GUI DisplayActivity open; (3) StorageBalloonWorker dynamically shrinks sparse guest disk space against host StatFs free bytes, so large container builds or logs risk balloon pressure on tight flash partitions; and (4) USB hardware cannot pass directly through crosvm from stock Terminal and must bridge indirectly over host Android TCP/vsock.
Unknown & limitations
This offline static inspection of public AOSP documentation and extracted Terminal APK/ELF/JS artifacts did not benchmark live guest CPU/disk I/O throughput, live gfxstream Vulkan rendering stability, or privileged VirtualizationService APEX internals beyond the Terminal application package.
Architecture
Android Terminal layers a Jetpack Compose/new2 host app (VmService, VmController, GuestAgentController, DisplayActivity) and WebView ttyd UI over Android Virtualization Framework (VirtualMachineConfig, pKVM kvm.arm-protected, crosvm), /dev/vhost-vsock (libforwarder_host_jni.so), RRO-configured VirtIO gfxstream GPU forwarding, and a Debian ARM64 cloud-init guest (cidata.iso).
Domain & data models
ConfigJson maps 23 fields (isProtected, memory_mib, hugepages, cpuTopology, customImageConfig, disks, display, gpu, network, sharedPath) to VirtualMachineConfig.Builder; KeepAwakeDuration enumerates 9 constants from OFF (0) to ONE_DAY (1440 min); StorageBalloonWorker tracks host UUID_DEFAULT allocatable bytes to recalculate guest sparse disk availability.
Workflows & state machines
Startup reads TerminalOverlay gfxstream flags -> VmController builds VirtualMachineConfig and checks canUseTtydOverVsock() -> GuestAgentController initializes Debian server gRPC, port forwarding (ForwarderHost), and clipboard sync -> ttyd WebView proxies window.WebSocket (parsing close code 1000 vs error); StorageBalloonWorker reschedules via WorkManager while wakeLockTimeoutJob enforces the 24-hour wake cap.
API & protocol surfaces
Three JNI entrypoints in libforwarder_host_jni.so (ForwarderHost.run, shutdown, updateListeningPorts), GuestAgentController Debian gRPC/AIDL methods (startDebianServerGrpc, enablePortForwarding, pullClipboardFromGuest, pushClipboardToGuest), and WebView TerminalApp JS bridge hooks (websocket_interceptor.js, terminal_disconnect.js, touch_to_mouse_handler.js).