feat: remove Leak Canary

This mostly ends up spamming about Autofill leaks in the framework
This commit is contained in:
Harsh Shandilya 2023-11-26 21:36:59 +05:30
parent dd01fc78a0
commit 8fa7b0b60f
No known key found for this signature in database
5 changed files with 2 additions and 89 deletions

View file

@ -85,7 +85,7 @@ dependencies {
implementation(libs.thirdparty.kotlinResult) implementation(libs.thirdparty.kotlinResult)
implementation(libs.thirdparty.logcat) implementation(libs.thirdparty.logcat)
implementation(libs.thirdparty.modernAndroidPrefs) implementation(libs.thirdparty.modernAndroidPrefs)
implementation(libs.thirdparty.plumber) implementation(libs.thirdparty.leakcanary.plumber)
implementation(libs.thirdparty.sshj) implementation(libs.thirdparty.sshj)
implementation(libs.thirdparty.bouncycastle.bcprov) implementation(libs.thirdparty.bouncycastle.bcprov)
@ -99,7 +99,6 @@ dependencies {
because("SSHJ now uses SLF4J 2.0 which we don't want") because("SSHJ now uses SLF4J 2.0 which we don't want")
} }
implementation(libs.thirdparty.leakcanary.core)
nonFreeImplementation(libs.thirdparty.nonfree.googlePlayAuthApiPhone) nonFreeImplementation(libs.thirdparty.nonfree.googlePlayAuthApiPhone)
nonFreeImplementation(libs.thirdparty.nonfree.sentry) nonFreeImplementation(libs.thirdparty.nonfree.sentry)
freeImplementation(projects.sentryStub) freeImplementation(projects.sentryStub)

View file

@ -1,8 +0,0 @@
package app.passwordstore.util.leaks
import leakcanary.EventListener
object SentryLeakUploader : EventListener {
override fun onEvent(event: EventListener.Event) {}
}

View file

@ -14,7 +14,6 @@ import app.passwordstore.util.extensions.getString
import app.passwordstore.util.features.Feature import app.passwordstore.util.features.Feature
import app.passwordstore.util.features.Features import app.passwordstore.util.features.Features
import app.passwordstore.util.git.sshj.setUpBouncyCastleForSshj import app.passwordstore.util.git.sshj.setUpBouncyCastleForSshj
import app.passwordstore.util.leaks.SentryLeakUploader
import app.passwordstore.util.proxy.ProxyUtils import app.passwordstore.util.proxy.ProxyUtils
import app.passwordstore.util.settings.GitSettings import app.passwordstore.util.settings.GitSettings
import app.passwordstore.util.settings.PreferenceKeys import app.passwordstore.util.settings.PreferenceKeys
@ -25,8 +24,6 @@ import io.sentry.Sentry
import io.sentry.protocol.User import io.sentry.protocol.User
import java.util.concurrent.Executors import java.util.concurrent.Executors
import javax.inject.Inject import javax.inject.Inject
import leakcanary.AppWatcher
import leakcanary.LeakCanary
import logcat.AndroidLogcatLogger import logcat.AndroidLogcatLogger
import logcat.LogPriority.DEBUG import logcat.LogPriority.DEBUG
import logcat.LogPriority.VERBOSE import logcat.LogPriority.VERBOSE
@ -46,18 +43,12 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
instance = this instance = this
val eventListeners = LeakCanary.config.eventListeners + SentryLeakUploader
if ( if (
BuildConfig.ENABLE_DEBUG_FEATURES || BuildConfig.ENABLE_DEBUG_FEATURES ||
prefs.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false) prefs.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false)
) { ) {
LogcatLogger.install(AndroidLogcatLogger(DEBUG)) LogcatLogger.install(AndroidLogcatLogger(DEBUG))
setVmPolicy() setVmPolicy()
AppWatcher.manualInstall(this)
LeakCanary.config = LeakCanary.config.copy(dumpHeap = true, eventListeners = eventListeners)
LeakCanary.showLeakDisplayActivityLauncherIcon(true)
} else {
LeakCanary.config = LeakCanary.config.copy(dumpHeap = false, eventListeners = eventListeners)
} }
prefs.registerOnSharedPreferenceChangeListener(this) prefs.registerOnSharedPreferenceChangeListener(this)
setNightMode() setNightMode()

View file

