-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop SharpAdbClient as it's not working with last scrcpy release
- Loading branch information
Showing
11 changed files
with
385 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace DeviceManager | ||
{ | ||
public class AdbManager | ||
{ | ||
private readonly string scrScpPath; | ||
private readonly string adb; | ||
public AdbManager(string scrScpPath) | ||
{ | ||
this.scrScpPath = scrScpPath; | ||
adb = Path.Combine(this.scrScpPath, "adb.exe"); | ||
} | ||
|
||
public List<DeviceData> GetDevices() | ||
{ | ||
var result = ConsoleExeRunner.Execute(adb, "devices"); | ||
|
||
bool skipping = true; | ||
var deviceSerials = new List<string>(); | ||
foreach (var line in result) | ||
{ | ||
if (line.StartsWith("List of devices")) | ||
{ | ||
skipping = false; | ||
continue; | ||
} | ||
|
||
if(skipping) continue; | ||
|
||
if(string.IsNullOrWhiteSpace(line)) continue; | ||
|
||
deviceSerials.Add(line.Split('\t')[0]); | ||
} | ||
|
||
var devices = new List<DeviceData>(); | ||
foreach (var serial in deviceSerials) | ||
{ | ||
var data = GetDeviceData(serial); | ||
|
||
devices.Add(data); | ||
} | ||
|
||
return devices; | ||
} | ||
|
||
public DeviceData GetDeviceData(string serial) | ||
{ | ||
var result = ConsoleExeRunner.Execute(adb, $"-s {serial} shell getprop"); | ||
|
||
/* | ||
* | ||
*[ro.product.model]: [Nexus 9] | ||
[ro.product.name]: [volantis] | ||
* | ||
*/ | ||
var deviceData = new DeviceData | ||
{ | ||
Serial = serial, | ||
State = DeviceState.Offline | ||
|
||
}; | ||
|
||
bool TryParse(string line, out (string key, string value) res) | ||
{ | ||
var match = Regex.Match(line, @"\[(?<key>.*)\]: \[(?<value>.*)\]"); | ||
if (match.Success) | ||
{ | ||
res = (match.Groups["key"].Value, match.Groups["value"].Value); | ||
return true; | ||
} | ||
|
||
res = (String.Empty, String.Empty); | ||
return false; | ||
} | ||
|
||
foreach (var line in result) | ||
{ | ||
if (TryParse(line, out var kv)) | ||
{ | ||
deviceData.State = DeviceState.Online; | ||
if (kv.key == "ro.product.model") { deviceData.Model = kv.value; } | ||
if (kv.key == "ro.product.name") { deviceData.Name = kv.value; } | ||
} | ||
} | ||
|
||
return deviceData; | ||
} | ||
|
||
public void Reboot(DeviceData device) | ||
{ | ||
ConsoleExeRunner.Execute(adb, $"-s {device.Serial} reboot"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace DeviceManager | ||
{ | ||
public class ConsoleExeRunner | ||
{ | ||
public static string[] Execute(string cmd, string args) | ||
{ | ||
var info = new ProcessStartInfo | ||
{ | ||
FileName = cmd, | ||
Arguments = args, | ||
CreateNoWindow = true, | ||
WindowStyle = ProcessWindowStyle.Hidden, | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false | ||
}; | ||
var p = Process.Start(info); | ||
var result = ReadLines(p.StandardOutput).ToArray(); | ||
p.WaitForExit(5000); | ||
|
||
return result; | ||
} | ||
|
||
public static IEnumerable<string> ReadLines(StreamReader reader) | ||
{ | ||
string line; | ||
while ((line = reader.ReadLine()) != null) | ||
{ | ||
yield return line; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace DeviceManager | ||
{ | ||
public class DeviceData | ||
{ | ||
public string Serial { get; set; } | ||
public string Name { get; set; } | ||
public string Model { get; set; } | ||
public DeviceState State { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<PublishUrlHistory>publish\</PublishUrlHistory> | ||
<InstallUrlHistory /> | ||
<SupportUrlHistory /> | ||
<UpdateUrlHistory /> | ||
<BootstrapperUrlHistory /> | ||
<ErrorReportUrlHistory /> | ||
<FallbackCulture>en-US</FallbackCulture> | ||
<VerifyUploadedFiles>false</VerifyUploadedFiles> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace DeviceManager | ||
{ | ||
public enum DeviceState | ||
{ | ||
Offline, Online | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<Weavers> | ||
<Costura> | ||
</Costura> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<Costura></Costura> | ||
</Weavers> |
Oops, something went wrong.