#!/usr/bin/env python3 """ Dialog and Policy Authorization Screenshot Capture Script. Captures root authorization requests, allow/deny flows, policy lists, access logs, and SlopRoot dialogs in the emulator, verifying each capture. """ 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) 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}") 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}") 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(): subprocess.run(["adb", "emu", "kill"], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) time.sleep(2) print("Starting test_api19_x86 emulator for dialog and policy tests...") 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: 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) 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) adb_cmd("install", "-r", os.path.join(BASE_DIR, "sumanager/build/sumanager.apk")) adb_cmd("install", "-r", os.path.join(BASE_DIR, "app/build/sloproot.apk")) # 1. SlopRoot Root Confirmation Dialog adb_cmd("shell", "am", "start", "-n", "org.sloproot/.MainActivity") time.sleep(2) # Tap 'Root device' button (x=240, y=238) adb_cmd("shell", "input", "tap", "240", "238") time.sleep(2) take_screenshot("12_sloproot_dialog_confirm_root.png", "SlopRoot confirmation dialog for Root device") # Dismiss dialog by pressing Cancel (x=240, y=380 or back) adb_cmd("shell", "input", "keyevent", "4") time.sleep(1) # 2. SlopRoot Cleanup Confirmation Dialog # Tap 'Cleanup' button (x=240, y=338) adb_cmd("shell", "input", "tap", "240", "338") time.sleep(2) take_screenshot("13_sloproot_dialog_confirm_cleanup.png", "SlopRoot confirmation dialog for Cleanup") adb_cmd("shell", "input", "keyevent", "4") time.sleep(1) # 3. Superuser Authorization Request Prompt (Allow scenario) adb_cmd("shell", "am", "start", "-n", "org.sloproot.sumanager/.RequestActivity", "--ei", "from.uid", "10042", "--es", "caller.package", "org.cyanogenmod.filemanager", "--es", "command", "ls -l /data") time.sleep(3) take_screenshot("14_sumanager_request_prompt.png", "SuManager interactive root authorization prompt") # Tap 'Allow' button (x=240, y=285) adb_cmd("shell", "input", "tap", "240", "285") time.sleep(2) # 4. SuManager Apps list showing newly authorized policy adb_cmd("shell", "am", "start", "-n", "org.sloproot.sumanager/.MainActivity") time.sleep(3) take_screenshot("15_sumanager_apps_with_allowed_policy.png", "SuManager Apps tab with allowed policy record") # 5. SuManager Logs tab showing access grant entry # Tap Logs tab (x=160, y=90) adb_cmd("shell", "input", "tap", "160", "90") time.sleep(2) take_screenshot("16_sumanager_logs_with_entry.png", "SuManager Logs tab with recorded root access log") # 6. Superuser Authorization Request Prompt (Deny scenario) adb_cmd("shell", "am", "start", "-n", "org.sloproot.sumanager/.RequestActivity", "--ei", "from.uid", "10088", "--es", "caller.package", "com.suspicious.payload", "--es", "command", "reboot recovery") time.sleep(3) take_screenshot("17_sumanager_request_prompt_deny.png", "SuManager root authorization prompt for untrusted request") # Tap 'Deny' button (x=80, y=285) adb_cmd("shell", "input", "tap", "80", "285") time.sleep(2) # 7. SuManager Apps list showing both policies (Allowed and Denied) adb_cmd("shell", "am", "start", "-n", "org.sloproot.sumanager/.MainActivity") time.sleep(1) # Tap Apps tab (x=50, y=90) adb_cmd("shell", "input", "tap", "50", "90") time.sleep(2) take_screenshot("18_sumanager_apps_multi_policy.png", "SuManager Apps tab with multiple managed policies") # 8. SuManager Logs tab showing multiple log records # Tap Logs tab (x=160, y=90) adb_cmd("shell", "input", "tap", "160", "90") time.sleep(2) take_screenshot("19_sumanager_logs_multi_entries.png", "SuManager Logs tab with multiple access events") print("=== Dialog and policy 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()