Skip to content

Commit

Permalink
又编写了大量注释
Browse files Browse the repository at this point in the history
Former-commit-id: cf345369fb22c9749efbbdcb243ffac9aa0e9a3a
  • Loading branch information
zsh2401 committed Mar 1, 2018
1 parent cfa7e22 commit 2408368
Show file tree
Hide file tree
Showing 27 changed files with 197 additions and 454 deletions.
4 changes: 2 additions & 2 deletions AutumnBox.Basic/ACP/AndroidClientController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static class AndroidClientController
private const string BROADCAST_STOP_ACP_SERVICE =
"top.atmb.autumnbox.COMMAND_STOP_ACP_SERVICE";
public static bool IsInstallAutumnBoxApp(DeviceSerial serial) {
return PackageHelper.IsInstall(serial, PACKAGE_NAME) == true;
return PackageManager.IsInstall(serial, PACKAGE_NAME) == true;
}
public static AdvanceOutput StartMainActivity(DeviceSerial device)
{
Expand All @@ -34,7 +34,7 @@ public static AdvanceOutput StartMainActivity(DeviceSerial device)
public static AdvanceOutput AwakeAcpService(DeviceSerial device) {
CheckInstallApp(device);
StartMainActivity(device);
return Service.RunService(device, PACKAGE_NAME,SERVICE_NAME);
return Service.StartService(device, PACKAGE_NAME,SERVICE_NAME);
}
public static AdvanceOutput StopAcpService(DeviceSerial device) {
return Broadcast.Send(device,BROADCAST_STOP_ACP_SERVICE);
Expand Down
1 change: 0 additions & 1 deletion AutumnBox.Basic/AutumnBox.Basic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
<Compile Include="Device\ActivityManager\ActivityManagerShared.cs" />
<Compile Include="Device\ActivityManager\Broadcast.cs" />
<Compile Include="Device\ActivityManager\Service.cs" />
<Compile Include="Device\PackageManage\PackageBasicInfo.cs" />
<Compile Include="Device\PackageManage\PackageManager.cs" />
<Compile Include="Device\PackageManage\UserManager.cs" />
<Compile Include="Executer\AdvanceOutput.cs" />
Expand Down
2 changes: 1 addition & 1 deletion AutumnBox.Basic/Device/ActivityManager/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class Service
/// <param name="pkgName">包名</param>
/// <param name="className">服务类名</param>
/// <returns></returns>
public static AdvanceOutput RunService(DeviceSerial device,
public static AdvanceOutput StartService(DeviceSerial device,
string pkgName,
string className) {
return ActivityManagerShared.Executer.QuicklyShell(device,$"am startservice {pkgName}/.{className}");
Expand Down
3 changes: 3 additions & 0 deletions AutumnBox.Basic/Device/BuildPropKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*********************************************************************************/
namespace AutumnBox.Basic.Device
{
/// <summary>
/// build.prop中常用的key
/// </summary>
public static class BuildPropKeys
{
public const string Board = "ro.product.board";
Expand Down
27 changes: 21 additions & 6 deletions AutumnBox.Basic/Device/DeviceBasicInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
namespace AutumnBox.Basic.Device
{

/// <summary>
/// 简单的仅包含设备id和设备状态的结构体,主要用于设备列表 DevicesList
/// </summary>
/// <summary>
/// 简单的仅包含设备id和设备状态的结构体,主要用于设备列表 DevicesList
/// </summary>
public struct DeviceBasicInfo : IEquatable<DeviceBasicInfo>
{
/// <summary>
Expand Down Expand Up @@ -52,16 +52,30 @@ public override string ToString()
{
return $"{Serial.ToString()} {State}";
}

/// <summary>
/// 比较是否相等
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator ==(DeviceBasicInfo left, DeviceBasicInfo right)
{
return left.Equals(right);
}
/// <summary>
/// 比较是否不等
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator !=(DeviceBasicInfo left, DeviceBasicInfo right)
{
return !left.Equals(right);
}

/// <summary>
/// 隐式转换为string
/// </summary>
/// <param name="info"></param>
public static implicit operator string(DeviceBasicInfo info)
{
return info.ToString();
Expand Down Expand Up @@ -97,7 +111,8 @@ public bool Equals(DeviceBasicInfo other)
/// <returns></returns>
public override bool Equals(object obj)
{
if (obj is DeviceBasicInfo) {
if (obj is DeviceBasicInfo)
{
return Equals((DeviceBasicInfo)obj);
}
return base.Equals(obj);
Expand Down
8 changes: 8 additions & 0 deletions AutumnBox.Basic/Device/DeviceHardwareInfoGetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ static DeviceHardwareInfoGetter()
executer = new CommandExecuter();
}
private readonly DeviceSerial serial;
/// <summary>
/// 构造
/// </summary>
/// <param name="deviceSerial"></param>
public DeviceHardwareInfoGetter(DeviceSerial deviceSerial)
{
this.serial = deviceSerial;
}
/// <summary>
/// 获取信息
/// </summary>
/// <returns></returns>
public DeviceHardwareInfo Get()
{
DeviceHardwareInfo result = new DeviceHardwareInfo
Expand Down
12 changes: 11 additions & 1 deletion AutumnBox.Basic/Device/DeviceHaveNoRootException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ namespace AutumnBox.Basic.Device
/// </summary>
public class DeviceHaveNoRootException : Exception
{
/// <summary>
/// 具体的设备
/// </summary>
public DeviceSerial Device { get; private set; }
public DeviceHaveNoRootException() { }
/// <summary>
/// 创建DeviceHaveNoRootException的新实例
/// </summary>
public DeviceHaveNoRootException() {
}
/// <summary>
/// 创建DeviceHaveNoRootException的新实例并说明设备
/// </summary>
public DeviceHaveNoRootException(DeviceSerial dev)
{
this.Device = dev;
Expand Down
3 changes: 3 additions & 0 deletions AutumnBox.Basic/Device/DeviceImageFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace AutumnBox.Basic.Device
public sealed class DeviceImageFinder : IDisposable,ISetableShell
{
private readonly DeviceSerial serial;
/// <summary>
/// 使用的android shell类
/// </summary>
public AndroidShell ShellAsSu
{
private get
Expand Down
8 changes: 8 additions & 0 deletions AutumnBox.Basic/Device/DeviceInfoGetterInFastboot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ public class DeviceInfoGetterInFastboot
{
private readonly CommandExecuter executer;
private readonly DeviceSerial serial;
/// <summary>
/// 创建DeviceInfoGetterInFastboot的新实例
/// </summary>
/// <param name="serial">具体的设备</param>
public DeviceInfoGetterInFastboot(DeviceSerial serial)
{
executer = new CommandExecuter();
this.serial = serial;
}
private const string resultPattern = @".+:\u0020(?<result>.+)";
/// <summary>
/// 获取Product信息
/// </summary>
/// <returns></returns>
public string GetProduct()
{
var text = executer.Execute(Command.MakeForFastboot(serial, "getvar product")).All.ToString();
Expand Down
15 changes: 13 additions & 2 deletions AutumnBox.Basic/Device/DeviceRebooter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@ namespace AutumnBox.Basic.Device
/// </summary>
public enum RebootOptions
{
/// <summary>
/// 重启到系统
/// </summary>
System,
/// <summary>
/// 重启到恢复模式
/// </summary>
Recovery,
/// <summary>
/// 重启到bootloader模式
/// </summary>
Fastboot,
/// <summary>
/// 高通9008模式
/// </summary>
Snapdragon9008,
}
/// <summary>
/// 设备重启器
/// </summary>
public static class DeviceRebooter
{
public delegate void FinishedCallback();
private static CommandExecuter executer;
static DeviceRebooter()
{
Expand All @@ -39,7 +50,7 @@ static DeviceRebooter()
/// <param name="dev"></param>
/// <param name="option"></param>
/// <param name="callback"></param>
public async static void RebootAsync(DeviceBasicInfo dev, RebootOptions option = RebootOptions.System, FinishedCallback callback = null)
public async static void RebootAsync(DeviceBasicInfo dev, RebootOptions option = RebootOptions.System, Action callback = null)
{
await Task.Run(() =>
{
Expand Down
34 changes: 34 additions & 0 deletions AutumnBox.Basic/Device/DeviceSerial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public bool IsIpAdress
}
private IPEndPoint _ip = null;
private string _serialNum = null;
/// <summary>
/// 变回string
/// </summary>
/// <returns></returns>
public override string ToString()
{
return _serialNum ?? _ip.ToString();
Expand All @@ -39,6 +43,10 @@ public override string ToString()
/// </summary>
/// <returns></returns>
public string ToFullSerial() => $"-s {_serialNum ?? _ip.ToString()}";
/// <summary>
/// 创建DeviceSerial的新实例
/// </summary>
/// <param name="serialStr"></param>
public DeviceSerial(string serialStr)
{
var strs = serialStr.Split(':');
Expand All @@ -54,18 +62,40 @@ public DeviceSerial(string serialStr)
}
}

/// <summary>
/// 判断两个serial是否相等
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator ==(DeviceSerial left, DeviceSerial right)
{
return left?.ToString() == right?.ToString();
}
/// <summary>
/// 判断两个serial是否不相等
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator !=(DeviceSerial left, DeviceSerial right)
{
return left?.ToString() != right?.ToString();
}
/// <summary>
/// 进行比较
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool Equals(DeviceSerial other)
{
return this.ToString() == other.ToString();
}
/// <summary>
/// 比较
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
if (obj is DeviceSerial)
Expand All @@ -77,6 +107,10 @@ public override bool Equals(object obj)
return base.Equals(obj);
}
}
/// <summary>
/// 获取哈希码
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return base.GetHashCode();
Expand Down
4 changes: 4 additions & 0 deletions AutumnBox.Basic/Device/DeviceSoftwareInfoGetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ static DeviceSoftwareInfoGetter()
executer = new CommandExecuter();
}
private readonly DeviceSerial serial;
/// <summary>
/// 创建DeviceSoftwareInfoGetter的新实例
/// </summary>
/// <param name="serial"></param>
public DeviceSoftwareInfoGetter(DeviceSerial serial)
{
this.serial = serial;
Expand Down
5 changes: 5 additions & 0 deletions AutumnBox.Basic/Device/DeviceState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ namespace AutumnBox.Basic.Device
{
public static class DeviceStateExt
{
/// <summary>
/// 将字符串解析为DeviceState
/// </summary>
/// <param name="strStatus"></param>
/// <returns></returns>
public static DeviceState ToDeviceState(this string strStatus)
{
switch (strStatus)
Expand Down
24 changes: 0 additions & 24 deletions AutumnBox.Basic/Device/PackageManage/PackageBasicInfo.cs

This file was deleted.

29 changes: 1 addition & 28 deletions AutumnBox.Basic/Device/PackageManage/PackageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,6 @@ namespace AutumnBox.Basic.Device.PackageManage
{
public static class PackageHelper
{
private static readonly string packagesPattern = @"package:(?<package>.+)";
/// <summary>
/// 获取设备上的所有包
/// </summary>
/// <param name="devSerial"></param>
/// <returns></returns>
public static List<PackageInfo> GetPackages(DeviceSerial devSerial)
{
var result = PackageManagerShared.Executer.QuicklyShell(devSerial, $"pm list packages");
var matches = Regex.Matches(result.ToString(), packagesPattern);
List<PackageInfo> packages = new List<PackageInfo>();
foreach (Match m in matches)
{
packages.Add(new PackageInfo(devSerial, m.Result("${package}")));
}
return packages;
}
/// <summary>
/// 检查是否安装了某个APP
/// </summary>
/// <param name="devSerial">设备</param>
/// <param name="packageName">应用名</param>
/// <returns></returns>
public static bool? IsInstall(DeviceSerial devSerial, string packageName)
{
var result = PackageManagerShared.Executer.QuicklyShell(devSerial, $"pm path {packageName}");
return result.IsSuccessful;
}

}
}
Loading

0 comments on commit 2408368

Please sign in to comment.