Skip to content

Commit 3cd0623

Browse files
author
regaw-leinad
committed
Add missing timeouts. Update doc
1 parent 1b460b5 commit 3cd0623

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

AndroidLib/Classes/AndroidController/Adb.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Adb.cs - Developed by Dan Wager for AndroidLib.dll
33
*/
44

5+
using System;
56
using System.IO;
67

78
namespace RegawMOD.Android
@@ -137,6 +138,7 @@ public static AdbCommand FormAdbShellCommand(Device device, bool rootShell, stri
137138
/// <remarks>Added specifically for RegawMOD CDMA Hero Rooter. Always remember to pass "exit" as the last command or it will not return!</remarks>
138139
/// <param name="device">Specific <see cref="Device"/> to run the command on</param>
139140
/// <param name="inputLines">Lines of commands to send to shell</param>
141+
[Obsolete("Method is deprecated, please use ExecuteAdbShellCommandInputString(Device, int, string...) instead.")]
140142
public static void ExecuteAdbShellCommandInputString(Device device, params string[] inputLines)
141143
{
142144
lock (_lock)
@@ -145,6 +147,21 @@ public static void ExecuteAdbShellCommandInputString(Device device, params strin
145147
}
146148
}
147149

150+
/// <summary>
151+
/// Opens Adb Shell and allows input to be typed directly to the shell. Experimental!
152+
/// </summary>
153+
/// <remarks>Added specifically for RegawMOD CDMA Hero Rooter. Always remember to pass "exit" as the last command or it will not return!</remarks>
154+
/// <param name="device">Specific <see cref="Device"/> to run the command on</param>
155+
/// <param name="timeout">The timeout in milliseonds</param>
156+
/// <param name="inputLines">Lines of commands to send to shell</param>
157+
public static void ExecuteAdbShellCommandInputString(Device device, int timeout, params string[] inputLines)
158+
{
159+
lock (_lock)
160+
{
161+
Command.RunProcessWriteInput(AndroidController.Instance.ResourceDirectory + ADB_EXE, "shell", timeout, inputLines);
162+
}
163+
}
164+
148165
/// <summary>
149166
/// Executes an <see cref="AdbCommand"/> on the running Adb Server
150167
/// </summary>

AndroidLib/Classes/AndroidController/Device.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private void RebootBootloaderThread()
201201
/// </summary>
202202
/// <param name="fileOnDevice">Path to file to pull from device</param>
203203
/// <param name="destinationDirectory">Directory on local computer to pull file to</param>
204-
/// /// <param name="timeout">The timeout for this operation (Default = -1)</param>
204+
/// /// <param name="timeout">The timeout for this operation in milliseconds (Default = -1)</param>
205205
/// <returns>True if file is pulled, false if pull failed</returns>
206206
public bool PullFile(string fileOnDevice, string destinationDirectory, int timeout = Command.DEFAULT_TIMEOUT)
207207
{
@@ -214,7 +214,7 @@ public bool PullFile(string fileOnDevice, string destinationDirectory, int timeo
214214
/// </summary>
215215
/// <param name="filePath">The path to the file on the computer you want to push</param>
216216
/// <param name="destinationFilePath">The desired full path of the file after pushing to the device (including file name and extension)</param>
217-
/// <param name="timeout">The timeout for this operation (Default = -1)</param>
217+
/// <param name="timeout">The timeout for this operation in milliseconds (Default = -1)</param>
218218
/// <returns>If the push was successful</returns>
219219
public bool PushFile(string filePath, string destinationFilePath, int timeout = Command.DEFAULT_TIMEOUT)
220220
{
@@ -227,6 +227,7 @@ public bool PushFile(string filePath, string destinationFilePath, int timeout =
227227
/// </summary>
228228
/// <param name="location">Path to folder to pull from device</param>
229229
/// <param name="destination">Directory on local computer to pull file to</param>
230+
/// <param name="timeout">The timeout for this operation in milliseconds (Default = -1)</param>
230231
/// <returns>True if directory is pulled, false if pull failed</returns>
231232
public bool PullDirectory(string location, string destination, int timeout = Command.DEFAULT_TIMEOUT)
232233
{
@@ -238,6 +239,7 @@ public bool PullDirectory(string location, string destination, int timeout = Com
238239
/// Installs an application from the local computer to the Android device
239240
/// </summary>
240241
/// <param name="location">Full path of apk on computer</param>
242+
/// <param name="timeout">The timeout for this operation in milliseconds (Default = -1)</param>
241243
/// <returns>True if install is successful, False if install fails for any reason</returns>
242244
public bool InstallApk(string location, int timeout = Command.DEFAULT_TIMEOUT)
243245
{

AndroidLib/Classes/Util/Command.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ internal static int RunProcessReturnExitCode(string executable, string arguments
217217
return exitCode;
218218
}
219219

220-
// TODO: Change to timeout implementation
220+
[Obsolete("Method is deprecated, please use RunProcessWriteInput(string, string, int, string...) instead.")]
221221
internal static void RunProcessWriteInput(string executable, string arguments, params string[] input)
222222
{
223223
using (Process p = new Process())
@@ -240,6 +240,28 @@ internal static void RunProcessWriteInput(string executable, string arguments, p
240240
}
241241
}
242242

243+
internal static void RunProcessWriteInput(string executable, string arguments, int timeout, params string[] input)
244+
{
245+
using (Process p = new Process())
246+
{
247+
p.StartInfo.FileName = executable;
248+
p.StartInfo.Arguments = arguments;
249+
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
250+
p.StartInfo.CreateNoWindow = true;
251+
p.StartInfo.UseShellExecute = false;
252+
253+
p.StartInfo.RedirectStandardInput = true;
254+
255+
p.Start();
256+
257+
using (StreamWriter w = p.StandardInput)
258+
for (int i = 0; i < input.Length; i++)
259+
w.WriteLine(input[i]);
260+
261+
p.WaitForExit(timeout);
262+
}
263+
}
264+
243265
internal static bool IsProcessRunning(string processName)
244266
{
245267
Process[] processes = Process.GetProcesses();

0 commit comments

Comments
 (0)