try improving the emulator start sequence

This commit is contained in:
Jean-Marie Mineau 2025-05-14 18:43:48 +02:00
parent 00ceb639c6
commit 69f1c7be10
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2

View file

@ -124,30 +124,50 @@ def worker(emu: str, apklist: list[str], out_folder: Path, script: Path):
# Start emulator with wipped data # Start emulator with wipped data
print(f"START ANALYSIS: {apk=}, emulator-{console_port}") print(f"START ANALYSIS: {apk=}, emulator-{console_port}")
proc = subprocess.Popen( i = 0
[ started = False
EMULATOR, while not started:
"-avd", if i != 0 and i % 10 == 0:
emu, print(
"-wipe-data", f"Warning: tried to start emulator-{console_port} (avd {emu}) for the {i}th time without success"
"-no-window", )
"-no-metrics", proc = subprocess.Popen(
"-debug-init", # dunno why but sometime needed [
"-ports", EMULATOR,
f"{console_port},{adb_port}", "-avd",
], emu,
stdout=fp_emu_stdout, "-wipe-data",
stderr=fp_emu_stderr, "-no-window",
) "-no-metrics",
subprocess.run( "-debug-init", # dunno why but sometime needed
[ADB, "-s", f"emulator-{console_port}", "wait-for-device"], "-ports",
stdout=fp_anly_stdout, f"{console_port},{adb_port}",
stderr=fp_anly_stderr, ],
) stdout=fp_emu_stdout,
stderr=fp_emu_stderr,
)
subprocess.run(
[ADB, "-s", f"emulator-{console_port}", "wait-for-device"],
stdout=fp_anly_stdout,
stderr=fp_anly_stderr,
)
j = 0
while not started:
started = f"emulator-{console_port}\t device" not in subprocess.run(
[ADB, "devices"], stdout=subprocess.PIPE
).stdout.decode("utf-8")
if not started:
time.sleep(1)
if j != 0 and j % 10 == 0:
print(
f"emulator-{console_port} has been offline for 10s, restarting it now"
)
proc.kill()
break
j += 1
i += 1
print(f"emulator-{console_port} started") print(f"emulator-{console_port} started")
fp_anly_stdout.write( fp_anly_stdout.write(f"START ANALYSIS: {apk=}, emulator-{console_port}\n")
f"START ANALYSIS: {apk=}, emulator-{console_port}, {folder=}"
)
subprocess.run( subprocess.run(
[ADB, "devices"], [ADB, "devices"],
stdout=fp_anly_stdout, stdout=fp_anly_stdout,