diff --git a/src/se/vidstige/jadb/JadbDevice.java b/src/se/vidstige/jadb/JadbDevice.java index d2afcbb..2088007 100644 --- a/src/se/vidstige/jadb/JadbDevice.java +++ b/src/se/vidstige/jadb/JadbDevice.java @@ -4,7 +4,11 @@ import se.vidstige.jadb.managers.Bash; import java.io.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class JadbDevice { private final String serial; @@ -70,6 +74,37 @@ public class JadbDevice { } } + public Map getprop() throws IOException, JadbException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(executeShell("getprop"))); + return parseProp(bufferedReader); + } + + //@VisibleForTesting + Map parseProp(BufferedReader bufferedReader) throws IOException { + final Pattern pattern = Pattern.compile("^\\[(.*)\\]:.\\[(.*)\\]"); + + HashMap result = new HashMap<>(); + + String line; + Matcher matcher = pattern.matcher(""); + + while ((line = bufferedReader.readLine()) != null) { + matcher.reset(line); + + if(matcher.find()) { + if(matcher.groupCount() < 2) { + System.err.println("Property line: " + line +" does not match patter. Ignoring"); + continue; + } + String key = matcher.group(1); + String value = matcher.group(2); + result.put(key, value); + } + } + + return result; + } + public List list(String remotePath) throws IOException, JadbException { Transport transport = getTransport(); SyncTransport sync = transport.startSync();