Search code examples
androidfilesystemmove

android code to move file into system?


Im a galaxy s6 user here, I found out that the switch recent app button (the one on the left of the home button) quite annoying while playing game like vainglory because I misclicked it quite often. After doing some research I found out that it is possible to comment out the key 254 of generic.kl under system/usr/keylayout, then i come out with an idea of creating a new generic.kl which commented out the key 254, then with a click of button on my app it will move the file with the commented key to system/usr/keylayout to replace the old way, vice versa, I will make a restore button there to restore it will the original generic.kl when I wan the recent app switch to start working again. So my question here is what would be the code to move a file to system and replace it? I do have some basic android programming knowledge and my phone is rooted.

Thanks in advance.


Solution

  • Use the code below to copy to system. Requires root access.

    void copyToSystem() {
    
        try {
            Process proc = Runtime.getRuntime().exec(
                new String[]{
                    "su", "-c", 
                    "mount -o rw,remount /system ;"
                  + " cp -f /storage/sdcard0/MyFolder/MyKeyLayout.kl /system/usr/keylayout/ ;"
                  + " mount -o ro,remount /system"});
            proc.waitFor();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    

    You need to import java.lang.Process and not android.os.Process

    Note: cp -f ensures that the file is replaced if already existing.