Skip to content
This repository was archived by the owner on Nov 10, 2020. It is now read-only.
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
1 change: 1 addition & 0 deletions AndroidLib/Classes/AndroidController/Adb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static class Adb
private static object _lock = "U is lawked";
internal const string ADB = "adb";
internal const string ADB_EXE = "adb.exe";
internal const string ADB_VERSION = "1.0.31";

/// <summary>
/// Forms an <see cref="AdbCommand"/> that is passed to <c>Adb.ExecuteAdbCommand()</c>
Expand Down
52 changes: 32 additions & 20 deletions AndroidLib/Classes/AndroidController/AndroidController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public sealed class AndroidController
#region MEMBER VARIABLES
private string resourceDirectory;
private List<string> connectedDevices;
private bool Extract_Resources = false;
#endregion

#region PROPERTIES
Expand Down Expand Up @@ -126,25 +127,24 @@ private AndroidController()
#region PRIVATE METHODS
private void CreateResourceDirectories()
{
if (!ResourceFolderManager.Register(ANDROID_CONTROLLER_TMP_FOLDER))
if (!Adb.ExecuteAdbCommand(new AdbCommand("version")).Contains(Adb.ADB_VERSION))
{
if (File.Exists(this.resourceDirectory + Adb.ADB_EXE) && Adb.ServerRunning)
{
Adb.KillServer();
Thread.Sleep(1000);
}

Adb.KillServer();
Thread.Sleep(1000);
ResourceFolderManager.Unregister(ANDROID_CONTROLLER_TMP_FOLDER);
Extract_Resources = true;
}

ResourceFolderManager.Register(ANDROID_CONTROLLER_TMP_FOLDER);
}

private void ExtractResources()
{
string[] res = new string[RESOURCES.Count];
RESOURCES.Keys.CopyTo(res, 0);
Extract.Resources(this, this.resourceDirectory, "Resources.AndroidController", res);
if (this.Extract_Resources)
{
string[] res = new string[RESOURCES.Count];
RESOURCES.Keys.CopyTo(res, 0);
Extract.Resources(this, this.resourceDirectory, "Resources.AndroidController", res);
}
}
#endregion

Expand All @@ -160,8 +160,6 @@ public void Dispose()
Adb.KillServer();
Thread.Sleep(1000);
}

ResourceFolderManager.Unregister(ANDROID_CONTROLLER_TMP_FOLDER);
AndroidController.instance = null;
}

Expand Down Expand Up @@ -300,19 +298,33 @@ public void UpdateDeviceList()
}
}

private bool _CancelRequest;
public bool CancelWait
{
get { return _CancelRequest; }
set { _CancelRequest = value; }
}

/// <summary>
/// Pauses thread until 1 or more Android devices are connected
/// </summary>
/// <remarks>Do Not Use in Windows Forms applications, as this method pauses the current thread. Works fine in Console Applications</remarks>
public void WaitForDevice()
{
/* Entering an endless loop will exaust CPU.
* Since this method must be called in a child thread in Windows Presentation Foundation (WPF) or Windows Form Apps,
* sleeping thread for 250 miliSecond (1/4 of a second)
* will be more friendly to the CPU. Nontheless checking 4 times for a connected device in each second is more than enough,
* and will not result in late response from the app if a device gets connected.
*/
while (!this.HasConnectedDevices) { Thread.Sleep(250); }
/* Entering an endless loop will exhaust CPU.
* Since this method must be called in a child thread in Windows Presentation Foundation (WPF) or Windows Form Apps,
* sleeping thread for 250 miliSecond (1/4 of a second)
* will be more friendly to the CPU. Nonetheless checking 4 times for a connected device in each second is more than enough,
* and will not result in late response from the app if a device gets connected.
*/
while (!this.HasConnectedDevices)
{
if (this.CancelWait)
{
break;
}
Thread.Sleep(250);
}
}
#endregion
}
Expand Down
Binary file modified AndroidLib/Resources/AAPT/aapt.exe
Binary file not shown.
Binary file modified AndroidLib/Resources/AndroidController/adb.exe
Binary file not shown.
Binary file modified AndroidLib/Resources/AndroidController/fastboot.exe
Binary file not shown.