Files
gitlab-instance-0a899031_lo…/_adb_test.py
2026-04-05 01:00:07 -05:00

113 lines
3.3 KiB
Python

import os
import sys
import time
import paramiko
from _gps_ssh_auth import ssh_password
HOST = "192.168.2.179"
USER = "eric"
GPS_ROOT = os.path.dirname(os.path.abspath(__file__))
APK = "/home/eric/codex_apk_recovery/rebuilt_app/app/build/outputs/apk/debug/app-debug.apk"
PKG = "com.lerist.fakelocation.rebuilt.debug"
def main():
password = ssh_password(GPS_ROOT)
if not password:
print("Set FL_SSH_PASS or fl_ssh_pass.txt", file=sys.stderr)
sys.exit(2)
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(HOST, username=USER, password=password, timeout=25)
def run(cmd: str, timeout: int = 90) -> tuple[int, str, str]:
stdin, stdout, stderr = client.exec_command(cmd, timeout=timeout)
out = stdout.read().decode(errors="replace")
err = stderr.read().decode(errors="replace")
code = stdout.channel.recv_exit_status()
return code, out, err
_, devs, _ = run("adb devices -l", 30)
print("=== adb devices ===")
print(devs.strip())
def is_ready_usb(line: str) -> bool:
parts = line.split()
return len(parts) >= 2 and parts[1] == "device" and "127.0.0.1" not in line and "emulator" not in line
serial = None
for line in devs.splitlines():
if is_ready_usb(line):
serial = line.split()[0]
break
if not serial:
for line in devs.splitlines():
parts = line.split()
if len(parts) >= 2 and parts[1] == "device" and "unauthorized" not in line:
serial = parts[0]
break
if not serial:
print("NO_DEVICE")
client.close()
sys.exit(1)
print("USING_SERIAL", serial)
_, out, _ = run(f"test -f {APK} && echo OK || echo MISSING", 10)
if "OK" not in out:
print("APK_MISSING:", APK)
client.close()
sys.exit(1)
_, out, err = run(f"adb -s {serial} install -r {APK} 2>&1", 120)
print("=== install ===")
print((out or err).strip())
_, out, err = run(f"adb -s {serial} shell pm path {PKG} 2>&1", 30)
print("=== pm path ===")
print((out or err).strip())
run(f"adb -s {serial} shell am force-stop {PKG} 2>&1", 15)
_, out, err = run(
f"adb -s {serial} shell am start -W -n {PKG}/com.lerist.fakelocation.rebuilt.MainActivity 2>&1",
45,
)
print("=== am start -W ===")
print((out or err).strip())
time.sleep(2)
_, out, err = run(
f"adb -s {serial} shell dumpsys activity activities 2>&1 | head -80",
30,
)
blob = out + err
for line in blob.splitlines():
if "topResumedActivity" in line or "mResumedActivity" in line:
print("=== activity line ===", line.strip())
_, out, err = run(f"adb -s {serial} shell pidof {PKG}", 15)
print("=== pidof ===", (out or err).strip())
_, out, err = run(
f"adb -s {serial} shell uiautomator dump /sdcard/window_dump.xml 2>&1",
25,
)
print("=== uiautomator dump ===", (out or err).strip()[:200])
_, out, err = run(
f"adb -s {serial} shell cat /sdcard/window_dump.xml 2>&1 | head -c 1200",
20,
)
print("=== dump xml head ===")
print((out or err).strip()[:800])
client.close()
print("DONE")
if __name__ == "__main__":
main()