-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathAndroidGetStateCommand.cs
More file actions
56 lines (49 loc) · 2.23 KB
/
AndroidGetStateCommand.cs
File metadata and controls
56 lines (49 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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;
using System.Threading.Tasks;
using Microsoft.DotNet.XHarness.Android;
using Microsoft.DotNet.XHarness.CLI.CommandArguments.Android;
using Microsoft.DotNet.XHarness.Common;
using Microsoft.DotNet.XHarness.Common.CLI;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Microsoft.DotNet.XHarness.CLI.Commands.Android
{
internal class AndroidGetStateCommand : GetStateCommand<AndroidGetStateCommandArguments>
{
protected override string CommandUsage { get; } = "android state";
protected override AndroidGetStateCommandArguments Arguments { get; } = new();
public AndroidGetStateCommand() : base(TargetPlatform.Android, new ServiceCollection())
{
}
protected override Task<ExitCode> InvokeInternal(ILogger logger)
{
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))
{
state = "No device attached";
}
logger.LogInformation($"ADB Version info:{Environment.NewLine}{runner.GetAdbVersion()}");
logger.LogInformation($"ADB State ('device' if physically attached):{Environment.NewLine}{state}");
logger.LogInformation($"List of devices:");
var deviceAndArchList = runner.GetAttachedDevicesWithProperties("architecture");
foreach (string device in deviceAndArchList.Keys)
{
logger.LogInformation($"Device: '{device}' - Architecture: {deviceAndArchList[device]}");
}
return Task.FromResult(ExitCode.SUCCESS);
}
catch (Exception toLog)
{
logger.LogCritical(toLog, $"Error: {toLog.Message}");
return Task.FromResult(ExitCode.GENERAL_FAILURE);
}
}
}
}