1

I have written a Web View app, which logs you into 12 different sites (sign in) which works pretty fine. However, i am trying to figure out a way to backup my web view's data (so that all the login credentials are saved) to SD card. the only way i have found is to copy the root/data/data/com.example/your app folder.

How do i copy this folder somewhere to my SD card using root command on the click of a button?

this is how i access and delete the data folder

private void clear() {
    String cmd = "pm clear com.wagtailapp";
    ProcessBuilder pb = new ProcessBuilder().redirectErrorStream(true)
            .command("su");
    Process p = null;
    try {
        p = pb.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
    StreamReader stdoutReader = new StreamReader(p.getInputStream(),
            CHARSET_NAME);
    stdoutReader.start();
    out = p.getOutputStream();
    try {
        out.write((cmd + "\n").getBytes(CHARSET_NAME));
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    try {
        out.write(("exit" + "\n").getBytes(CHARSET_NAME));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        out.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        p.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    String result = stdoutReader.getResult();
}

}

streamreader.java

class StreamReader extends Thread {
private InputStream is;
private StringBuffer mBuffer;
private String mCharset;
private CountDownLatch mCountDownLatch;

StreamReader(InputStream is, String charset) {
    this.is = is;
    mCharset = charset;
    mBuffer = new StringBuffer("");
    mCountDownLatch = new CountDownLatch(1);
}

String getResult() {
    try {
        mCountDownLatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return mBuffer.toString();
}

@Override
public void run() {
    InputStreamReader isr = null;
    try {
        isr = new InputStreamReader(is, mCharset);
        int c = -1;
        while ((c = isr.read()) != -1) {
            mBuffer.append((char) c);
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (isr != null)
                isr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        mCountDownLatch.countDown();
    }
}

}

Emily
  • 11
  • 4
  • i don't think it's good to expose such data on the SD card. – Yazan Mar 10 '16 at 12:36
  • i though passwords were encrypted. how about hiding that folder by simply putting a "."? – Emily Mar 10 '16 at 12:46
  • i am not sure if content is encrypted, but as credentials and cookies (maybe) it's not good to expose it, adding . will hide it from regular user's .. those are not whom we are afraid of :) – Yazan Mar 10 '16 at 12:50
  • its all good, this is for personal use :D – Emily Mar 10 '16 at 15:04
  • well, just remember i have warned you :), you can use Java APIs to read/write file (copy) such as this http://stackoverflow.com/questions/2520305/java-io-to-copy-one-file-to-another and this https://examples.javacodegeeks.com/core-java/io/file/4-ways-to-copy-file-in-java/ – Yazan Mar 10 '16 at 15:33

0 Answers0