Skip to content

Add AdbRunner app management APIs (install/uninstall/launch/force-stop/list-packages) #12084

Description

@rmarinho

Summary

Add app management APIs to Xamarin.Android.Tools.AdbRunner so the MAUI DevTools CLI can install, uninstall, launch, and force-stop Android apps on devices/emulators without consumers shelling out to adb install / pm / am.

Context

AdbRunner already exposes ListDevicesAsync, WaitForDeviceAsync, StopEmulatorAsync, GetShellPropertyAsync, RunShellCommandAsync, and (via dotnet/android-tools#305) reverse-port management. The next gap is the app lifecycle, which both the VS Code MAUI extension's ServiceHub and the MAUI DevTools CLI currently implement independently. See maui-labs#197 for the full audit.

Proposed API

namespaceXamarin.Android.Tools;publicpartialclassAdbRunner{/// adb -s <serial> install [-r] [-g] <apk>publicvirtualTask<AdbAppInstallResult>InstallPackageAsync(stringserial,stringapkPath,boolreplaceExisting=true,boolgrantRuntimePermissions=false,CancellationTokencancellationToken=default);/// adb -s <serial> uninstall [-k] <package>publicvirtualTask<AdbAppOperationResult>UninstallPackageAsync(stringserial,stringpackageName,boolkeepData=false,CancellationTokencancellationToken=default);/// adb -s <serial> shell am start -n <package>/<activity>/// If activity is null, resolves the launcher activity via cmd package resolve-activity.publicvirtualTask<AdbAppOperationResult>LaunchAppAsync(stringserial,stringpackageName,string?activity=null,IReadOnlyDictionary<string,string>?extras=null,CancellationTokencancellationToken=default);/// adb -s <serial> shell am force-stop <package>publicvirtualTask<AdbAppOperationResult>ForceStopAsync(stringserial,stringpackageName,CancellationTokencancellationToken=default);/// adb -s <serial> shell pm list packages [-3] [-s] [filter]publicvirtualTask<IReadOnlyList<string>>ListPackagesAsync(stringserial,PackageFilterfilter=PackageFilter.All,string?namePattern=null,CancellationTokencancellationToken=default);}publicrecordAdbAppInstallResult(boolSuccess,string?PackageName,string?ErrorCode,// INSTALL_FAILED_VERSION_DOWNGRADE etc.stringStdout,stringStderr);publicrecordAdbAppOperationResult(boolSuccess,stringStdout,stringStderr);publicenumPackageFilter{All,ThirdParty,System,Disabled,Enabled}

Notes:

  • InstallPackageAsync should parse the INSTALL_FAILED_* error codes that pm install returns and surface them in ErrorCode so callers can map to typed errors (the MAUI DevTools CLI maps these to E2xxx codes).
  • LaunchAppAsync activity resolution: when activity == null, run cmd package resolve-activity --components <package> and use the name=... line.

Consumer

  • MAUI DevTools CLI (dotnet/maui-labs) — new subcommands under maui android device: install, uninstall, launch, stop, list. See maui-labs#197 audit (these replace raw adb install / am start / am force-stop fallbacks in the DevFlow skills).
  • VS Code MAUI extension ServiceHub → CLI migration. Today MauiAndroidPlatform.ts calls AndroidDeviceManager.installApp() / launchApp() / forceStopApp().
  • DevFlow integration tests that boot an emulator, install the sample APK, launch, and tear down.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    android-toolsIssues migrated from dotnet/android-tools / relates to the xamarin-android-tools subtreeneeds-triageIssues that need to be assigned.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions