fix: add MAIN/LAUNCHER flags to Android launcher activity resolver

Merged
MY
9mo ago
+168-39

Summary

  • Add -a android.intent.action.MAIN -c android.intent.category.LAUNCHER to the resolve-activity fallback command in resolveAndroidLaunchComponent()
  • The resolver was missing these intent flags, causing it to resolve the wrong activity on multi-entry apps (e.g. Microsoft Outlook)
  • E2E testing uncovered a deeper issue: am start -W -p <package> exits with code 0 even when it fails to resolve the activity, printing Error: Activity not started, unable to resolve Intent to stdout. The original try/catch never triggered the fallback because runCmd did not throw on exit code 0. Added isAmStartError() to detect this silent failure and correctly fall through to the component-based fallback.
  • Add unit tests for resolver parsing, error detection, and launch command construction

Changes

Commit 1: Fix resolve-activity flags

resolveAndroidLaunchComponent() now passes -a android.intent.action.MAIN -c android.intent.category.LAUNCHER to cmd package resolve-activity, ensuring the correct launcher activity is resolved for multi-entry apps.

Commit 2: Detect am start silent failures

  • Replace try/catch with allowFailure: true + stdout/stderr inspection via isAmStartError()
  • am start -p returning exit code 0 with Error: Activity not started in stdout now correctly triggers the component-based fallback
  • Verified end-to-end on a physical Android device with Microsoft Outlook

Test plan

  • parseAndroidLaunchComponent correctly parses multi-entry resolve output
  • isAmStartError detects am start failure messages in stdout
  • isAmStartError returns false for successful launches
  • Fallback resolve-activity command includes -a MAIN -c LAUNCHER flags
  • Default launch path still uses -p <package> (system-driven resolution)
  • E2E: agent-device open "com.microsoft.office.outlook" --platform android launches Outlook without --activity flag on physical device