Skip to content

Commit 45ff1d8

Browse files
committed
Add --adb switch for android state command
1 parent abe8931 commit 45ff1d8

5 files changed

Lines changed: 58 additions & 18 deletions

File tree

src/Microsoft.DotNet.XHarness.Android/AdbRunner.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class AdbRunner
3535

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

38+
public string AdbExePath => _absoluteAdbExePath;
39+
3840
public AdbRunner(ILogger log, string adbExePath = "") : this(log, new AdbProcessManager(log), adbExePath) { }
3941

4042
public AdbRunner(ILogger log, IAdbProcessManager processManager, string adbExePath = "")
@@ -51,17 +53,20 @@ public AdbRunner(ILogger log, IAdbProcessManager processManager, string adbExePa
5153
_log.LogDebug($"Using {AdbEnvironmentVariableName} environment variable ({environmentPath}) for ADB path.");
5254
adbExePath = environmentPath;
5355
}
56+
5457
if (string.IsNullOrEmpty(adbExePath))
5558
{
5659
adbExePath = GetCliAdbExePath();
5760
}
5861

5962
_absoluteAdbExePath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(adbExePath));
63+
6064
if (!File.Exists(_absoluteAdbExePath))
6165
{
6266
_log.LogError($"Unable to find adb.exe");
6367
throw new FileNotFoundException($"Could not find adb.exe. Either set it in the environment via {AdbEnvironmentVariableName} or call with valid path (provided: '{adbExePath}')", adbExePath);
6468
}
69+
6570
if (!_absoluteAdbExePath.Equals(adbExePath))
6671
{
6772
_log.LogDebug($"ADBRunner using ADB.exe supplied from {adbExePath}");
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
2-
// The .NET Foundation licenses this file to you under the MIT license.
3-
// See the LICENSE file in the project root for more information.
4-
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
8-
namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Android
9-
{
10-
internal class AndroidGetStateCommandArguments : XHarnessCommandArguments
11-
{
12-
protected override IEnumerable<Argument> GetArguments() => Enumerable.Empty<Argument>();
13-
}
14-
}
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Collections.Generic;
6+
7+
namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Android
8+
{
9+
internal class AndroidGetStateCommandArguments : XHarnessCommandArguments
10+
{
11+
public ShowAdbPathArgument ShowAdbPath { get; set; } = new();
12+
13+
protected override IEnumerable<Argument> GetArguments() => new Argument[]
14+
{
15+
ShowAdbPath
16+
};
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Android
6+
{
7+
internal class ShowAdbPathArgument : SwitchArgument
8+
{
9+
public ShowAdbPathArgument() : base("adb|show-adb-path", "Prints ONLY path to the adb executable XHarness is using", false)
10+
{
11+
}
12+
}
13+
}

src/Microsoft.DotNet.XHarness.CLI/Commands/Android/AndroidGetStateCommand.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ internal class AndroidGetStateCommand : GetStateCommand<AndroidGetStateCommandAr
2424
}
2525

2626
protected override Task<ExitCode> InvokeInternal(ILogger logger)
27-
{
27+
{
28+
var runner = new AdbRunner(logger);
29+
30+
if (Arguments.ShowAdbPath)
31+
{
32+
Console.WriteLine(runner.AdbExePath);
33+
return Task.FromResult(ExitCode.SUCCESS);
34+
}
35+
2836
logger.LogInformation("Getting state of ADB and attached Android device(s)");
2937
try
3038
{
31-
var runner = new AdbRunner(logger);
3239
string state = runner.GetAdbState();
3340
if (string.IsNullOrEmpty(state))
3441
{

src/Microsoft.DotNet.XHarness.CLI/Program.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,21 @@ private static bool IsOutputSensitive(string[] args)
9898

9999
switch (args[0])
100100
{
101-
case "ios":
102101
case "apple":
103-
case "android":
104102
return args[1] == "device";
103+
104+
case "android":
105+
if (args[1] == "device")
106+
{
107+
return true;
108+
}
109+
110+
if (args[1] == "state" && args.Contains("--adb"))
111+
{
112+
return true;
113+
}
114+
115+
return false;
105116
}
106117

107118
return false;

0 commit comments

Comments
 (0)