@@ -17,27 +17,45 @@ public class EmulatorRunner
1717{
1818readonly 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>
2025public EmulatorRunner ( Func < string ? > getSdkPath )
2126{
2227this . 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>
2533public string ? EmulatorPath {
2634get {
2735var sdkPath = getSdkPath ( ) ;
2836if ( string . IsNullOrEmpty ( sdkPath ) )
2937return null ;
38+
3039var ext = OS . IsWindows ? ".exe" : "" ;
3140var path = Path . Combine ( sdkPath , "emulator" , "emulator" + ext ) ;
41+
3242return 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>
4159public Process StartAvd ( string avdName , bool coldBoot = false , string ? additionalArgs = null )
4260{
4361if ( ! IsAvailable )
@@ -58,12 +76,16 @@ public Process StartAvd (string avdName, bool coldBoot = false, string? addition
5876
5977var process = new Process { StartInfo = psi } ;
6078process . Start ( ) ;
79+
6180return 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>
6789public async Task < List < string > > ListAvdNamesAsync ( CancellationToken cancellationToken = default )
6890{
6991if ( ! IsAvailable )
@@ -77,14 +99,15 @@ public async Task<List<string>> ListAvdNamesAsync (CancellationToken cancellatio
7799CreateNoWindow = 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
82104var avds = new List < string > ( ) ;
83105foreach ( var line in stdout . ToString ( ) . Split ( '\n ' ) ) {
84106var trimmed = line . Trim ( ) ;
85107if ( ! string . IsNullOrEmpty ( trimmed ) )
86108avds . Add ( trimmed ) ;
87109}
110+
88111return avds ;
89112}
90113}
0 commit comments