Java tutorial
//package com.java2s; //License from project: Apache License import java.io.DataOutputStream; import java.io.IOException; import android.content.Context; import android.util.Log; public class Main { public final static String SCRIPT_NAME = "surunner.sh"; public static void deleteBuildPropertyBatched(Context c, String propArgument) { StringBuilder propName = new StringBuilder(""); StringBuilder propValue = new StringBuilder(""); StringBuilder commandLine = new StringBuilder(""); boolean isValue = false; for (int i = 0; i < propArgument.length(); i++) { char ch = propArgument.charAt(i); if (ch == '=' && isValue == false) { isValue = true; } else if (ch == ';') { commandLine.append("busybox sed -i \"/" + propName + "=.*/d\" /system/build.prop ; "); isValue = false; propName = new StringBuilder(""); propValue = new StringBuilder(""); } else { if (isValue) propValue.append(ch); else propName.append(ch); } } Process p = null; try { remountSystem(c); p = runSuCommandAsync(c, commandLine.toString()); p.waitFor(); } catch (Exception d) { Log.e("Helper", "Failed to batch delete build.prop. errcode:" + d.toString()); } } public static void remountSystem(Context c) { try { runSuCommand(c, "mount -orw,remount /system ; "); } catch (Exception d) { /* Does not require error handler */ } } public static Process runSuCommandAsync(Context context, String command) throws IOException { DataOutputStream fout = new DataOutputStream(context.openFileOutput(SCRIPT_NAME, 0)); fout.writeBytes(command); fout.close(); String[] args = new String[] { "su", "-c", ". " + context.getFilesDir().getAbsolutePath() + "/" + SCRIPT_NAME }; Process proc = Runtime.getRuntime().exec(args); return proc; } public static int runSuCommand(Context context, String command) throws IOException, InterruptedException { return runSuCommandAsync(context, command).waitFor(); } }