Android examples for Android OS:Shell
get IO Scheduler from Shell
import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.SystemProperties; import android.util.Log; import android.widget.Toast; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Date; public class Main{ private static final String TAG = Thread.currentThread().getStackTrace()[1].getClassName(); public static String getIOScheduler() { String scheduler = null;//from w ww. ja v a 2 s . c o m String[] schedulers = readStringArray("/sys/block/mmcblk0/queue/scheduler"); if (schedulers != null) { for (String s : schedulers) { if (s.charAt(0) == '[') { scheduler = s.substring(1, s.length() - 1); break; } } } return scheduler; } private static String[] readStringArray(String fname) { String line = readOneLine(fname); if (line != null) { return line.split(" "); } return null; } public static String readOneLine(String fname) { BufferedReader br = null; String line = null; try { br = new BufferedReader(new FileReader(fname), 1024); line = br.readLine(); } catch (FileNotFoundException ignored) { Log.d(TAG, "File was not found! trying via shell..."); return readFileViaShell(fname, true); } catch (IOException e) { Log.d(TAG, "IOException while reading system file", e); return readFileViaShell(fname, true); } finally { if (br != null) { try { br.close(); } catch (IOException ignored) { // failed to close reader } } } return line; } public static String readFileViaShell(String filePath, boolean useSu) { String command = new String("cat " + filePath); return useSu ? CMDProcessorAOKP.runSuCommand(command).getStdout() : CMDProcessorAOKP.runShellCommand(command).getStdout(); } }