Search code examples
androidlinux-kernelroottweak

Android: The ways to change build.prop


I need to build an application which enables me to edit the build.prop by using my own application. This is to optimize some of the values in the build.prop. Of course, I can edit this file using a file manager with root access. But my problem is, I need to edit this using an application that I create, and make it easy for the novice users to edit the file with recommended settings by my application. Please help me figure out this. Thanks for you time!


Solution

  • Something like this should work. Code hasn't been tested and might need some changes

    Requesting Superuser Access

    process = Runtime.getRuntime().exec("su");
    os = new DataOutputStream(process.getOutputStream());
    os.writeBytes("mount -o remount rw /system/\n"); 
    os.writeBytes("exit\n");
    os.flush();
    process.waitFor();
    
    File file=new File("/system/build.prop");
    

    Read file

    FileInputStream fis = openFileInput("/system/build.prop");
    String content = "";
    byte[] input = new byte[fis.available()];
    while (fis.read(input) != -1) {}
    content += new String(input);
    

    EDIT String content here.

    Write file

    DataOutputStream outstream= new DataOutputStream(new FileOutputStream(file,false));
    String body = content;
    outstream.write(body.getBytes());
    outstream.close();
    

    Remember to backup your build.prop in-case something goes wrong during editing.