From 8fa7b0b60f9718209f8827767fa71b277faf8cec Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 26 Nov 2023 21:36:59 +0530 Subject: feat: remove Leak Canary This mostly ends up spamming about Autofill leaks in the framework --- app/build.gradle.kts | 3 +- .../passwordstore/util/leaks/SentryLeakUploader.kt | 8 --- app/src/main/java/app/passwordstore/Application.kt | 9 --- .../passwordstore/util/leaks/SentryLeakUploader.kt | 67 ---------------------- 4 files changed, 1 insertion(+), 86 deletions(-) delete mode 100644 app/src/free/java/app/passwordstore/util/leaks/SentryLeakUploader.kt delete mode 100644 app/src/nonFree/java/app/passwordstore/util/leaks/SentryLeakUploader.kt (limited to 'app') diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9a469213..2bef7d22 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -85,7 +85,7 @@ dependencies { implementation(libs.thirdparty.kotlinResult) implementation(libs.thirdparty.logcat) implementation(libs.thirdparty.modernAndroidPrefs) - implementation(libs.thirdparty.plumber) + implementation(libs.thirdparty.leakcanary.plumber) implementation(libs.thirdparty.sshj) implementation(libs.thirdparty.bouncycastle.bcprov) @@ -99,7 +99,6 @@ dependencies { 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.sentry) freeImplementation(projects.sentryStub) diff --git a/app/src/free/java/app/passwordstore/util/leaks/SentryLeakUploader.kt b/app/src/free/java/app/passwordstore/util/leaks/SentryLeakUploader.kt deleted file mode 100644 index 4b59b9f7..00000000 --- a/app/src/free/java/app/passwordstore/util/leaks/SentryLeakUploader.kt +++ /dev/null @@ -1,8 +0,0 @@ -package app.passwordstore.util.leaks - -import leakcanary.EventListener - -object SentryLeakUploader : EventListener { - - override fun onEvent(event: EventListener.Event) {} -} diff --git a/app/src/main/java/app/passwordstore/Application.kt b/app/src/main/java/app/passwordstore/Application.kt index 279c6af0..b685ebb7 100644 --- a/app/src/main/java/app/passwordstore/Application.kt +++ b/app/src/main/java/app/passwordstore/Application.kt @@ -14,7 +14,6 @@ import app.passwordstore.util.extensions.getString import app.passwordstore.util.features.Feature import app.passwordstore.util.features.Features import app.passwordstore.util.git.sshj.setUpBouncyCastleForSshj -import app.passwordstore.util.leaks.SentryLeakUploader import app.passwordstore.util.proxy.ProxyUtils import app.passwordstore.util.settings.GitSettings import app.passwordstore.util.settings.PreferenceKeys @@ -25,8 +24,6 @@ import io.sentry.Sentry import io.sentry.protocol.User import java.util.concurrent.Executors import javax.inject.Inject -import leakcanary.AppWatcher -import leakcanary.LeakCanary import logcat.AndroidLogcatLogger import logcat.LogPriority.DEBUG import logcat.LogPriority.VERBOSE @@ -46,18 +43,12 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere override fun onCreate() { super.onCreate() instance = this - val eventListeners = LeakCanary.config.eventListeners + SentryLeakUploader if ( BuildConfig.ENABLE_DEBUG_FEATURES || prefs.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false) ) { LogcatLogger.install(AndroidLogcatLogger(DEBUG)) 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) setNightMode() diff --git a/app/src/nonFree/java/app/passwordstore/util/leaks/SentryLeakUploader.kt b/app/src/nonFree/java/app/passwordstore/util/leaks/SentryLeakUploader.kt deleted file mode 100644 index d8889350..00000000 --- a/app/src/nonFree/java/app/passwordstore/util/leaks/SentryLeakUploader.kt +++ /dev/null @@ -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() - 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 - ) { - leakContexts["heapDumpPath"] = heapAnalysis.heapDumpFile.absolutePath - heapAnalysis.metadata.forEach { (key, value) -> leakContexts[key] = value } - leakContexts["analysisDurationMs"] = heapAnalysis.analysisDurationMillis - } - - private fun addLeak(leak: Leak, leakContexts: MutableMap) { - 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) { - leakTrace.retainedHeapByteSize?.let { leakContexts["retainedHeapByteSize"] = it } - leakContexts["signature"] = leakTrace.signature - leakContexts["leakTrace"] = leakTrace.toString() - } - - class FakeReportingException(message: String) : RuntimeException(message) -} -- cgit v1.2.3