public class DeviceInfo { public static String execute(String cmd) { System.out.println(cmd); StringBuilder sb = new StringBuilder(); StringBuilder error = new StringBuilder(); try { Process p = Runtime.getRuntime().exec(cmd); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = bufferedReader.readLine()) != null) { sb.append(line); sb.append("\n"); } BufferedReader errorReader = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((line = errorReader.readLine()) != null) { error.append(line); error.append("\n"); } } catch (Exception e) { e.printStackTrace(); } // String err = error.toString(); System.out.println(error.toString()); return sb.toString(); } public static Map<String, String> getDevices() { String t = execute("adb devices"); String[] ds = t.split("\n"); Map<String, String> r = new HashMap<String,String>(); for (int i = 1; i < ds.length; i++) { ds[i] = ds[i].split(" |\t")[0]; r.put(execute(ADB.getPhoneInfoBase(ds[i])).replace("\n", ""), ds[i]); } return r; } public static String execute(String cmd, ResultCallback resultCallback) { // System.out.println(cmd); int count = 0; StringBuffer sb = new StringBuffer(); StringBuffer error = new StringBuffer(); try { Process p = Runtime.getRuntime().exec(cmd); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = bufferedReader.readLine()) != null /*&& count < 5*/) { //long start = System.currentTimeMillis(); //count++; sb.append(line); sb.append("\n"); resultCallback.receiveLine(line + "\n" ); // long end= System.currentTimeMillis();// if (line.contains("Escape")) {// break;// }// if(end-start>5*1000)// {// break;// } } } catch (Exception e) { e.printStackTrace(); } // String err = error.toString(); System.out.println(error.toString()); return sb.toString(); }}