AndroidDebugBridge { public static ListenableFuture<AdbVersion> getAdbVersion(@NonNull final File adb) { final SettableFuture<AdbVersion> future = SettableFuture.create(); new Thread(new Runnable() { @Override public void run() { ProcessBuilder pb = new ProcessBuilder(adb.getPath(), "version"); pb.redirectErrorStream(true); Process p = null; try { p = pb.start(); } catch (IOException e) { future.setException(e); return; } StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); try { String line; while ((line = br.readLine()) != null) { AdbVersion version = AdbVersion.parseFrom(line); if (version != AdbVersion.UNKNOWN) { future.set(version); return; } sb.append(line); sb.append('\n'); } } catch (IOException e) { future.setException(e); return; } finally { try { br.close(); } catch (IOException e) { future.setException(e); } } future.setException(new RuntimeException( "Unable to detect adb version, adb output: " + sb.toString())); } }, "Obtaining adb version").start(); return future; } private  AndroidDebugBridge(String osLocation); private  AndroidDebugBridge(); static synchronized void initIfNeeded(boolean clientSupport); static synchronized void init(boolean clientSupport); static synchronized void terminate(); static InetSocketAddress getSocketAddress(); static AndroidDebugBridge createBridge(); @Nullable static AndroidDebugBridge createBridge(@NonNull String osLocation,
                                                  boolean forceNewBridge); @Nullable static AndroidDebugBridge getBridge(); static void disconnectBridge(); static void addDebugBridgeChangeListener(@NonNull IDebugBridgeChangeListener listener); static void removeDebugBridgeChangeListener(IDebugBridgeChangeListener listener); static void addDeviceChangeListener(@NonNull IDeviceChangeListener listener); static void removeDeviceChangeListener(IDeviceChangeListener listener); static void addClientChangeListener(IClientChangeListener listener); static void removeClientChangeListener(IClientChangeListener listener); @NonNull IDevice[] getDevices(); boolean hasInitialDeviceList(); void setSelectedClient(Client selectedClient); boolean isConnected(); int getConnectionAttemptCount(); int getRestartAttemptCount(); static ListenableFuture<AdbVersion> getAdbVersion(@NonNull final File adb); boolean restart();  }
@Test @Ignore public void emptyAdbPath() throws Exception { AdbVersion version = AndroidDebugBridge.getAdbVersion( new File("adb")).get(5, TimeUnit.SECONDS); assertTrue(version.compareTo(AdbVersion.parseFrom("1.0.20")) > 0); }
@Test public void adbVersion() throws Exception { AdbVersion version = AndroidDebugBridge .getAdbVersion(mAdbPath).get(5, TimeUnit.SECONDS); assertNotSame(version, AdbVersion.UNKNOWN); assertTrue(version.compareTo(AdbVersion.parseFrom("1.0.20")) > 0); }