package com.squareup.leakcanary; import android.app.PendingIntent; import android.os.SystemClock; import android.text.format.Formatter; import com.squareup.leakcanary.internal.DisplayLeakActivity; import com.squareup.leakcanary.internal.LeakCanaryInternals; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; /* loaded from: classes.dex */ public class DisplayLeakService extends AbstractAnalysisResultService { private HeapDump renameHeapdump(HeapDump heapDump) { File file = new File(heapDump.heapDumpFile.getParent(), new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss_SSS'.hprof'", Locale.US).format(new Date())); if (!heapDump.heapDumpFile.renameTo(file)) { CanaryLog.d("Could not rename heap dump file %s to %s", heapDump.heapDumpFile.getPath(), file.getPath()); } return heapDump.buildUpon().heapDumpFile(file).build(); } private boolean saveResult(HeapDump heapDump, AnalysisResult analysisResult) { return AnalyzedHeap.save(heapDump, analysisResult) != null; } private void showNotification(PendingIntent pendingIntent, String str, String str2) { LeakCanaryInternals.showNotification(this, str, str2, pendingIntent, (int) (SystemClock.uptimeMillis() / 1000)); } protected void afterDefaultHandling(HeapDump heapDump, AnalysisResult analysisResult, String str) { } @Override // com.squareup.leakcanary.AbstractAnalysisResultService protected final void onAnalysisResultFailure(String str) { super.onAnalysisResultFailure(str); showNotification(null, getString(R.string.leak_canary_result_failure_title), str); } @Override // com.squareup.leakcanary.AbstractAnalysisResultService protected final void onHeapAnalyzed(AnalyzedHeap analyzedHeap) { String string; HeapDump heapDump = analyzedHeap.heapDump; AnalysisResult analysisResult = analyzedHeap.result; String leakInfo = LeakCanary.leakInfo(this, heapDump, analysisResult, true); CanaryLog.d("%s", leakInfo); HeapDump renameHeapdump = renameHeapdump(heapDump); if (saveResult(renameHeapdump, analysisResult)) { PendingIntent createPendingIntent = DisplayLeakActivity.createPendingIntent(this, renameHeapdump.referenceKey); if (analysisResult.failure != null) { string = getString(R.string.leak_canary_analysis_failed); } else { String classSimpleName = LeakCanaryInternals.classSimpleName(analysisResult.className); if (analysisResult.leakFound) { long j = analysisResult.retainedHeapSize; if (j == -1) { string = analysisResult.excludedLeak ? getString(R.string.leak_canary_leak_excluded, new Object[]{classSimpleName}) : getString(R.string.leak_canary_class_has_leaked, new Object[]{classSimpleName}); } else { String formatShortFileSize = Formatter.formatShortFileSize(this, j); string = analysisResult.excludedLeak ? getString(R.string.leak_canary_leak_excluded_retaining, new Object[]{classSimpleName, formatShortFileSize}) : getString(R.string.leak_canary_class_has_leaked_retaining, new Object[]{classSimpleName, formatShortFileSize}); } } else { string = getString(R.string.leak_canary_class_no_leak, new Object[]{classSimpleName}); } } showNotification(createPendingIntent, string, getString(R.string.leak_canary_notification_message)); } else { onAnalysisResultFailure(getString(R.string.leak_canary_could_not_save_text)); } afterDefaultHandling(renameHeapdump, analysisResult, leakInfo); } }