Search in sources :

Example 1 with FutureResult

use of com.squareup.leakcanary.internal.FutureResult in project leakcanary by square.

the class AndroidHeapDumper method dumpHeap.

@Override
public File dumpHeap() {
    File heapDumpFile = leakDirectoryProvider.newHeapDumpFile();
    if (heapDumpFile == RETRY_LATER) {
        return RETRY_LATER;
    }
    FutureResult<Toast> waitingForToast = new FutureResult<>();
    showToast(waitingForToast);
    if (!waitingForToast.wait(5, SECONDS)) {
        CanaryLog.d("Did not dump heap, too much time waiting for Toast.");
        return RETRY_LATER;
    }
    Toast toast = waitingForToast.get();
    try {
        Debug.dumpHprofData(heapDumpFile.getAbsolutePath());
        cancelToast(toast);
        return heapDumpFile;
    } catch (Exception e) {
        CanaryLog.d(e, "Could not dump heap");
        // Abort heap dump
        return RETRY_LATER;
    }
}
Also used : FutureResult(com.squareup.leakcanary.internal.FutureResult) Toast(android.widget.Toast) File(java.io.File)

Aggregations

Toast (android.widget.Toast)1 FutureResult (com.squareup.leakcanary.internal.FutureResult)1 File (java.io.File)1