com.android.ddmlib.Client Java Examples
The following examples show how to use
com.android.ddmlib.Client.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeviceLogDataProvider.java From logviewer with Apache License 2.0 | 6 votes |
/** * Updates the process list */ public void updateProcessList() { if (logListener != null) { UIUtil.invokeLaterIfNeeded(() -> { try { if (device != null && logListener != null) { List<Client> clients = Lists.newArrayList(device.getClients()); clients.sort(new ClientCellRenderer.ClientComparator()); logListener.onProcessList(toLogProcess(clients)); } } catch (Exception ignored) { } }); } }
Example #2
Source File: LogReader.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
/** * Get a reference to the name of the process with the given ID. The * reference may contain a null-object, couldn't be retrieved, but may be * available later. * * @param device Device, where the process runs. * @param pid ID of the process. * @return A reference to a string containing the process name or * {@code null}, if the process couldn't be retrieved yet. */ private String[] getProcessName(IDevice device, int pid) { Map<Integer, String[]> cache = processNameCache.get(device.getSerialNumber()); if (cache == null) { cache = new HashMap<>(); processNameCache.put(device.getSerialNumber(), cache); } String[] nameref = cache.get(pid); if (nameref == null) { nameref = new String[1]; cache.put(pid, nameref); } if (nameref[0] == null) { for (Client client : device.getClients()) { ClientData data = client.getClientData(); if (data.getPid() == pid) { nameref[0] = data.getClientDescription(); } } } return nameref; }
Example #3
Source File: LogSourceManager.java From logviewer with Apache License 2.0 | 6 votes |
/** * Observe for deviec state changes */ private void observeForDeviceChange() { deviceSelectionListener = new DeviceContext.DeviceSelectionListener() { @Override public void deviceSelected(@Nullable IDevice device) { notifyDeviceUpdated(device); } @Override public void deviceChanged(@NotNull IDevice device, int changeMask) { if ((changeMask & IDevice.CHANGE_STATE) == IDevice.CHANGE_STATE) { notifyDeviceUpdated(device); } } @Override public void clientSelected(@Nullable final Client c) { } }; deviceContext.addListener(deviceSelectionListener, this); AndroidDebugBridge.addClientChangeListener(this); AndroidDebugBridge.addDeviceChangeListener(this); AndroidDebugBridge.addDebugBridgeChangeListener(this); }
Example #4
Source File: ClientNode.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
ClientNode(final Client client) { super(Children.LEAF, Lookups.fixed(client)); assert client != null; this.client = client; this.setIconBaseWithExtension("org/netbeans/modules/android/project/resources/application.png"); updateInfo(); AndroidDebugBridge.addClientChangeListener(this); this.addNodeListener(new NodeListener() { @Override public void childrenAdded(NodeMemberEvent e) { } @Override public void childrenRemoved(NodeMemberEvent e) { } @Override public void childrenReordered(NodeReorderEvent e) { } @Override public void nodeDestroyed(NodeEvent e) { AndroidDebugBridge.removeClientChangeListener(ClientNode.this); } @Override public void propertyChange(PropertyChangeEvent e) { } }); }
Example #5
Source File: BlazeAutoAndroidDebugger.java From intellij with Apache License 2.0 | 5 votes |
@Override public void attachToClient(Project project, Client client, RunConfiguration config) { if (isNativeProject(project)) { log.info("Project has native development enabled. Attaching native debugger."); nativeDebugger.attachToClient(project, client, config); } else { super.attachToClient(project, client, config); } }
Example #6
Source File: BlazeNativeAndroidDebugger.java From intellij with Apache License 2.0 | 5 votes |
@NotNull @Override protected RunnerAndConfigurationSettings createRunnerAndConfigurationSettings( @NotNull Project project, @NotNull Module module, @NotNull Client client, @Nullable AndroidDebuggerState inputState) { String runConfigurationName = String.format( "%s %s Debugger (%d)", Blaze.getBuildSystem(project).getName(), getDisplayName(), client.getClientData().getPid()); RunnerAndConfigurationSettings runSettings = RunManager.getInstance(project) .createConfiguration( runConfigurationName, new BlazeAndroidNativeAttachConfigurationType.Factory()); BlazeAndroidNativeAttachConfiguration configuration = (BlazeAndroidNativeAttachConfiguration) runSettings.getConfiguration(); configuration.setClient(client); configuration.getAndroidDebuggerContext().setDebuggerType(getId()); configuration.getConfigurationModule().setModule(module); configuration.setConsoleProvider(getConsoleProvider()); // TODO(b/145707569): Copy debugger settings from inputState to state. See // NativeAndroidDebugger. AndroidDebuggerState state = configuration.getAndroidDebuggerContext().getAndroidDebuggerState(); if (state instanceof NativeAndroidDebuggerState) { NativeAndroidDebuggerState nativeState = (NativeAndroidDebuggerState) state; nativeState.setWorkingDir(WorkspaceRoot.fromProject(project).directory().getPath()); } return runSettings; }
Example #7
Source File: BlazeNativeAndroidDebugger.java From intellij with Apache License 2.0 | 5 votes |
@Override protected RunnerAndConfigurationSettings createRunnerAndConfigurationSettings( Project project, Module module, Client client) { RunnerAndConfigurationSettings runSettings = super.createRunnerAndConfigurationSettings(project, module, client); AndroidNativeAttachConfiguration configuration = (AndroidNativeAttachConfiguration) runSettings.getConfiguration(); AndroidDebuggerState state = configuration.getAndroidDebuggerContext().getAndroidDebuggerState(); if (state instanceof NativeAndroidDebuggerState) { NativeAndroidDebuggerState nativeState = (NativeAndroidDebuggerState) state; nativeState.setWorkingDir(WorkspaceRoot.fromProject(project).directory().getPath()); } return runSettings; }
Example #8
Source File: BlazeAutoAndroidDebugger.java From intellij with Apache License 2.0 | 5 votes |
@Override public void attachToClient(Project project, Client client) { if (isNativeProject(project)) { log.info("Project has native development enabled. Attaching native debugger."); nativeDebugger.attachToClient(project, client); } else { super.attachToClient(project, client); } }
Example #9
Source File: EmulatorDeviceNode.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private void updateKeys() { Set<ClientHolder> keys = new HashSet<>(); final Client[] clients = device.getClients(); for (Client client : clients) { keys.add(new ClientHolder(client)); } this.setKeys(keys); }
Example #10
Source File: BlazeNativeAndroidDebugger.java From intellij with Apache License 2.0 | 5 votes |
@NotNull @Override protected RunnerAndConfigurationSettings createRunnerAndConfigurationSettings( @NotNull Project project, @NotNull Module module, @NotNull Client client, @Nullable AndroidDebuggerState inputState) { String runConfigurationName = String.format( "%s %s Debugger (%d)", Blaze.getBuildSystem(project).getName(), getDisplayName(), client.getClientData().getPid()); RunnerAndConfigurationSettings runSettings = RunManager.getInstance(project) .createConfiguration( runConfigurationName, new BlazeAndroidNativeAttachConfigurationType.Factory()); BlazeAndroidNativeAttachConfiguration configuration = (BlazeAndroidNativeAttachConfiguration) runSettings.getConfiguration(); configuration.setClient(client); configuration.getAndroidDebuggerContext().setDebuggerType(getId()); configuration.getConfigurationModule().setModule(module); configuration.setConsoleProvider(getConsoleProvider()); // TODO(b/145707569): Copy debugger settings from inputState to state. See // NativeAndroidDebugger. AndroidDebuggerState state = configuration.getAndroidDebuggerContext().getAndroidDebuggerState(); if (state instanceof NativeAndroidDebuggerState) { NativeAndroidDebuggerState nativeState = (NativeAndroidDebuggerState) state; nativeState.setWorkingDir(WorkspaceRoot.fromProject(project).directory().getPath()); } return runSettings; }
Example #11
Source File: MobileDeviceNode.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private void updateKeys() { Set<ClientHolder> keys = new HashSet<ClientHolder>(); final Client[] clients = device.getClients(); for (Client client : clients) { keys.add(new ClientHolder(client)); } this.setKeys(keys); }
Example #12
Source File: BlazeAutoAndroidDebugger.java From intellij with Apache License 2.0 | 5 votes |
@Override public void attachToClient(Project project, Client client, RunConfiguration config) { if (isNativeProject(project)) { log.info("Project has native development enabled. Attaching native debugger."); nativeDebugger.attachToClient(project, client, config); } else { super.attachToClient(project, client, config); } }
Example #13
Source File: ConnectBlazeTestDebuggerTask.java From intellij with Apache License 2.0 | 5 votes |
/** * Wires up listeners to automatically reconnect the debugger for each test method. When you * `blaze test` an android_test in debug mode, it kills the instrumentation process between each * test method, disconnecting the debugger. We listen for the start of a new method waiting for a * debugger, and reconnect. TODO: Support stopping Blaze from the UI. This is hard because we have * no way to distinguish process handler termination/debug session ending initiated by the user. */ private void setUpForReattachingDebugger( String targetPackage, LaunchInfo launchInfo, ProcessHandlerLaunchStatus launchStatus, ProcessHandlerConsolePrinter printer) { final AndroidDebugBridge.IClientChangeListener reattachingListener = new AndroidDebugBridge.IClientChangeListener() { // The target application can either // 1. Match our target name, and become available for debugging. // 2. Be available for debugging, and suddenly have its name changed to match. static final int CHANGE_MASK = Client.CHANGE_DEBUGGER_STATUS | Client.CHANGE_NAME; @Override public void clientChanged(@NotNull Client client, int changeMask) { ClientData data = client.getClientData(); String clientDescription = data.getClientDescription(); if (clientDescription != null && clientDescription.equals(targetPackage) && (changeMask & CHANGE_MASK) != 0 && data.getDebuggerConnectionStatus().equals(ClientData.DebuggerStatus.WAITING)) { reattachDebugger(launchInfo, client, launchStatus, printer); } } }; AndroidDebugBridge.addClientChangeListener(reattachingListener); runContext.addLaunchTaskCompleteListener( () -> { AndroidDebugBridge.removeClientChangeListener(reattachingListener); launchStatus.terminateLaunch("Test run completed.\n", true); }); }
Example #14
Source File: ClientNode.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
@Override public void clientChanged(Client client, int eventType) { if (this.client.equals(client) && (eventType & (Client.CHANGE_INFO | Client.CHANGE_NAME)) != 0) { SwingUtilities.invokeLater(new Runnable() { public void run() { updateInfo(); firePropertySetsChange(null, null); } }); } }
Example #15
Source File: ConnectBlazeTestDebuggerTask.java From intellij with Apache License 2.0 | 5 votes |
private void reattachDebugger( LaunchInfo launchInfo, final Client client, ProcessHandlerLaunchStatus launchStatus, ProcessHandlerConsolePrinter printer) { ApplicationManager.getApplication() .invokeLater(() -> launchDebugger(launchInfo, client, launchStatus, printer)); }
Example #16
Source File: GradleDebugInfo.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
@Override public AndroidDebugInfo.AndroidDebugData data(Client client) { final int port = client.getDebuggerListenPort(); final Map<String, Object> properties = Maps.newHashMap(); final AndroidClassPathProvider cpp = project.getLookup().lookup(AndroidClassPathProvider.class); final ClassPath sourcePath = cpp.getSourcePath(); final ClassPath compilePath = cpp.getCompilePath(); final ClassPath bootPath = cpp.getBootPath(); properties.put("sourcepath", ClassPathSupport.createProxyClassPath(sourcePath, Launches.toSourcePath(compilePath))); properties.put("name", ProjectUtils.getInformation(project).getDisplayName()); // NOI18N properties.put("jdksources", Launches.toSourcePath(bootPath)); // NOI18N properties.put("baseDir", FileUtil.toFile(project.getProjectDirectory())); //NOI18N return new AndroidDebugInfo.AndroidDebugData("localhost", port, properties); }
Example #17
Source File: LogSourceManager.java From logviewer with Apache License 2.0 | 5 votes |
@Override public void clientChanged(Client client, int changeMask) { DeviceLogSource deviceLogSource = getDeviceSource(client.getDevice()); if (deviceLogSource != null && deviceLogSource == selectedSource && ((changeMask & Client.CHANGE_NAME) != 0)) { ((DeviceLogDataProvider) deviceLogSource.getLogProvider()).updateProcessList(); } }
Example #18
Source File: DeviceLogDataProvider.java From logviewer with Apache License 2.0 | 5 votes |
/** * Convert list of {@link Client} to list of {@link LogProcess} */ private Set<LogProcess> toLogProcess(List<Client> clientList) { Set<LogProcess> logProcesses = new HashSet<>(); for (Client client : clientList) { if (client != null) { logProcesses.add(new LogProcess(client)); } } return logProcesses; }
Example #19
Source File: ClientCellRenderer.java From logviewer with Apache License 2.0 | 5 votes |
public int compare(Client a, Client b) { ClientData ad = a.getClientData(); ClientData bd = b.getClientData(); String as = ad.getClientDescription() != null ? ad.getClientDescription() : String.valueOf(ad.getPid()); String bs = bd.getClientDescription() != null ? bd.getClientDescription() : String.valueOf(bd.getPid()); return as.compareTo(bs); }
Example #20
Source File: MobileDeviceNode.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
public ClientHolder(final Client client) { assert client != null; this.client = client; }
Example #21
Source File: ConnectBlazeTestDebuggerTask.java From intellij with Apache License 2.0 | 4 votes |
/** * Nearly a clone of {@link ConnectJavaDebuggerTask#launchDebugger}. There are a few changes to * account for null variables that could occur in our implementation. */ @Override public ProcessHandler launchDebugger( @NotNull LaunchInfo currentLaunchInfo, @NotNull Client client, @NotNull ProcessHandlerLaunchStatus launchStatus, @NotNull ProcessHandlerConsolePrinter printer) { String debugPort = Integer.toString(client.getDebuggerListenPort()); int pid = client.getClientData().getPid(); Logger.getInstance(ConnectJavaDebuggerTask.class) .info( String.format( Locale.US, "Attempting to connect debugger to port %1$s [client %2$d]", debugPort, pid)); // create a new process handler RemoteConnection connection = new RemoteConnection(true, "localhost", debugPort, false); RemoteDebugProcessHandler debugProcessHandler = new RemoteDebugProcessHandler(project); // switch the launch status and console printers to point to the new process handler // this is required, esp. for AndroidTestListener which holds a // reference to the launch status and printers, and those should // be updated to point to the new process handlers, // otherwise test results will not be forwarded appropriately ProcessHandler oldProcessHandler = launchStatus.getProcessHandler(); launchStatus.setProcessHandler(debugProcessHandler); printer.setProcessHandler(debugProcessHandler); // Detach old process handler after the launch status // has been updated to point to the new process handler. oldProcessHandler.detachProcess(); AndroidDebugState debugState = new AndroidDebugState( project, debugProcessHandler, connection, currentLaunchInfo.consoleProvider); RunContentDescriptor oldDescriptor; AndroidSessionInfo oldSession = oldProcessHandler.getUserData(AndroidSessionInfo.KEY); if (oldSession != null) { oldDescriptor = oldSession.getDescriptor(); } else { // This is the first time we are attaching the debugger; get it from the environment instead. oldDescriptor = currentLaunchInfo.env.getContentToReuse(); } RunContentDescriptor debugDescriptor; try { // @formatter:off ExecutionEnvironment debugEnv = new ExecutionEnvironmentBuilder(currentLaunchInfo.env) .executor(currentLaunchInfo.executor) .runner(currentLaunchInfo.runner) .contentToReuse(oldDescriptor) .build(); debugDescriptor = DebuggerPanelsManager.getInstance(project) .attachVirtualMachine(debugEnv, debugState, connection, false); // @formatter:on } catch (ExecutionException e) { printer.stderr("ExecutionException: " + e.getMessage() + '.'); return null; } // Based on the above try block we shouldn't get here unless we have assigned to debugDescriptor assert debugDescriptor != null; // re-run the collected text from the old process handler to the new // TODO: is there a race between messages received once the debugger has been connected, // and these messages that are printed out? final AndroidProcessText oldText = AndroidProcessText.get(oldProcessHandler); if (oldText != null) { oldText.printTo(debugProcessHandler); } RunProfile runProfile = currentLaunchInfo.env.getRunProfile(); RunConfiguration runConfiguration = runProfile instanceof AndroidRunConfiguration ? (AndroidRunConfiguration) runProfile : null; AndroidSessionInfo sessionInfo = AndroidSessionInfo.create( debugProcessHandler, debugDescriptor, runConfiguration, currentLaunchInfo.env.getExecutor().getId(), currentLaunchInfo.env.getExecutor().getActionName(), currentLaunchInfo.env.getExecutionTarget()); debugProcessHandler.putUserData(AndroidSessionInfo.KEY, sessionInfo); debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEBUG_CLIENT, client); debugProcessHandler.putUserData( AndroidSessionInfo.ANDROID_DEVICE_API_LEVEL, client.getDevice().getVersion()); return debugProcessHandler; }
Example #22
Source File: TestDevice.java From buck with Apache License 2.0 | 4 votes |
@Override public Client[] getClients() { throw new UnsupportedOperationException(); }
Example #23
Source File: TestDevice.java From buck with Apache License 2.0 | 4 votes |
@Override public Client getClient(String s) { throw new UnsupportedOperationException(); }
Example #24
Source File: EmulatorDeviceNode.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
public ClientHolder(final Client client) { assert client != null; this.client = client; }
Example #25
Source File: FlyingGetClientWindowsTask.java From LayoutMaster with Apache License 2.0 | 4 votes |
public FlyingGetClientWindowsTask(final Project project, final Client client) { super(project, "Flying Obtaining Windows"); this.client = client; }
Example #26
Source File: ClientNode.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override protected boolean enable(Node[] activatedNodes) { return activatedNodes.length == 1 && activatedNodes[0].getLookup().lookup(Client.class) != null; }
Example #27
Source File: ClientNode.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override protected boolean enable(Node[] activatedNodes) { return activatedNodes.length == 1 && activatedNodes[0].getLookup().lookup(Client.class) != null; }
Example #28
Source File: GradleLaunchExecutor.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
public void doLaunchAfterBuild(final String command, File output, File manifestFile) { if (!Launches.isLaunchingCommand(command)) { return; } // TODO(radim): where to get config final LaunchConfiguration launchConfig = launchConfig(); // project.getLookup().lookup(AndroidConfigProvider.class).getActiveConfiguration().getLaunchConfiguration(); final AndroidLauncher launcher = Preconditions.checkNotNull( project.getLookup().lookup(AndroidLauncher.class)); final LaunchInfo launchInfo = createLaunchInfo(manifestFile, output, command, launchConfig); final LaunchAction launchAction = findLaunchAction(command); if (!Launches.isDebugCommand(command)) { launcher.launch( Lookups.fixed(launchInfo, launchAction, launchConfig, project, Launches.getActivityConfiguration(command, project)), command); } else { final Future<Client> future = launcher.launch( Lookups.fixed(launchInfo, launchAction, launchConfig, project, Launches.getActivityConfiguration(command, project)), command); if (future != null) { Client c = null; try { c = future.get(20, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException interruptedException) { Exceptions.printStackTrace(interruptedException); } if (c != null) { final int port = c.getDebuggerListenPort(); final Map<String, Object> properties = Maps.newHashMap(); final AndroidClassPathProvider cpp = project.getLookup().lookup(AndroidClassPathProvider.class); final ClassPath sourcePath = cpp.getSourcePath(); final ClassPath compilePath = cpp.getCompilePath(); final ClassPath bootPath = cpp.getBootPath(); properties.put("sourcepath", ClassPathSupport.createProxyClassPath(sourcePath, Launches.toSourcePath(compilePath))); properties.put("name", ProjectUtils.getInformation(project).getDisplayName()); // NOI18N properties.put("jdksources", Launches.toSourcePath(bootPath)); // NOI18N properties.put("baseDir", FileUtil.toFile(project.getProjectDirectory())); //NOI18N try { JPDADebugger.attach("localhost", port, new Object[]{properties}); //NOI18N } catch (DebuggerStartException ex) { Exceptions.printStackTrace(ex); } } else { NotifyDescriptor nd = new NotifyDescriptor.Message("Unable to get Android Client Info ", NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notifyLater(nd); } } } }
Example #29
Source File: LogProcess.java From logviewer with Apache License 2.0 | 4 votes |
public LogProcess(Client client) { ClientData cd = client.getClientData(); setProcessName(cd.getClientDescription()); setProcessID(cd.getPid()); }
Example #30
Source File: FlyingLayoutInspectorCaptureTask.java From LayoutMaster with Apache License 2.0 | 4 votes |
public FlyingLayoutInspectorCaptureTask(@NotNull Project project, @NotNull Client client, @NotNull ClientWindow window) { super(project, "Capturing View Hierarchy"); myClient = client; myWindow = window; }