我正在开发一款使用AndroidLib.dll的HTC One Max Utility。
AndroidLib Git Hub位置:https://github.com/regaw-leinad/AndroidLib
下面的类是我的代码用来执行adb shell root命令的。
public static void ExecuteAdbShellCommandInputString(Device device, params string[] inputLines)
{
lock (_lock)
{
Command.RunProcessWriteInput(AndroidController.Instance.ResourceDirectory + ADB_EXE, "shell", inputLines);
}
}
internal static void RunProcessWriteInput(string executable, string arguments, params string[] input)
{
using (Process p = new Process())
{
p.StartInfo.FileName = executable;
p.StartInfo.Arguments = arguments;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.Start();
using (StreamWriter w = p.StandardInput)
for (int i = 0; i < input.Length; i++)
w.WriteLine(input[i]);
p.WaitForExit();
}
}
我在下面的代码中的命令执行但从不退出,我的表单程序锁定。
private void unlockboot_Click(object sender, EventArgs e)
{
button1.Enabled = false; // to prevent user from spamming the unlock button
button2.Enabled = false;
string serial;
// Setting up the Android ADB Daemon and getting the device serial.
android = AndroidController.Instance;
serial = android.ConnectedDevices[0];
device = android.GetConnectedDevice(serial);
// Send message to Console Output RichTextBox and executing commands.
richTextBox1.Clear();
richTextBox1.Text = "Begin Bootloader Flag Unlock Process.\n";
Adb.ExecuteAdbShellCommandInputString(device, "su", @"echo -ne 'HTCU' | dd of=/dev/block/mmcblk0p3 bs=1 seek=33796", "exit", "exit");
richTextBox1.Text += "Completed... Exiting ADB Root.\n";
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
// Killing the ADB Daemon and closing out resources.
android.Dispose();
richTextBox1.Text += "Your Bootloader has been Unlocked.\n";
richTextBox1.ScrollToCaret();
}
这让我感到难过,我添加了exit命令退出Shell中的Root,另一个退出adb shell。
感谢您的帮助。
答案 0 :(得分:0)
通过实施超时,我能够解决此问题。 WaitForExit(1000)