private DeviceState SetState() { string state = null; using (var r = new StringReader(Adb.Devices())) { string line; while (r.Peek() != -1) { line = r.ReadLine(); if (line != null && line.Contains(_serialNumber)) { state = line.Substring(line.IndexOf('\t') + 1); } } } if (state == null) { using (var r = new StringReader(Fastboot.Devices())) { string line; while (r.Peek() != -1) { line = r.ReadLine(); if (line != null && line.Contains(_serialNumber)) { state = line.Substring(line.IndexOf('\t') + 1); } } } } switch (state) { case "device": return(DeviceState.Online); case "recovery": return(DeviceState.Recovery); case "fastboot": return(DeviceState.Fastboot); case "sideload": return(DeviceState.Sideload); case "unauthorized": return(DeviceState.Unauthorized); default: return(DeviceState.Unknown); } }
private Task UpdateDeviceListTask() { return(Task.Factory.StartNew(() => { this._connectedDevices.Clear(); var deviceList = Adb.Devices(); if (!(deviceList.Length <= 0)) { using (var s = new StringReader(deviceList)) { while (s.Peek() != -1) { var line = s.ReadLine(); if (line != null && (line.StartsWith("List") || line.StartsWith("\r\n") || line.Trim() == "")) { continue; } if (line == null || line.IndexOf('\t') == -1) { continue; } line = line.Substring(0, line.IndexOf('\t')); this._connectedDevices.Add(line); } } } deviceList = Fastboot.Devices(); if (deviceList.Length <= 0) { return; } using (var s = new StringReader(deviceList)) { while (s.Peek() != -1) { var line = s.ReadLine(); if (line != null && (line.StartsWith("List") || line.StartsWith("\r\n") || line.Trim() == "")) { continue; } if (line == null || line.IndexOf('\t') == -1) { continue; } line = line.Substring(0, line.IndexOf('\t')); this._connectedDevices.Add(line); } } })); }