mardi 3 mai 2016

Accessing an app database through ADB multiple times without closing the connection?

I am using ADB to access an app database like this:

public static int runCommandInt(String arg1) {
    try {
            ProcessBuilder proc = new ProcessBuilder(adbLocation, "shell", "sqlite3",
                "/data/data/com.package/databases/Database.db", arg1);
            Process p = proc.start();
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
            BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
            String s = null;
            int i = 0;
            while ((s = stdInput.readLine()) != null) {
                i = Integer.parseInt(s);
                p.destroyForcibly();
                return i;
            }
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
}

The problem with this, however, is that every time I try to run a command, it opens and closes adb (and therefore the database connection as well - which is extremely inefficient), is there a way to get the same adb window and execute more commands there?

It has to go through adb unfortunately. Pulling the database every second and checking locally leaves too much room for error.

Aucun commentaire:

Enregistrer un commentaire