use of com.android.ddmlib.AndroidDebugBridge in project atlas by alibaba.
the class AwoInstaller method initAndroidDebugBridge.
protected static AndroidDebugBridge initAndroidDebugBridge(AndroidBuilder androidBuilder) {
synchronized (ADB_LOCK) {
if (!adbInitialized) {
DdmPreferences.setTimeOut(adbConnectionTimeout);
AndroidDebugBridge.init(false);
adbInitialized = true;
}
AndroidDebugBridge androidDebugBridge = AndroidDebugBridge.createBridge(androidBuilder.getSdkInfo().getAdb().getAbsolutePath(), false);
waitUntilConnected(androidDebugBridge);
return androidDebugBridge;
}
}
use of com.android.ddmlib.AndroidDebugBridge in project atlas by alibaba.
the class AwoInstaller method installPatchIfDeviceConnected.
/**
* no device or too many device make install fail
*
* @param patch
* @return
*/
private static boolean installPatchIfDeviceConnected(AndroidBuilder androidBuilder, File patch, String patchPkg, Logger logger) {
final AndroidDebugBridge androidDebugBridge = initAndroidDebugBridge(androidBuilder);
if (!androidDebugBridge.isConnected()) {
throw new RuntimeException("Android Debug Bridge is not connected.");
}
waitForInitialDeviceList(androidDebugBridge, logger);
List<IDevice> devices = Arrays.asList(androidDebugBridge.getDevices());
String PATCH_INSTALL_DIRECTORY = String.format("%s%s%s", PATCH_INSTALL_DIRECTORY_PREFIX, patchPkg, PATCH_INSTALL_DIRECTORY_SUFFIX);
if (devices.size() == 0) {
throw new RuntimeException(String.format("%s%s%s%s%s", "no device connected,please check whether the connection is successful or copy ", patch, " in build/outputs/awbs/libxxx.so ", PATCH_INSTALL_DIRECTORY, " and restart you app"));
}
if (devices.size() > 1) {
throw new RuntimeException("too much devices be connected,please disconnect the others and try again");
}
CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
executor.setLogger(logger);
executor.setCaptureStdOut(true);
executor.setCaptureStdErr(true);
List<String> cmd = Arrays.asList("push", patch.getAbsolutePath(), PATCH_INSTALL_DIRECTORY + patch.getName());
try {
executor.executeCommand(androidBuilder.getSdkInfo().getAdb().getAbsolutePath(), cmd, false);
return true;
} catch (ExecutionException e) {
throw new RuntimeException("Error while trying to push patch to device ", e);
} finally {
String errout = executor.getStandardError();
if ((errout != null) && (errout.trim().length() > 0)) {
logger.error(errout);
}
}
}
use of com.android.ddmlib.AndroidDebugBridge in project android by JetBrains.
the class AndroidProcessChooserDialog method doUpdateTree.
private void doUpdateTree(boolean showAllProcesses) {
final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(myProject);
final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
final DefaultTreeModel model = new DefaultTreeModel(root);
if (debugBridge == null) {
myProcessTree.setModel(model);
return;
}
final Set<String> processNames = collectAllProcessNames(myProject);
TreeNode selectedDeviceNode = null;
TreeNode selectedClientNode = null;
Object[] firstTreePath = null;
final IDevice[] devices = debugBridge.getDevices();
for (IDevice device : devices) {
final DefaultMutableTreeNode deviceNode = new DefaultMutableTreeNode(device);
root.add(deviceNode);
final String deviceName = device.getName();
if (deviceName.equals(myLastSelectedDevice)) {
selectedDeviceNode = deviceNode;
}
List<Client> clients = Lists.newArrayList(device.getClients());
Collections.sort(clients, (c1, c2) -> {
String n1 = StringUtil.notNullize(c1.getClientData().getClientDescription());
String n2 = StringUtil.notNullize(c2.getClientData().getClientDescription());
return n1.compareTo(n2);
});
for (Client client : clients) {
final String clientDescription = client.getClientData().getClientDescription();
if (clientDescription != null && (showAllProcesses || isRelatedProcess(processNames, clientDescription))) {
final DefaultMutableTreeNode clientNode = new DefaultMutableTreeNode(client);
deviceNode.add(clientNode);
if (clientDescription.equals(myLastSelectedProcess) && (selectedDeviceNode == null || deviceName.equals(myLastSelectedDevice))) {
selectedClientNode = clientNode;
selectedDeviceNode = deviceNode;
}
if (firstTreePath == null) {
firstTreePath = new Object[] { root, deviceNode, clientNode };
}
}
}
}
final Object[] pathToSelect;
if (selectedDeviceNode != null && selectedClientNode != null) {
pathToSelect = new Object[] { root, selectedDeviceNode, selectedClientNode };
} else if (selectedDeviceNode != null) {
pathToSelect = new Object[] { root, selectedDeviceNode };
} else {
pathToSelect = firstTreePath;
}
UIUtil.invokeLaterIfNeeded(() -> {
myProcessTree.setModel(model);
if (pathToSelect != null) {
myProcessTree.getSelectionModel().setSelectionPath(new TreePath(pathToSelect));
} else {
getOKAction().setEnabled(false);
}
TreeUtil.expandAll(myProcessTree);
});
}
use of com.android.ddmlib.AndroidDebugBridge in project android by JetBrains.
the class AndroidProcessChooserDialog method updateTree.
private void updateTree() {
final boolean showAllProcesses = myShowAllProcessesCheckBox.isSelected();
myUpdatesQueue.queue(new Update(AndroidProcessChooserDialog.this) {
@Override
public void run() {
final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(myProject);
if (debugBridge != null && AdbService.isDdmsCorrupted(debugBridge)) {
ApplicationManager.getApplication().invokeLater(() -> {
Messages.showErrorDialog(myContentPanel, AndroidBundle.message("ddms.corrupted.error"));
AndroidProcessChooserDialog.this.close(1);
});
return;
}
doUpdateTree(showAllProcesses);
}
@Override
public boolean canEat(Update update) {
return true;
}
});
}
use of com.android.ddmlib.AndroidDebugBridge in project android by JetBrains.
the class AndroidSdkUtils method getDebugBridge.
@Nullable
public static AndroidDebugBridge getDebugBridge(@NotNull Project project) {
ApplicationManager.getApplication().assertIsDispatchThread();
AndroidSdkData data = getProjectSdkData(project);
if (data == null) {
data = getFirstAndroidModuleSdkData(project);
}
if (data == null) {
return null;
}
AndroidDebugBridge bridge = null;
boolean retry;
do {
File adb = getAdb(project);
if (adb == null) {
LOG.error("Unable to locate adb within SDK");
return null;
}
Future<AndroidDebugBridge> future = AdbService.getInstance().getDebugBridge(adb);
MyMonitorBridgeConnectionTask task = new MyMonitorBridgeConnectionTask(project, future);
ProgressManager.getInstance().run(task);
if (task.wasCanceled()) {
// if the user cancelled the dialog
return null;
}
retry = false;
try {
bridge = future.get();
} catch (InterruptedException e) {
break;
} catch (ExecutionException e) {
// timed out waiting for bridge, ask the user what to do
String message = "ADB not responding. If you'd like to retry, then please manually kill \"" + FN_ADB + "\" and click 'Restart'";
retry = Messages.showYesNoDialog(project, message, CommonBundle.getErrorTitle(), "&Restart", "&Cancel", Messages.getErrorIcon()) == Messages.YES;
}
} while (retry);
return bridge;
}
Aggregations