fixed app launcher commmand

This commit is contained in:
user
2026-03-28 20:17:44 +02:00
parent 3e018d60f9
commit 7c210ffe8f
2 changed files with 68 additions and 9 deletions

View File

@@ -22,17 +22,34 @@ export class AndroidCommandExecutor {
["-s", serial, "shell", "am", "force-stop", packageName],
{ allowFailure: true },
);
await this.run([
"-s",
const launchActivity = await this.resolveLauncherActivity(
serial,
"shell",
"monkey",
"-p",
packageName,
"-c",
"android.intent.category.LAUNCHER",
"1",
]);
);
if (launchActivity) {
await this.run([
"-s",
serial,
"shell",
"am",
"start",
"-n",
launchActivity,
]);
} else {
await this.run([
"-s",
serial,
"shell",
"monkey",
"-p",
packageName,
"-c",
"android.intent.category.LAUNCHER",
"1",
]);
}
return { serial };
}
@@ -54,4 +71,41 @@ export class AndroidCommandExecutor {
throw error;
}
}
private async resolveLauncherActivity(
serial: string,
packageName: string,
): Promise<string | null> {
const result = await this.run(
[
"-s",
serial,
"shell",
"cmd",
"package",
"resolve-activity",
"--brief",
"-a",
"android.intent.action.MAIN",
"-c",
"android.intent.category.LAUNCHER",
packageName,
],
{ allowFailure: true },
);
const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`;
const lines = output
.split("\n")
.map((line) => line.trim())
.filter(Boolean);
for (const line of lines) {
if (line.includes("/") && !line.startsWith("priority=")) {
return line;
}
}
return null;
}
}