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);
}
}
});
}
Aggregations