Skip to content

Commit 39617c8

Browse files
rmarinhoCopilot
andcommitted
Refactor EmulatorRunner per copilot instructions
- Add XML documentation to all public members - Use 'is not null' instead of '!= null' - Improve code formatting - Remove unused variable assignment Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 89cf17c commit 39617c8

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

src/Xamarin.Android.Tools.AndroidSdk/Runners/EmulatorRunner.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,45 @@ public class EmulatorRunner
1717
{
1818
readonly Func<string?> getSdkPath;
1919

20+
/// <summary>
21+
/// Creates a new <see cref="EmulatorRunner"/>.
22+
/// </summary>
23+
/// <param name="getSdkPath">Function that returns the Android SDK path.</param>
24+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="getSdkPath"/> is null.</exception>
2025
public EmulatorRunner (Func<string?> getSdkPath)
2126
{
2227
this.getSdkPath = getSdkPath ?? throw new ArgumentNullException (nameof (getSdkPath));
2328
}
2429

30+
/// <summary>
31+
/// Gets the path to the emulator executable, or null if not found.
32+
/// </summary>
2533
public string? EmulatorPath {
2634
get {
2735
var sdkPath = getSdkPath ();
2836
if (string.IsNullOrEmpty (sdkPath))
2937
return null;
38+
3039
var ext = OS.IsWindows ? ".exe" : "";
3140
var path = Path.Combine (sdkPath, "emulator", "emulator" + ext);
41+
3242
return File.Exists (path) ? path : null;
3343
}
3444
}
3545

36-
public bool IsAvailable => EmulatorPath != null;
46+
/// <summary>
47+
/// Gets whether the Android Emulator is available.
48+
/// </summary>
49+
public bool IsAvailable => EmulatorPath is not null;
3750

3851
/// <summary>
3952
/// Starts an AVD and returns the process.
4053
/// </summary>
54+
/// <param name="avdName">The name of the AVD to start.</param>
55+
/// <param name="coldBoot">Whether to perform a cold boot (ignore snapshots).</param>
56+
/// <param name="additionalArgs">Additional command-line arguments.</param>
57+
/// <returns>The emulator process.</returns>
58+
/// <exception cref="InvalidOperationException">Thrown when Android Emulator is not found.</exception>
4159
public Process StartAvd (string avdName, bool coldBoot = false, string? additionalArgs = null)
4260
{
4361
if (!IsAvailable)
@@ -58,12 +76,16 @@ public Process StartAvd (string avdName, bool coldBoot = false, string? addition
5876

5977
var process = new Process { StartInfo = psi };
6078
process.Start ();
79+
6180
return process;
6281
}
6382

6483
/// <summary>
6584
/// Lists the names of installed AVDs.
6685
/// </summary>
86+
/// <param name="cancellationToken">Cancellation token.</param>
87+
/// <returns>A list of AVD names.</returns>
88+
/// <exception cref="InvalidOperationException">Thrown when Android Emulator is not found.</exception>
6789
public async Task<List<string>> ListAvdNamesAsync (CancellationToken cancellationToken = default)
6890
{
6991
if (!IsAvailable)
@@ -77,14 +99,15 @@ public async Task<List<string>> ListAvdNamesAsync (CancellationToken cancellatio
7799
CreateNoWindow = true
78100
};
79101

80-
var exitCode = await ProcessUtils.StartProcess (psi, stdout, null, cancellationToken).ConfigureAwait (false);
102+
await ProcessUtils.StartProcess (psi, stdout, null, cancellationToken).ConfigureAwait (false);
81103

82104
var avds = new List<string> ();
83105
foreach (var line in stdout.ToString ().Split ('\n')) {
84106
var trimmed = line.Trim ();
85107
if (!string.IsNullOrEmpty (trimmed))
86108
avds.Add (trimmed);
87109
}
110+
88111
return avds;
89112
}
90113
}

0 commit comments

Comments
 (0)