#!/usr/bin/env python3 """ Comprehensive Emulator Screenshot Capture and Verification Script. Boots the emulator, exercises SlopRoot and SuManager, captures working screenshots, verifies that no screenshot is blank or empty, and copies all captures to artifacts. """ import os import sys import time import shutil import subprocess from PIL import Image BASE_DIR = "/mnt/16aebe95-f920-450d-b96c-c06bb50ba672/sloproot" ARTIFACT_DIR = "/home/koutsie/.gemini/antigravity-cli/brain/a27700c5-eca4-4bd4-8f04-fddd76c9f8a6" DOCS_SCREENSHOTS = os.path.join(BASE_DIR, "docs/screenshots") os.makedirs(DOCS_SCREENSHOTS, exist_ok=True) ANDROID_HOME = os.path.join(BASE_DIR, "android-sdk") ANDROID_AVD_HOME = os.path.join(BASE_DIR, "avd") env = os.environ.copy() env["ANDROID_HOME"] = ANDROID_HOME env["ANDROID_AVD_HOME"] = ANDROID_AVD_HOME env["PATH"] = f"{ANDROID_HOME}/emulator:{ANDROID_HOME}/platform-tools:{env['PATH']}" PORT = "5554" DEVICE = f"emulator-{PORT}" def adb_cmd(*args): return subprocess.run(["adb", "-s", DEVICE] + list(args), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) def take_screenshot(filename, description): out_path = os.path.join(DOCS_SCREENSHOTS, filename) print(f"Capturing: {description} -> {filename}...") time.sleep(2) # Use screencap via shell res = subprocess.run(["python3", os.path.join(BASE_DIR, "tests/adb_screenshot.py"), out_path, DEVICE], env=env) if res.returncode != 0 or not os.path.exists(out_path): raise RuntimeError(f"Screenshot failed for {filename}") # Verify not empty / not black with Image.open(out_path) as im: colors = im.getcolors(maxcolors=100000) num_colors = len(colors) if colors else 100000 print(f" Verified {filename}: size={im.size}, colors={num_colors}") if num_colors < 20: raise ValueError(f"Screenshot {filename} appears blank or empty! Color count: {num_colors}") # Copy to artifact dir artifact_path = os.path.join(ARTIFACT_DIR, filename) shutil.copyfile(out_path, artifact_path) print(f" Saved to artifact directory: {artifact_path}") return out_path def main(): # Kill any existing emulator subprocess.run(["adb", "emu", "kill"], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) time.sleep(2) print("Starting test_api19_x86 emulator...") emu_proc = subprocess.Popen( ["emulator", "-avd", "test_api19_x86", "-port", PORT, "-no-window", "-no-audio", "-no-boot-anim", "-gpu", "swiftshader_indirect"], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL ) try: print("Waiting for boot completion...") adb_cmd("wait-for-device") for i in range(60): res = adb_cmd("shell", "getprop", "sys.boot_completed") if res.stdout.strip() == "1": print(f"Boot completed in {i}s") break time.sleep(1) # Unlock screen adb_cmd("shell", "sqlite3", "/data/data/com.android.providers.settings/databases/settings.db", 'INSERT OR REPLACE INTO secure (name, value) VALUES ("lockscreen.disabled", "1");') adb_cmd("shell", "svc", "power", "stayon", "true") adb_cmd("shell", "input", "keyevent", "82") adb_cmd("shell", "input", "keyevent", "3") time.sleep(2) # Install latest APKs print("Installing sumanager.apk and sloproot.apk...") res1 = adb_cmd("install", "-r", os.path.join(BASE_DIR, "sumanager/build/sumanager.apk")) res2 = adb_cmd("install", "-r", os.path.join(BASE_DIR, "app/build/sloproot.apk")) print(f"Install SuManager: {res1.stdout.strip()}") print(f"Install SlopRoot: {res2.stdout.strip()}") # 1. Launcher Home Screen adb_cmd("shell", "input", "keyevent", "3") time.sleep(2) take_screenshot("01_launcher_home.png", "Home screen with launcher icons") # 2. SlopRoot Main Screen adb_cmd("shell", "am", "start", "-n", "org.sloproot/.MainActivity") time.sleep(3) take_screenshot("02_sloproot_main.png", "SlopRoot main activity on launch") # 3. SlopRoot Click Check Root # Check root button is in row 1, col 1: around x=80, y=238 adb_cmd("shell", "input", "tap", "80", "238") time.sleep(3) take_screenshot("03_sloproot_check_root.png", "SlopRoot after clicking Check root") # 4. SlopRoot Root Terminal Activity # Terminal button is in row 2, col 1: around x=80, y=285 adb_cmd("shell", "input", "tap", "80", "285") time.sleep(3) take_screenshot("04_sloproot_terminal.png", "SlopRoot interactive root terminal") # In Root Terminal, tap Preset 'id' (x=80, y=95) and tap Run (x=280, y=65) adb_cmd("shell", "input", "tap", "80", "95") time.sleep(1) adb_cmd("shell", "input", "tap", "280", "65") time.sleep(2) take_screenshot("05_sloproot_terminal_executed.png", "SlopRoot terminal command execution") # Back to home adb_cmd("shell", "input", "keyevent", "4") time.sleep(1) adb_cmd("shell", "input", "keyevent", "4") time.sleep(1) # 5. SuManager Main Screen (Apps Tab) adb_cmd("shell", "am", "start", "-n", "org.sloproot.sumanager/.MainActivity") time.sleep(3) take_screenshot("06_sumanager_main_apps.png", "SuManager main activity (Apps tab)") # 6. SuManager Click Check Root (x=80, y=185) adb_cmd("shell", "input", "tap", "80", "185") time.sleep(2) take_screenshot("07_sumanager_checked_root.png", "SuManager after clicking Check root") # 7. SuManager Switch to Logs Tab (x=160, y=90) adb_cmd("shell", "input", "tap", "160", "90") time.sleep(2) take_screenshot("08_sumanager_logs_tab.png", "SuManager Logs tab") # 8. SuManager Switch to Settings Tab (x=270, y=90) adb_cmd("shell", "input", "tap", "270", "90") time.sleep(2) take_screenshot("09_sumanager_settings_tab.png", "SuManager Settings tab") # 9. SuManager Switch back to Apps and open Terminal (Apps tab: x=50, y=90, Terminal btn: x=240, y=185) adb_cmd("shell", "input", "tap", "50", "90") time.sleep(1) adb_cmd("shell", "input", "tap", "240", "185") time.sleep(2) take_screenshot("10_sumanager_terminal.png", "SuManager Root Terminal activity") # Run command 'id' in SuManager terminal adb_cmd("shell", "input", "text", "id") time.sleep(1) # Tap Run (x=280, y=60) adb_cmd("shell", "input", "tap", "280", "60") time.sleep(2) take_screenshot("11_sumanager_terminal_executed.png", "SuManager terminal id execution") print("=== All screenshots captured, verified, and copied successfully! ===") finally: print("Shutting down emulator...") adb_cmd("emu", "kill") try: emu_proc.terminate() emu_proc.wait(timeout=5) except Exception: emu_proc.kill() print("Emulator shut down cleanly.") if __name__ == "__main__": main()