2
if (DownloadManager.STATUS_SUCCESSFUL == c
.getInt(columnIndex)) {
    mProgress.setProgress(70);
    mStatus.setText(R.string.status_backup);
    File dl_path = new File(DownloadManager.COLUMN_LOCAL_URI);
    File og_path = new File("/system/app/app.apk");
    String bu_path = "/sdcard/asdfgsd/backup/app.apk";
    Process p;  
    try {  
        // Preform su to get root privledges
        p = Runtime.getRuntime().exec("su");   
        // Attempt to write a file to a root-only  
        DataOutputStream os = new DataOutputStream(p.getOutputStream());  
        os.writeBytes("echo \"Do I have root?\" >/system/sd/temporary.txt\n");  
        // Close the terminal  
        os.writeBytes("exit\n");  
        os.flush();  
        try {  
            p.waitFor();
            if (p.exitValue() != 255) {  
                // Trying to remount system partition in read-write mode
                p.getOutputStream().write("mount -o r,remount -t yaffs2 /dev/block/mtdblock3 /system".getBytes());
                if (og_path.renameTo(new File(bu_path))) {
                    mProgress.setProgress(90);
                    mStatus.setText(R.string.status_install);
                    dl_path.renameTo(og_path);  } else {
                    mStatus.setText(R.string.status_error_1);
                }
            }
        } catch (InterruptedException e) {  
             mStatus.setText(R.string.status_error_2);  
        }  
    } catch (IOException e) {  
         mStatus.setText(R.string.status_error_3);  
    }   
}

So this is a piece of code that should replace an app from /system/app to backup folder and then it should replace a copy downloaded via DM API to /system/app. Everything works perfect until app starts asking for SU permissions. As you can see, I put some error strings in case of exceptions to make debug easier, and it seems like it got an IO exception (status_error_3). What's wrong with my code?

UPD: SU successfully asks for granting permissions to my app, so it should work but it doesn't.

Thanks in advance!

Adiost
  • 199
  • 2
  • 10

0 Answers0