Skip to content

Commit 9d4b4f5

Browse files
rmarinhoCopilot
andcommitted
Add optional logger callback to BuildDeviceDescription and MergeDevicesAndEmulators
Accepts Action<TraceLevel, string> to route debug messages through the caller's logging infrastructure (e.g., MSBuild TaskLoggingHelper). Restores log messages lost when logic moved from dotnet/android to android-tools: AVD name formatting, running emulator detection, and non-running emulator additions. Follows the existing CreateTaskLogger pattern used by JdkInstaller. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 01ed6b9 commit 9d4b4f5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,14 @@ public static AdbDeviceStatus MapAdbStateToStatus (string adbState)
259259
/// Priority: AVD name (for emulators) > model > product > device > serial.
260260
/// Ported from dotnet/android GetAvailableAndroidDevices.BuildDeviceDescription.
261261
/// </summary>
262-
public static string BuildDeviceDescription (AdbDeviceInfo device)
262+
public static string BuildDeviceDescription (AdbDeviceInfo device, Action<TraceLevel, string>? logger = null)
263263
{
264-
if (device.Type == AdbDeviceType.Emulator && !string.IsNullOrEmpty (device.AvdName))
265-
return FormatDisplayName (device.AvdName!);
264+
if (device.Type == AdbDeviceType.Emulator && !string.IsNullOrEmpty (device.AvdName)) {
265+
logger?.Invoke (TraceLevel.Verbose, $"Emulator {device.Serial}, original AVD name: {device.AvdName}");
266+
var formatted = FormatDisplayName (device.AvdName!);
267+
logger?.Invoke (TraceLevel.Verbose, $"Emulator {device.Serial}, formatted AVD display name: {formatted}");
268+
return formatted;
269+
}
266270

267271
if (!string.IsNullOrEmpty (device.Model))
268272
return device.Model!.Replace ('_', ' ');
@@ -299,7 +303,7 @@ public static string FormatDisplayName (string avdName)
299303
/// Running emulators are not duplicated. Non-running emulators are added with Status=NotRunning.
300304
/// Ported from dotnet/android GetAvailableAndroidDevices.MergeDevicesAndEmulators.
301305
/// </summary>
302-
public static List<AdbDeviceInfo> MergeDevicesAndEmulators (IReadOnlyList<AdbDeviceInfo> adbDevices, IReadOnlyList<string> availableEmulators)
306+
public static List<AdbDeviceInfo> MergeDevicesAndEmulators (IReadOnlyList<AdbDeviceInfo> adbDevices, IReadOnlyList<string> availableEmulators, Action<TraceLevel, string>? logger = null)
303307
{
304308
var result = new List<AdbDeviceInfo> (adbDevices);
305309

@@ -310,10 +314,14 @@ public static List<AdbDeviceInfo> MergeDevicesAndEmulators (IReadOnlyList<AdbDev
310314
runningAvdNames.Add (device.AvdName!);
311315
}
312316

317+
logger?.Invoke (TraceLevel.Verbose, $"Running emulators AVD names: {string.Join (", ", runningAvdNames)}");
318+
313319
// Add non-running emulators
314320
foreach (var avdName in availableEmulators) {
315-
if (runningAvdNames.Contains (avdName))
321+
if (runningAvdNames.Contains (avdName)) {
322+
logger?.Invoke (TraceLevel.Verbose, $"Emulator '{avdName}' is already running, skipping");
316323
continue;
324+
}
317325

318326
var displayName = FormatDisplayName (avdName);
319327
result.Add (new AdbDeviceInfo {
@@ -323,6 +331,7 @@ public static List<AdbDeviceInfo> MergeDevicesAndEmulators (IReadOnlyList<AdbDev
323331
Status = AdbDeviceStatus.NotRunning,
324332
AvdName = avdName,
325333
});
334+
logger?.Invoke (TraceLevel.Verbose, $"Added non-running emulator: {avdName}");
326335
}
327336

328337
// Sort: online devices first, then not-running emulators, alphabetically by description

0 commit comments

Comments
 (0)