Esempio n. 1
0
        private void GetSuData()
        {
            if (this._device.State != DeviceState.Online)
            {
                this._version = null;
                this._exists  = false;
                return;
            }

            var adbCmd = Adb.FormAdbShellCommand(this._device, false, "su", "-v");

            using (var r = new StringReader(Adb.ExecuteAdbCommand(adbCmd)))
            {
                var line = r.ReadLine();

                if (line.Contains("not found") || line.Contains("permission denied"))
                {
                    this._version = "-1";
                    this._exists  = false;
                }
                else
                {
                    this._version = line;
                    this._exists  = true;
                }
            }
        }
Esempio n. 2
0
        private void Update()
        {
            try
            {
                this._prop.Clear();

                if (this._device.State != DeviceState.Online)
                {
                    return;
                }

                var adbCmd = Adb.FormAdbShellCommand(this._device, false, "getprop");
                var prop   = Adb.ExecuteAdbCommand(adbCmd);

                var lines = prop.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries);

                for (var i = 0; i < lines.Length; i++)
                {
                    var entry = lines[i].Split(new string[] { "[", "]: [", "]" }, StringSplitOptions.RemoveEmptyEntries);

                    if (entry.Length == 2)
                    {
                        this._prop.Add(entry[0], entry[1]);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message, "Using: getprop in BuildProp.cs", ex.StackTrace);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets a Dictionary<c> string / ListingType></c> containing all the files and folders in the directory added as a parameter.
        /// </summary>
        /// The directory you'd like to list the files and folders from.
        /// E.G.: /system/bin/
        /// <returns>See <see cref="Dictionary"/></returns>
        public Dictionary <string, ListingType> GetFilesAndDirectories(string location)
        {
            if (location == null || string.IsNullOrEmpty(location) || Regex.IsMatch(location, @"\s"))
            {
                throw new ArgumentException("rootDir must not be null or empty!");
            }

            var        filesAndDirs = new Dictionary <string, ListingType>();
            AdbCommand cmd          = null;

            if (_device.BusyBox.IsInstalled)
            {
                cmd = Adb.FormAdbShellCommand(_device, true, "busybox", "ls", "-a", "-p", "-l", location);
            }
            else
            {
                cmd = Adb.FormAdbShellCommand(_device, true, "ls", "-a", "-p", "-l", location);
            }

            using (var reader = new StringReader(Adb.ExecuteAdbCommand(cmd)))
            {
                string line = null;
                while (reader.Peek() != -1)
                {
                    line = reader.ReadLine();
                    if (!string.IsNullOrEmpty(line) && !Regex.IsMatch(line, @"\s"))
                    {
                        filesAndDirs.Add(line, line.EndsWith("/") ? ListingType.Directory : ListingType.File);
                    }
                }
            }


            return(filesAndDirs);
        }
Esempio n. 4
0
        private void UpdateMountPoints()
        {
            if (this._device.State != DeviceState.Online)
            {
                this._systemMount = new MountInfo(null, null, MountType.None);
                return;
            }

            var adbCmd = Adb.FormAdbShellCommand(this._device, false, "mount");

            using (var r = new StringReader(Adb.ExecuteAdbCommand(adbCmd)))
            {
                string    line;
                string[]  splitLine;
                string    dir, mount;
                MountType type;

                while (r.Peek() != -1)
                {
                    line      = r.ReadLine();
                    splitLine = line.Split(' ');

                    try
                    {
                        if (line.Contains(" on /system "))
                        {
                            dir               = splitLine[2];
                            mount             = splitLine[0];
                            type              = (MountType)Enum.Parse(typeof(MountType), splitLine[5].Substring(1, 2).ToUpper());
                            this._systemMount = new MountInfo(dir, mount, type);
                            return;
                        }

                        if (line.Contains(" /system "))
                        {
                            dir               = splitLine[1];
                            mount             = splitLine[0];
                            type              = (MountType)Enum.Parse(typeof(MountType), splitLine[3].Substring(0, 2).ToUpper());
                            this._systemMount = new MountInfo(dir, mount, type);
                            return;
                        }
                    }
                    catch
                    {
                        dir               = "/system";
                        mount             = "ERROR";
                        type              = MountType.None;
                        this._systemMount = new MountInfo(dir, mount, type);
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Updates the instance of busybox
        /// </summary>
        /// <remarks>Generally called only if busybox may have changed on the device</remarks>
        public void Update()
        {
            this._commands.Clear();

            if (!this._device.HasRoot || this._device.State != DeviceState.Online)
            {
                SetNoBusybox();
                return;
            }

            var adbCmd = Adb.FormAdbShellCommand(this._device, false, Executable);

            using (var s = new StringReader(Adb.ExecuteAdbCommand(adbCmd)))
            {
                var check = s.ReadLine();

                if (check.Contains(string.Format("{0}: not found", Executable)))
                {
                    SetNoBusybox();
                    return;
                }

                this._isInstalled = true;

                this._version = check.Split(' ')[1].Substring(1);

                while (s.Peek() != -1 && s.ReadLine() != "Currently defined functions:")
                {
                }

                var cmds = s.ReadToEnd().Replace(" ", "").Replace("\r\r\n\t", "").Trim('\t', '\r', '\n').Split(',');

                if (cmds.Length.Equals(0))
                {
                    SetNoBusybox();
                }
                else
                {
                    foreach (var cmd in cmds)
                    {
                        this._commands.Add(cmd);
                    }
                }
            }
        }
 private void CreateResourceDirectories()
 {
     try
     {
         if (!Adb.ExecuteAdbCommand(new AdbCommand("version")).Contains(Adb.AdbVersion))
         {
             Adb.KillServer();
             Thread.Sleep(1000);
             ResourceFolderManager.Unregister(AndroidControllerTmpFolder);
             _extractResources = true;
         }
     }
     catch (Exception)
     {
         _extractResources = true;
     }
     ResourceFolderManager.Register(AndroidControllerTmpFolder);
 }
Esempio n. 7
0
        /// <summary>
        /// Gets a <see cref="ListingType"/> indicating is the requested location is a File or Directory
        /// </summary>
        /// <param name="location">Path of requested location on device</param>
        /// <returns>See <see cref="ListingType"/></returns>
        /// <remarks><para>Requires a device containing BusyBox for now, returns ListingType.ERROR if not installed.</para>
        /// <para>Returns ListingType.NONE if file/Directory does not exist</para></remarks>
        public ListingType FileOrDirectory(string location)
        {
            if (!this._device.BusyBox.IsInstalled)
            {
                return(ListingType.Error);
            }

            var isFile = Adb.FormAdbShellCommand(this._device, false, string.Format(IsFile, location));
            var isDir  = Adb.FormAdbShellCommand(this._device, false, string.Format(IsDirectory, location));

            if (Adb.ExecuteAdbCommand(isFile).Contains("1"))
            {
                return(ListingType.File);
            }
            else if (Adb.ExecuteAdbCommand(isDir).Contains("1"))
            {
                return(ListingType.Directory);
            }

            return(ListingType.None);
        }
Esempio n. 8
0
        private void Update()
        {
            if (this._device.State != DeviceState.Online)
            {
                this._acPower       = false;
                this._dump          = null;
                this._health        = -1;
                this._level         = -1;
                this._present       = false;
                this._scale         = -1;
                this._status        = -1;
                this._technology    = null;
                this._temperature   = -1;
                this._usbPower      = false;
                this._voltage       = -1;
                this._wirelessPower = false;
                this._outString     = "Device Not Online";
                return;
            }
            else
            {
                var adbCmd = Adb.FormAdbShellCommand(this._device, false, "dumpsys", "battery");
                this._dump = Adb.ExecuteAdbCommand(adbCmd);

                using (var r = new StringReader(this._dump))
                {
                    string line;

                    while (true)
                    {
                        line = r.ReadLine();

                        if (line != null && !line.Contains("Current Battery Service state"))
                        {
                            continue;
                        }
                        this._dump = line + r.ReadToEnd();
                        break;
                    }
                }

                using (var r = new StringReader(this._dump))
                {
                    var line = "";

                    while (r.Peek() != -1)
                    {
                        line = r.ReadLine();

                        if (line == "")
                        {
                            continue;
                        }
                        else if (line.Contains("AC "))
                        {
                            bool.TryParse(line.Substring(14), out this._acPower);
                        }
                        else if (line.Contains("USB"))
                        {
                            bool.TryParse(line.Substring(15), out this._usbPower);
                        }
                        else if (line.Contains("Wireless"))
                        {
                            bool.TryParse(line.Substring(20), out this._wirelessPower);
                        }
                        else if (line.Contains("status"))
                        {
                            int.TryParse(line.Substring(10), out this._status);
                        }
                        else if (line.Contains("health"))
                        {
                            int.TryParse(line.Substring(10), out this._health);
                        }
                        else if (line.Contains("present"))
                        {
                            bool.TryParse(line.Substring(11), out this._present);
                        }
                        else if (line.Contains("level"))
                        {
                            int.TryParse(line.Substring(9), out this._level);
                        }
                        else if (line.Contains("scale"))
                        {
                            int.TryParse(line.Substring(9), out this._scale);
                        }
                        else if (line.Contains("voltage"))
                        {
                            int.TryParse(line.Substring(10), out this._voltage);
                        }
                        else if (line.Contains("temp"))
                        {
                            int.TryParse(line.Substring(15), out this._temperature);
                        }
                        else if (line.Contains("tech"))
                        {
                            this._technology = line.Substring(14);
                        }
                    }
                }

                this._outString = this._dump.Replace("Service state", "State For Device " + this._device.SerialNumber);
            }
        }