Search in sources :

Example 1 with IClientChangeListener

use of com.android.ddmlib.AndroidDebugBridge.IClientChangeListener in project android by JetBrains.

the class ToggleAllocationTrackingAction method installListener.

private void installListener(@NotNull final Client listeningClient, @NotNull final Project project) {
    AndroidDebugBridge.addClientChangeListener(new IClientChangeListener() {

        @Override
        public void clientChanged(Client client, int changeMask) {
            if (client == listeningClient && (changeMask & Client.CHANGE_HEAP_ALLOCATIONS) != 0) {
                final byte[] data = client.getClientData().getAllocationsData();
                ApplicationManager.getApplication().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            if (myProject.isDisposed()) {
                                return;
                            }
                            final CaptureService service = CaptureService.getInstance(myProject);
                            String name = service.getSuggestedName(listeningClient);
                            CaptureHandle handle = service.startCaptureFile(AllocationCaptureType.class, name, true);
                            service.appendDataCopy(handle, data);
                            service.finalizeCaptureFileAsynchronous(handle, new FutureCallback<Capture>() {

                                @Override
                                public void onSuccess(Capture result) {
                                    service.notifyCaptureReady(result);
                                }

                                @Override
                                public void onFailure(Throwable t) {
                                    throw new RuntimeException(t);
                                }
                            }, EdtExecutor.INSTANCE);
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
                // Remove self from listeners.
                AndroidDebugBridge.removeClientChangeListener(this);
            }
        }
    });
}
Also used : CaptureService(com.android.tools.idea.profiling.capture.CaptureService) IOException(java.io.IOException) Capture(com.android.tools.idea.profiling.capture.Capture) IClientChangeListener(com.android.ddmlib.AndroidDebugBridge.IClientChangeListener) CaptureHandle(com.android.tools.idea.profiling.capture.CaptureHandle) Client(com.android.ddmlib.Client)

Aggregations

IClientChangeListener (com.android.ddmlib.AndroidDebugBridge.IClientChangeListener)1 Client (com.android.ddmlib.Client)1 Capture (com.android.tools.idea.profiling.capture.Capture)1 CaptureHandle (com.android.tools.idea.profiling.capture.CaptureHandle)1 CaptureService (com.android.tools.idea.profiling.capture.CaptureService)1 IOException (java.io.IOException)1