public void KillDevice(Device device)
 {
     StringBuilder args = new StringBuilder();
     if (device != null)
     {
         args.AppendFormat("-s {0} ", device.FullName());
     }
     args.AppendFormat("emu kill");
     _adbProcess.Start(args.ToString());
 }
        public string QueryProperty(Device device, string propertyName)
        {
            StringBuilder args = new StringBuilder();
            if (device != null)
            {
                args.AppendFormat("-s {0} ", device.FullName());
            }
            args.AppendFormat("shell getprop {0}", propertyName);

            StringBuilder output = new StringBuilder();
            _adbProcess.Start(args.ToString());

            _adbProcess.ListenToStandardOut((outMessage) =>
            {
                output.AppendLine(outMessage);
            });

            _adbProcess.WaitForExit();
            return output.ToString().Trim();
        }
        public void Install(Device device, string apkFilePath, AdbInstallFlags installFlags = AdbInstallFlags.None)
        {
            StringBuilder args = new StringBuilder();
            if (device != null)
            {
                args.AppendFormat("-s {0} ", device.FullName());
            }
            args.Append("install ");

            if (installFlags != AdbInstallFlags.None)
            {
                var enums = Enum.GetValues(typeof(AdbInstallFlags));
                foreach (var installFlag in enums)
                {
                    // get description attribute
                    Enum flag = (AdbInstallFlags)installFlag;
                    if ((AdbInstallFlags)flag == AdbInstallFlags.None)
                    {
                        continue;
                    }
                    if (installFlags.HasFlag(flag))
                    {
                        string enumDesc = GetEnumDescription(flag);
                        args.AppendFormat("{0} ", enumDesc);
                    }
                }
            }

            if (!Path.IsPathRooted(apkFilePath))
            {
                var currentDir = Environment.CurrentDirectory;
                var apkPath = System.IO.Path.Combine(currentDir, apkFilePath);
            }

            args.AppendFormat("\"{0}\"", apkFilePath);

            StringBuilder output = new StringBuilder();
            _adbProcess.Start(args.ToString());

            _adbProcess.ListenToStandardOut((outMessage) =>
            {
                output.AppendLine(outMessage);
            });

            _adbProcess.WaitForExit();

            if (!string.IsNullOrWhiteSpace(output.ToString()))
            {
                if (output.ToString().Contains("Success"))
                {
                    return;
                }
            }

            throw new Exception(string.Format("Unable to install APK file: {0}. Message: {1}", apkFilePath, output.ToString()));
        }
        public string ReadFileContents(Device device, string path)
        {
            StringBuilder args = new StringBuilder();
            if (device != null)
            {
                args.AppendFormat("-s {0} ", device.FullName());
            }
            args.AppendFormat("shell cat {0}", path);

            StringBuilder output = new StringBuilder();
            _adbProcess.Start(args.ToString());

            _adbProcess.ListenToStandardOut((outMessage) =>
            {
                output.AppendLine(outMessage);
            });

            _adbProcess.WaitForExit();
            return output.ToString();
        }
        public string StartInstrument(Device device, string packageName, string runnerClass, Action<string> onStdOut)
        {
            //   &quot;$(AndroidDebugBridgeExePath) & quot; shell am instrument - w $(AndroidTestsManifestPackageName) /$(AndroidTestsInstrumentationClassPath)
            StringBuilder args = new StringBuilder();
            if (device != null)
            {
                args.AppendFormat("-s {0} ", device.FullName());
            }
            args.Append("shell am instrument -w ");
            //if (waitForFinish)
            //{
            //    args.Append("-w ");
            //}

            args.AppendFormat("{0}/{1}", packageName, runnerClass);

            StringBuilder output = new StringBuilder();
            _adbProcess.Start(args.ToString());

            _adbProcess.ListenToStandardOut((outMessage) =>
            {
                output.AppendLine(outMessage);
                onStdOut(outMessage);
            });

            _adbProcess.WaitForExit();

            return output.ToString();

        }