Skip to content

fix(adb): launch apps with monkey --pct-syskeys 0 - #216

Open
glayyiyi wants to merge 1 commit into
google:mainfrom
glayyiyi:fix/adb-launch-no-syskeys
Open

glayyiyi wants to merge 1 commit into
google:mainfrom
glayyiyi:fix/adb-launch-no-syskeys

Conversation

@glayyiyi

Copy link
Copy Markdown

Summary

AndroidAdbDriver.launch_app runs monkey -p <pkg> -c android.intent.category.LAUNCHER 1. On devices without physical keys, that one event does not launch the app. This covers emulators, Redroid, and car head units. monkey prints ** SYS_KEYS has no physical keys but with factor 2.0%., reports no Events injected, and the previous app stays in the foreground.

As a result, every task with a locked app spends about 45 s on three launch attempts before the agent gives up. The agent then opens the app from the app drawer, which costs extra steps.

This PR adds --pct-syskeys 0. monkey then injects the launch (Events injected: 1), and the app comes to the foreground. On devices that do have keys, behavior is unchanged: the flag only disables system-key events, and a launch never needs one.

Reproduction (Redroid, Android 13, 1920×720)

$ adb shell monkey -p com.example.themesim -c android.intent.category.LAUNCHER 1
** SYS_KEYS has no physical keys but with factor 2.0%.
$ adb shell dumpsys window displays | grep mCurrentFocus
  mCurrentFocus=Window{… io.github.seijikohara.femto/…MainActivity}      # launcher still in front

$ adb shell monkey --pct-syskeys 0 -p com.example.themesim -c android.intent.category.LAUNCHER 1
Events injected: 1
$ adb shell dumpsys window displays | grep mCurrentFocus
  mCurrentFocus=Window{… com.example.themesim/com.example.themesim.MainActivity}

com.android.settings behaves the same way.

Effect on a Flash run

I ran two test cases through the Flash profile on the same device, judging each result by device state read over adb.

case before after
Apply a theme in a custom-drawn theme store app (locked app) 142–152 s, 6 steps 22 s, 2–3 steps
Turn on Dark theme in Settings 121–191 s, 12–14 steps 30 s, 5 steps

Before the change, 22 of the last 24 locked-app tasks in the log started with Failed to launch locked app … after 3 attempts.

Tests

  • tests/unit/test_drivers.py now asserts the exact launch command.
  • make test, make lint and make typecheck pass (0 errors).

On devices without physical keys (emulators, Redroid, car head units) monkey warns
"SYS_KEYS has no physical keys" and its single event does not launch the app, so
the initial app launch timed out three times (about 45 s) before the agent opened
the app from the app drawer. With --pct-syskeys 0 the launch event is injected
("Events injected: 1") and the app comes to the foreground.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant