Files
trycua--cua/samples/python/2_ephemeral_fdroid.py
T
wehub-resource-sync 91e75e620b
CI: cua-driver distro-compat matrix / debian:12 (glibc 2.36) (push) Has been cancelled
CI: SPDX Headers / Check SPDX headers (warn-only) (push) Has been cancelled
CD: Docs MCP Server / build (linux/amd64) (push) Has been cancelled
CD: Docs MCP Server / build (linux/arm64) (push) Has been cancelled
CD: Docs MCP Server / merge (push) Has been cancelled
CI: cua-driver distro-compat matrix / Resolve release version (push) Has been cancelled
CI: cua-driver distro-compat matrix / fedora:41 (glibc 2.40) (push) Has been cancelled
CI: cua-driver distro-compat matrix / rockylinux:9 (glibc 2.34) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:22.04 (glibc 2.35) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:24.04 (glibc 2.39) (push) Has been cancelled
CI: cua-driver distro-compat matrix / Distro compat summary (push) Has been cancelled
CI: Rust Linux unit / Rust Linux unit and compile (push) Has been cancelled
CI: Rust Windows unit / Rust Windows unit and compile (push) Has been cancelled
CI: Nix Linux Rust source / Nix / compositor build (push) Has been cancelled
CI: Nix Linux Rust source / Nix / driver package (push) Has been cancelled
CI: Nix Linux Rust source / Nix / Rust unit tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:19 +08:00

59 lines
1.6 KiB
Python

"""
Demo 2: Ephemeral Android Sandbox — F-Droid APK Install
Spins up a local Android VM, installs F-Droid, takes a screenshot.
Sandbox is automatically destroyed on exit.
Usage:
python samples/python/2_ephemeral_fdroid.py
"""
import asyncio
from pathlib import Path
from cua_sandbox import Sandbox
from cua_sandbox.image import Image
FDROID_APK = "https://f-droid.org/F-Droid.apk"
OUT_DIR = Path(__file__).parent / "out"
async def main():
OUT_DIR.mkdir(exist_ok=True)
print("\n" + "=" * 50)
print(" Ephemeral Android Sandbox — F-Droid")
print("=" * 50 + "\n")
image = Image.android().apk_install(FDROID_APK)
print("Starting local Android VM with F-Droid pre-installed...")
print("(VM is ephemeral — destroyed automatically on exit)\n")
async with Sandbox.ephemeral(image, local=True) as sb:
print("✓ Sandbox ready\n")
w, h = await sb.screen.size()
print(f" Screen size : {w}x{h}")
screenshot = await sb.screenshot(format="png")
out = OUT_DIR / "fdroid_home.png"
out.write_bytes(screenshot)
print(f" Screenshot : {out} ({len(screenshot):,} bytes)")
print("\nLaunching F-Droid...")
await sb.shell.run("am start -n org.fdroid.fdroid/.views.main.MainActivity")
await asyncio.sleep(3)
screenshot2 = await sb.screenshot(format="png")
out2 = OUT_DIR / "fdroid_launched.png"
out2.write_bytes(screenshot2)
print(f" Screenshot : {out2} ({len(screenshot2):,} bytes)")
print("\n✓ Sandbox destroyed\n")
print("=" * 50 + "\n")
if __name__ == "__main__":
asyncio.run(main())