Created
November 16, 2018 14:43
-
-
Save MikeFot/735c9e7adbaede041d91b716a97864c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.crashlytics.android.Crashlytics | |
import com.squareup.leakcanary.AnalysisResult | |
import com.squareup.leakcanary.DisplayLeakService | |
import com.squareup.leakcanary.HeapDump | |
import io.fabric.sdk.android.Fabric | |
import timber.log.Timber | |
class LeakUploadService : DisplayLeakService() { | |
override fun afterDefaultHandling( | |
heapDump: HeapDump, | |
result: AnalysisResult, | |
leakInfo: String | |
) { | |
if (!result.leakFound || result.excludedLeak) { | |
return | |
} | |
if (result.leakFound) { | |
uploadLeakToServer(result) | |
} | |
} | |
private fun uploadLeakToServer(result: AnalysisResult) { | |
if (Fabric.isInitialized()) { | |
val exception = result.leakTraceAsFakeException() | |
Timber.d("Logging leak exception to Crashlytics ${exception.hashCode()}") | |
Crashlytics.logException(exception) | |
} | |
} | |
} |
Author
MikeFot
commented
Nov 16, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment