/// <summary> /// Determines if the app has been rooted, by checking if we can /// locate the specified file. /// </summary> public bool CanLocateFile(string target) { try { using (var process = Java.Lang.Runtime.GetRuntime().Exec(new[] { "which", target })) { try { using (var inputStream = new Java.IO.InputStreamReader(process.InputStream)) { using (var inputReader = new Java.IO.BufferedReader(inputStream)) { // will return the path of the target, if found, // otherwise an empty response. return(!string.IsNullOrWhiteSpace(inputReader.ReadLine())); } } } finally { process.Destroy(); } } } catch (Exception ex) { Env.Reporter.ReportException($"CanLocateFile bombed for {target}", ex); return(false); } }
/// <summary> /// Determines if the app has been rooted, by checking if the specified /// OS property has the specified value /// </summary> public bool HasPropValue(string key, string value) { try { using (var process = Java.Lang.Runtime.GetRuntime().Exec("getprop")) { try { if (process.InputStream == null) { return(false); } using (var inputStreamReader = new Java.IO.InputStreamReader(process.InputStream)) { using (var inputReader = new Java.IO.BufferedReader(inputStreamReader)) { for (var i = 0; i < 1000; ++i) { var line = inputReader.ReadLine(); if (line == null) { break; } var k = $"[{key}]"; var v = $"[{value}]"; if (line.Contains(k) && line.Contains(v)) { return(true); } } } } } finally { process.Destroy(); } } return(false); } catch (Exception ex) { this.Env.Reporter.ReportException($"HasPropValue bombed for {this.id} ({key}={value})", ex); return(false); } }
//Adapted from: https://stackoverflow.com/questions/3012287/how-to-read-mms-data-in-android private string GetMmsText(string id) { Android.Net.Uri partURI = Android.Net.Uri.Parse("content://mms/part/" + id); System.IO.Stream inputStream = null; System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); try { ContentResolver contentResolver = AndroidApp.Context.ContentResolver; inputStream = contentResolver.OpenInputStream(partURI); if (inputStream != null) { Java.IO.InputStreamReader inputStreamReader = new Java.IO.InputStreamReader(inputStream, "UTF-8"); Java.IO.BufferedReader reader = new Java.IO.BufferedReader(inputStreamReader); string temp = reader.ReadLine(); while (temp != null) { stringBuilder.Append(temp); temp = reader.ReadLine(); } } } catch (System.IO.IOException error) { Log.Error(TAG, "Error reading MMS text: " + error); } finally { if (inputStream != null) { try { inputStream.Close(); } catch (System.IO.IOException error) { Log.Error(TAG, "Error closing input stream for reading MMS text: " + error); } } } return(stringBuilder.ToString()); }
private async Task Connect(string name) { BluetoothDevice device = null; BluetoothAdapter adapter = BluetoothAdapter.DefaultAdapter; BluetoothSocket bthSocket = null; _cancellationToken = new CancellationTokenSource(); while (_cancellationToken.IsCancellationRequested == false) { try { Thread.Sleep(250); adapter = BluetoothAdapter.DefaultAdapter; Console.Write("Trying to connect to " + name + ". "); foreach (var bondedDevice in adapter.BondedDevices) { if (bondedDevice.Name.ToUpper().IndexOf(name.ToUpper()) >= 0) { Console.Write("Found " + bondedDevice.Name); device = bondedDevice; break; } } if (device == null) { Console.Write("Not found"); } else { Console.WriteLine(); UUID uuid = UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"); bthSocket = device.CreateInsecureRfcommSocketToServiceRecord(uuid); if (bthSocket != null) { Console.WriteLine("test"); await bthSocket.ConnectAsync(); if (bthSocket.IsConnected) { Console.WriteLine("Connected"); RVCC.MainPage.BluetoothConnect(); var mReader = new Java.IO.InputStreamReader(bthSocket.InputStream); var buffer = new Java.IO.BufferedReader(mReader); while (_cancellationToken.IsCancellationRequested == false) { if (MessageToSend != null) { Console.WriteLine(MessageToSend); var chars = MessageToSend.ToCharArray(); var bytes = new List <byte>(); foreach (var character in chars) { bytes.Add((byte)character); } await bthSocket.OutputStream.WriteAsync(bytes.ToArray(), 0, bytes.Count); MessageToSend = null; } } } } } } catch (Exception ex) { Console.Write(ex); Console.Write(ex.Message); } finally { if (bthSocket != null) { bthSocket.Close(); } device = null; adapter = null; } } }