@Nullable public AndroidDebugBridge getDebugBridge(@NotNull Project project) { if (!initializeDdmlib(project)) { return null; } return AndroidDebugBridge.getBridge(); }
private static void doInitializeDdmlib(@NotNull String adbPath) { synchronized (myDdmsLock) { if (!myDdmLibInitialized) { myDdmLibInitialized = true; DdmPreferences.setLogLevel(Log.LogLevel.INFO.getStringValue()); DdmPreferences.setTimeOut(AndroidUtils.TIMEOUT); AndroidDebugBridge.init(AndroidEnableAdbServiceAction.isAdbServiceEnabled()); LOG.info("DDMLib initialized"); final AndroidDebugBridge bridge = AndroidDebugBridge.createBridge(adbPath, true); waitUntilConnect(bridge); if (!bridge.isConnected()) { LOG.info("Failed to connect debug bridge"); } } else { final AndroidDebugBridge bridge = AndroidDebugBridge.getBridge(); final boolean forceRestart = myAdbCrashed || (bridge != null && !bridge.isConnected()); if (forceRestart) { LOG.info("Restart debug bridge: " + (myAdbCrashed ? "crashed" : "disconnected")); } final AndroidDebugBridge newBridge = AndroidDebugBridge.createBridge(adbPath, forceRestart); waitUntilConnect(newBridge); if (!newBridge.isConnected()) { LOG.info("Failed to connect debug bridge after restart"); } } } }