-
Notifications
You must be signed in to change notification settings - Fork 36
EmulatorRunner.LaunchEmulator: return EmulatorLaunchResult with serial, ports, and log path #340
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,62 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Xamarin.Android.Tools; | ||
|
|
||
| /// <summary> | ||
| /// Returned by <see cref="EmulatorRunner.LaunchEmulator"/> with enriched launch information. | ||
| /// </summary> | ||
| public sealed class EmulatorLaunchResult | ||
| { | ||
| public EmulatorLaunchResult (Process process, string logPath) | ||
| { | ||
| if (process is null) | ||
| throw new System.ArgumentNullException (nameof (process)); | ||
| if (logPath is null) | ||
| throw new System.ArgumentNullException (nameof (logPath)); | ||
| Process = process; | ||
| LogPath = logPath; | ||
| } | ||
|
rmarinho marked this conversation as resolved.
|
||
|
|
||
| /// <summary>The running emulator process.</summary> | ||
| public Process Process { get; } | ||
|
|
||
| /// <summary>The OS process ID of the emulator process.</summary> | ||
| public int Pid => Process.Id; | ||
|
|
||
| /// <summary> | ||
| /// The emulator console port (e.g., 5554). Populated either from the pre-assigned | ||
| /// <c>-ports</c> argument or once <see cref="PortsResolvedAsync"/> completes. | ||
| /// </summary> | ||
| public int? ConsolePort { get; internal set; } | ||
|
|
||
| /// <summary> | ||
| /// The emulator ADB port (e.g., 5555). Populated either from the pre-assigned | ||
| /// <c>-ports</c> argument or once <see cref="PortsResolvedAsync"/> completes. | ||
| /// </summary> | ||
| public int? AdbPort { get; internal set; } | ||
|
Comment on lines
+34
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 💡 Code organization — Per repo convention, consider adding a /// <remarks>
/// <see cref="ConsolePort"/> and <see cref="AdbPort"/> are written by process
/// output callbacks and should only be read after <see cref="PortsResolvedAsync"/> completes.
/// </remarks>This makes the ordering contract explicit for future callers. Rule: Document thread-safety invariants |
||
|
|
||
| /// <summary> | ||
| /// The ADB serial for this emulator (e.g., <c>emulator-5554</c>), derived from <see cref="ConsolePort"/>. | ||
| /// Returns <c>null</c> until <see cref="ConsolePort"/> is populated. | ||
| /// </summary> | ||
| public string? Serial => ConsolePort is int p ? $"emulator-{p}" : null; | ||
|
|
||
| /// <summary> | ||
| /// The path to the emulator log file. Resolved at launch time from the <c>-logfile</c> | ||
| /// argument (if specified) or from the <c>ANDROID_AVD_HOME</c> / <c>ANDROID_USER_HOME</c> | ||
| /// environment variables, falling back to the AOSP default | ||
| /// (<c>~/.android/avd/<name>.avd/emulator.log</c>). | ||
| /// </summary> | ||
| public string LogPath { get; } | ||
|
|
||
| /// <summary> | ||
| /// A <see cref="Task"/> that completes when the emulator has reported its console and ADB | ||
| /// port assignments via stdout/stderr. If ports were pre-assigned via <c>-ports</c>, this | ||
| /// task is already completed. | ||
| /// </summary> | ||
| internal Task PortsResolvedAsync { get; set; } = Task.CompletedTask; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,7 +176,16 @@ Xamarin.Android.Tools.EmulatorRunner | |
| Xamarin.Android.Tools.EmulatorRunner.BootEmulatorAsync(string! deviceOrAvdName, Xamarin.Android.Tools.AdbRunner! adbRunner, Xamarin.Android.Tools.EmulatorBootOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Xamarin.Android.Tools.EmulatorBootResult!>! | ||
| Xamarin.Android.Tools.EmulatorRunner.EmulatorRunner(string! emulatorPath, System.Collections.Generic.IDictionary<string!, string!>? environmentVariables = null, System.Action<System.Diagnostics.TraceLevel, string!>? logger = null) -> void | ||
| Xamarin.Android.Tools.EmulatorRunner.ListAvdNamesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<string!>!>! | ||
| Xamarin.Android.Tools.EmulatorRunner.LaunchEmulator(string! avdName, bool coldBoot = false, System.Collections.Generic.List<string!>? additionalArgs = null) -> System.Diagnostics.Process! | ||
| Xamarin.Android.Tools.EmulatorRunner.LaunchEmulator(string! avdName, bool coldBoot = false, int? consolePort = null, int? adbPort = null, string? logFile = null, System.Collections.Generic.List<string!>? additionalArgs = null) -> Xamarin.Android.Tools.EmulatorLaunchResult! | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a breaking API change, can we leave the existing method and just add new one? |
||
| Xamarin.Android.Tools.EmulatorRunner.LaunchEmulatorAsync(string! avdName, bool coldBoot = false, int? consolePort = null, int? adbPort = null, string? logFile = null, System.Collections.Generic.List<string!>? additionalArgs = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Xamarin.Android.Tools.EmulatorLaunchResult!>! | ||
| Xamarin.Android.Tools.EmulatorLaunchResult | ||
| Xamarin.Android.Tools.EmulatorLaunchResult.EmulatorLaunchResult(System.Diagnostics.Process! process, string! logPath) -> void | ||
| Xamarin.Android.Tools.EmulatorLaunchResult.AdbPort.get -> int? | ||
| Xamarin.Android.Tools.EmulatorLaunchResult.ConsolePort.get -> int? | ||
| Xamarin.Android.Tools.EmulatorLaunchResult.LogPath.get -> string! | ||
| Xamarin.Android.Tools.EmulatorLaunchResult.Pid.get -> int | ||
| Xamarin.Android.Tools.EmulatorLaunchResult.Process.get -> System.Diagnostics.Process! | ||
| Xamarin.Android.Tools.EmulatorLaunchResult.Serial.get -> string? | ||
| Xamarin.Android.Tools.AdbPortRule | ||
| Xamarin.Android.Tools.AdbPortRule.AdbPortRule(Xamarin.Android.Tools.AdbPortSpec! Remote, Xamarin.Android.Tools.AdbPortSpec! Local) -> void | ||
| Xamarin.Android.Tools.AdbPortRule.Local.get -> Xamarin.Android.Tools.AdbPortSpec! | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.