Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.XHarness.Android/AdbRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class AdbRunner

public int APIVersion => _api ?? GetAPIVersion();

public string AdbExePath => _absoluteAdbExePath;

public AdbRunner(ILogger log, string adbExePath = "") : this(log, new AdbProcessManager(log), adbExePath) { }

public AdbRunner(ILogger log, IAdbProcessManager processManager, string adbExePath = "")
Expand All @@ -51,17 +53,20 @@ public AdbRunner(ILogger log, IAdbProcessManager processManager, string adbExePa
_log.LogDebug($"Using {AdbEnvironmentVariableName} environment variable ({environmentPath}) for ADB path.");
adbExePath = environmentPath;
}

if (string.IsNullOrEmpty(adbExePath))
{
adbExePath = GetCliAdbExePath();
}

_absoluteAdbExePath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(adbExePath));

if (!File.Exists(_absoluteAdbExePath))
{
_log.LogError($"Unable to find adb.exe");
throw new FileNotFoundException($"Could not find adb.exe. Either set it in the environment via {AdbEnvironmentVariableName} or call with valid path (provided: '{adbExePath}')", adbExePath);
}

if (!_absoluteAdbExePath.Equals(adbExePath))
{
_log.LogDebug($"ADBRunner using ADB.exe supplied from {adbExePath}");
Comment thread
premun marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Linq;

namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Android
{
internal class AndroidGetStateCommandArguments : XHarnessCommandArguments
{
protected override IEnumerable<Argument> GetArguments() => Enumerable.Empty<Argument>();
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;

namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Android
{
internal class AndroidGetStateCommandArguments : XHarnessCommandArguments
{
public ShowAdbPathArgument ShowAdbPath { get; set; } = new();

protected override IEnumerable<Argument> GetArguments() => new Argument[]
{
ShowAdbPath
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Android
{
internal class ShowAdbPathArgument : SwitchArgument
{
public ShowAdbPathArgument() : base("adb|show-adb-path", "Prints ONLY path to the adb executable XHarness is using", false)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ internal class AndroidGetStateCommand : GetStateCommand<AndroidGetStateCommandAr
}

protected override Task<ExitCode> InvokeInternal(ILogger logger)
{
{
var runner = new AdbRunner(logger);

if (Arguments.ShowAdbPath)
{
Console.WriteLine(runner.AdbExePath);
return Task.FromResult(ExitCode.SUCCESS);
}

logger.LogInformation("Getting state of ADB and attached Android device(s)");
try
{
var runner = new AdbRunner(logger);
string state = runner.GetAdbState();
if (string.IsNullOrEmpty(state))
{
Expand Down
15 changes: 13 additions & 2 deletions src/Microsoft.DotNet.XHarness.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,21 @@ private static bool IsOutputSensitive(string[] args)

switch (args[0])
{
case "ios":
case "apple":
case "android":
return args[1] == "device";

case "android":
if (args[1] == "device")
{
return true;
}

if (args[1] == "state" && args.Contains("--adb"))
{
return true;
}

return false;
}

return false;
Expand Down