-
Notifications
You must be signed in to change notification settings - Fork 31
Add AvdManagerRunner for avdmanager CLI operations #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Xamarin.Android.Tools; | ||
|
|
||
| public class AvdInfo | ||
| { | ||
| public string Name { get; set; } = string.Empty; | ||
| public string? DeviceProfile { get; set; } | ||
| public string? Path { get; set; } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,183 @@ | ||||||||||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||||||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||||||||||
|
|
||||||||||||||
| using System; | ||||||||||||||
| using System.Collections.Generic; | ||||||||||||||
| using System.IO; | ||||||||||||||
| using System.Linq; | ||||||||||||||
| using System.Threading; | ||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||
|
|
||||||||||||||
| namespace Xamarin.Android.Tools; | ||||||||||||||
|
|
||||||||||||||
| /// <summary> | ||||||||||||||
rmarinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| /// Runs Android Virtual Device Manager (avdmanager) commands. | ||||||||||||||
| /// </summary> | ||||||||||||||
| public class AvdManagerRunner | ||||||||||||||
| { | ||||||||||||||
| readonly string avdManagerPath; | ||||||||||||||
| readonly IDictionary<string, string>? environmentVariables; | ||||||||||||||
|
|
||||||||||||||
| /// <summary> | ||||||||||||||
| /// Creates a new AvdManagerRunner with the full path to the avdmanager executable. | ||||||||||||||
| /// </summary> | ||||||||||||||
| /// <param name="avdManagerPath">Full path to avdmanager (e.g., "/path/to/sdk/cmdline-tools/latest/bin/avdmanager").</param> | ||||||||||||||
| /// <param name="environmentVariables">Optional environment variables to pass to avdmanager processes.</param> | ||||||||||||||
| public AvdManagerRunner (string avdManagerPath, IDictionary<string, string>? environmentVariables = null) | ||||||||||||||
| { | ||||||||||||||
| if (string.IsNullOrWhiteSpace (avdManagerPath)) | ||||||||||||||
| throw new ArgumentException ("Path to avdmanager must not be empty.", nameof (avdManagerPath)); | ||||||||||||||
| this.avdManagerPath = avdManagerPath; | ||||||||||||||
| this.environmentVariables = environmentVariables; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public async Task<IReadOnlyList<AvdInfo>> ListAvdsAsync (CancellationToken cancellationToken = default) | ||||||||||||||
| { | ||||||||||||||
| using var stdout = new StringWriter (); | ||||||||||||||
| using var stderr = new StringWriter (); | ||||||||||||||
| var psi = ProcessUtils.CreateProcessStartInfo (avdManagerPath, "list", "avd"); | ||||||||||||||
| var exitCode = await ProcessUtils.StartProcess (psi, stdout, stderr, cancellationToken, environmentVariables).ConfigureAwait (false); | ||||||||||||||
|
|
||||||||||||||
| ProcessUtils.ThrowIfFailed (exitCode, "avdmanager list avd", stderr); | ||||||||||||||
|
|
||||||||||||||
| return ParseAvdListOutput (stdout.ToString ()); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public async Task<AvdInfo> CreateAvdAsync (string name, string systemImage, string? deviceProfile = null, | ||||||||||||||
| bool force = false, CancellationToken cancellationToken = default) | ||||||||||||||
| { | ||||||||||||||
|
Comment on lines
+46
to
+48
|
||||||||||||||
| ProcessUtils.ValidateNotNullOrEmpty (name, nameof (name)); | ||||||||||||||
| ProcessUtils.ValidateNotNullOrEmpty (systemImage, nameof (systemImage)); | ||||||||||||||
|
Comment on lines
+49
to
+50
|
||||||||||||||
| ProcessUtils.ValidateNotNullOrEmpty (name, nameof (name)); | |
| ProcessUtils.ValidateNotNullOrEmpty (systemImage, nameof (systemImage)); | |
| if (string.IsNullOrWhiteSpace (name)) | |
| throw new ArgumentException ("AVD name cannot be null, empty, or whitespace.", nameof (name)); | |
| if (string.IsNullOrWhiteSpace (systemImage)) | |
| throw new ArgumentException ("System image cannot be null, empty, or whitespace.", nameof (systemImage)); |
Uh oh!
There was an error while loading. Please reload this page.