Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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 Process deleteBuildProperty(Context c, String propName) {
        Process p = null;
        try {
            remountSystem(c);

            p = runSuCommandAsync(c, "busybox sed -i \"/" + propName + "=.*/d\" /system/build.prop ; ");
            p.waitFor();
        } catch (Exception d) {
            Log.e("Helper", "d");
            Log.e("Helper", "Failed to delete build.prop. errcode:" + d.toString());
        }
        return p;
    }

    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();
    }
}