Search in sources :

Example 16 with AndroidDebugBridge

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;
    }
}
Also used : AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 17 with 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);
        }
    }
}
Also used : CommandExecutor(com.taobao.android.builder.tools.command.CommandExecutor) IDevice(com.android.ddmlib.IDevice) ExecutionException(com.taobao.android.builder.tools.command.ExecutionException) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 18 with AndroidDebugBridge

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);
    });
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IDevice(com.android.ddmlib.IDevice) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Client(com.android.ddmlib.Client) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 19 with AndroidDebugBridge

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;
        }
    });
}
Also used : Update(com.intellij.util.ui.update.Update) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 20 with AndroidDebugBridge

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;
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)23 IDevice (com.android.ddmlib.IDevice)11 NotNull (org.jetbrains.annotations.NotNull)4 File (java.io.File)3 Client (com.android.ddmlib.Client)2 Project (com.intellij.openapi.project.Project)2 JBLoadingPanel (com.intellij.ui.components.JBLoadingPanel)2 TIntArrayList (gnu.trove.TIntArrayList)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)1 IdDisplay (com.android.sdklib.repository.IdDisplay)1 DeviceContext (com.android.tools.idea.ddms.DeviceContext)1 DevicePanel (com.android.tools.idea.ddms.DevicePanel)1 OpenVmTraceHandler (com.android.tools.idea.ddms.OpenVmTraceHandler)1 AndroidLogcatView (com.android.tools.idea.logcat.AndroidLogcatView)1 SuppressForbidden (com.facebook.buck.annotations.SuppressForbidden)1 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)1 ConsoleView (com.intellij.execution.ui.ConsoleView)1 RunnerLayoutUi (com.intellij.execution.ui.RunnerLayoutUi)1