@ -1,67 +0,0 @@
package app.passwordstore.util.leaks
import io.sentry.Sentry
import io.sentry.SentryEvent
import leakcanary.EventListener
import leakcanary.EventListener.Event
import shark.HeapAnalysisSuccess
import shark.Leak
import shark.LeakTrace
import shark.LibraryLeak
object SentryLeakUploader : EventListener {
override fun onEvent(event: Event) {
when (event) {
is Event.HeapAnalysisDone<*> -> {
if (event.heapAnalysis !is HeapAnalysisSuccess) return
val heapAnalysis = event.heapAnalysis as HeapAnalysisSuccess
val allLeakTraces =
heapAnalysis.allLeaks.toList().flatMap { leak ->
leak.leakTraces.map { leakTrace -> leak to leakTrace }
}
allLeakTraces.forEach { (leak, leakTrace) ->
val exception = FakeReportingException(leak.shortDescription)
val sentryEvent =
SentryEvent(exception).apply {
val leakContexts = mutableMapOf<String, Any>()
addHeapAnalysis(heapAnalysis, leakContexts)
addLeak(leak, leakContexts)
addLeakTrace(leakTrace, leakContexts)
contexts["Leak"] = leakContexts
// grouping leaks
fingerprints = listOf(leak.signature)
}
Sentry.captureEvent(sentryEvent)
}
}
else -> {}
}
}
private fun addHeapAnalysis(
heapAnalysis: HeapAnalysisSuccess,
leakContexts: MutableMap<String, Any>
) {
leakContexts["heapDumpPath"] = heapAnalysis.heapDumpFile.absolutePath
heapAnalysis.metadata.forEach { (key, value) -> leakContexts[key] = value }
leakContexts["analysisDurationMs"] = heapAnalysis.analysisDurationMillis
}
private fun addLeak(leak: Leak, leakContexts: MutableMap<String, Any>) {
leakContexts["libraryLeak"] = leak is LibraryLeak
if (leak is LibraryLeak) {
leakContexts["libraryLeakPattern"] = leak.pattern.toString()
leakContexts["libraryLeakDescription"] = leak.description
}
}
private fun addLeakTrace(leakTrace: LeakTrace, leakContexts: MutableMap<String, Any>) {
leakTrace.retainedHeapByteSize?.let { leakContexts["retainedHeapByteSize"] = it }
leakContexts["signature"] = leakTrace.signature
leakContexts["leakTrace"] = leakTrace.toString()
}
class FakeReportingException(message: String) : RuntimeException(message)
}

View file

@ -10,7 +10,6 @@ flowbinding = "1.2.0"
hilt = "2.48.1" hilt = "2.48.1"
kotlin = "1.9.20" kotlin = "1.9.20"
kotlinResult = "1.1.18" kotlinResult = "1.1.18"
leakcanary = "2.12"
lifecycle = "2.6.2" lifecycle = "2.6.2"
[libraries] [libraries]
@ -84,13 +83,12 @@ thirdparty-flowbinding-android = { module = "io.github.reactivecircus.flowbindin
thirdparty-jgit = "org.eclipse.jgit:org.eclipse.jgit:3.7.1.201504261725-r" thirdparty-jgit = "org.eclipse.jgit:org.eclipse.jgit:3.7.1.201504261725-r"
thirdparty-kotlinResult = { module = "com.michael-bull.kotlin-result:kotlin-result", version.ref = "kotlinResult" } thirdparty-kotlinResult = { module = "com.michael-bull.kotlin-result:kotlin-result", version.ref = "kotlinResult" }
thirdparty-kotlinResult-coroutines = { module = "com.michael-bull.kotlin-result:kotlin-result-coroutines", version.ref = "kotlinResult" } thirdparty-kotlinResult-coroutines = { module = "com.michael-bull.kotlin-result:kotlin-result-coroutines", version.ref = "kotlinResult" }
thirdparty-leakcanary-core = { module = "com.squareup.leakcanary:leakcanary-android-core", version.ref = "leakcanary" } thirdparty-leakcanary-plumber = "com.squareup.leakcanary:plumber-android-startup:2.12"
thirdparty-logcat = "com.squareup.logcat:logcat:0.1" thirdparty-logcat = "com.squareup.logcat:logcat:0.1"
thirdparty-modernAndroidPrefs = "de.maxr1998:modernandroidpreferences:2.3.2" thirdparty-modernAndroidPrefs = "de.maxr1998:modernandroidpreferences:2.3.2"
thirdparty-nonfree-googlePlayAuthApiPhone = "com.google.android.gms:play-services-auth-api-phone:18.0.1" thirdparty-nonfree-googlePlayAuthApiPhone = "com.google.android.gms:play-services-auth-api-phone:18.0.1"
thirdparty-nonfree-sentry = "io.sentry:sentry-android:6.34.0" thirdparty-nonfree-sentry = "io.sentry:sentry-android:6.34.0"
thirdparty-pgpainless = "org.pgpainless:pgpainless-core:1.6.3" thirdparty-pgpainless = "org.pgpainless:pgpainless-core:1.6.3"
thirdparty-plumber = { module = "com.squareup.leakcanary:plumber-android-startup", version.ref = "leakcanary" }
thirdparty-slack-lints = "com.slack.lint:slack-lint-checks:0.7.0" thirdparty-slack-lints = "com.slack.lint:slack-lint-checks:0.7.0"
thirdparty-slf4j-api = { module = "org.slf4j:slf4j-api", version = { strictly = "[1.7, 1.8[", prefer = "1.7.36" } } thirdparty-slf4j-api = { module = "org.slf4j:slf4j-api", version = { strictly = "[1.7, 1.8[", prefer = "1.7.36" } }
thirdparty-sshj = "com.hierynomus:sshj:0.37.0" thirdparty-sshj = "com.hierynomus:sshj:0.37.0"