/** * Called after a heap dump is analyzed, whether or not a leak was found. * In {@link AnalyzedHeap#result} check {@link AnalysisResult#leakFound} and {@link * AnalysisResult#excludedLeak} to see if there was a leak and if it can be ignored. * <p> * This will be called from a background intent service thread. * <p> * It's OK to block here and wait for the heap dump to be uploaded. * <p> * The analyzed heap file and heap dump file will be deleted immediately after this callback * returns. */ protected void onHeapAnalyzed(@NonNull AnalyzedHeap analyzedHeap) { onHeapAnalyzed(analyzedHeap.heapDump, analyzedHeap.result); }
@Override protected final void onHandleIntentInForeground(@Nullable Intent intent) { if (intent == null) { CanaryLog.d("AbstractAnalysisResultService received a null intent, ignoring."); return; } if (!intent.hasExtra(ANALYZED_HEAP_PATH_EXTRA)) { onAnalysisResultFailure(getString(R.string.leak_canary_result_failure_no_disk_space)); return; } File analyzedHeapFile = new File(intent.getStringExtra(ANALYZED_HEAP_PATH_EXTRA)); AnalyzedHeap analyzedHeap = AnalyzedHeap.load(analyzedHeapFile); if (analyzedHeap == null) { onAnalysisResultFailure(getString(R.string.leak_canary_result_failure_no_file)); return; } try { onHeapAnalyzed(analyzedHeap); } finally { //noinspection ResultOfMethodCallIgnored analyzedHeap.heapDump.heapDumpFile.delete(); //noinspection ResultOfMethodCallIgnored analyzedHeap.selfFile.delete(); } }
@Override protected final void onHandleIntent(Intent intent) { HeapDump heapDump = (HeapDump) intent.getSerializableExtra(HEAP_DUMP_EXTRA); AnalysisResult result = (AnalysisResult) intent.getSerializableExtra(RESULT_EXTRA); try { onHeapAnalyzed(heapDump, result); } finally { //noinspection ResultOfMethodCallIgnored heapDump.heapDumpFile.delete(); } }