예제 #1
0
        /// <summary>
        /// Executes a generic ADB command.
        /// </summary>
        /// <param name="device">Optional if there is only one device attached</param>
        /// <param name="command"></param>
        /// <param name="timeoutMilliseconds">Timeout (in milliseconds) before the method to end in any case. If null, there is no timeout.</param>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public ExeResponse Execute(Device device, string command, int?timeoutMilliseconds, params string[] arguments)
        {
            if (String.IsNullOrEmpty(command))
            {
                return(null);
            }
            if (arguments == null)
            {
                arguments = new string[] { }
            }
            ;

            arguments = new[] { command }.Concat(arguments).ToArray();

            return(Exe.Adb(device, timeoutMilliseconds, arguments));
        }
예제 #2
0
파일: Build.cs 프로젝트: elegos/ADTlib
        public void Load(Device device)
        {
            if (PropsList.Count > 0)
            {
                return;
            }

            var raw = Exe.Adb(device, new[] { "shell", "cat /system/build.prop" });

            if (ExeResponse.IsNullOrAbnormalExit(raw))
            {
                return;
            }
            var lines = raw.Output.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            PropsList.Clear();
            foreach (var matches in lines.Select(line => Regex.Match(line, PropRegex, RegexOptions.IgnoreCase)).Where(matches => matches.Success))
            {
                PropsList.Add(matches.Groups["prop"].Value, matches.Groups["value"].Value);
            }
        }
예제 #3
0
        /// <summary>
        /// Retrieves a list of currently connected <see cref="Device"/>s (in debug mode).
        /// Drivers must be correctly installed to let ADB see the devices.
        /// </summary>
        /// <returns></returns>
        public List <Device> GetDevicesList()
        {
            var output = Exe.Adb(null, new[] { "devices" });

            if (ExeResponse.IsNullOrAbnormalExit(output))
            {
                return(null);
            }

            var cursor = output.Output.Split(new[] { Environment.NewLine }, StringSplitOptions.None).GetEnumerator();

            var devices = new List <Device>();

            while (cursor.MoveNext())
            {
                var current = cursor.Current as string;
                if (String.IsNullOrEmpty(current))
                {
                    continue;
                }

                var matches = Regex.Match(current, "^(?<serial>[a-z|0-9]+)[\\s]+(?<state>[a-z|0-9]+)$");
                if (!matches.Success)
                {
                    continue;
                }

                devices.Add(new Device
                {
                    Build        = new Build(matches.Groups["serial"].Value),
                    SerialNumber = matches.Groups["serial"].Value
                });
            }

            return(devices);
        }