feat(leakcanary): migrate to manual initialization

This commit is contained in:
Harsh Shandilya 2022-12-03 17:46:51 +05:30
parent 8e3b4422a9
commit 9156a81ad7
No known key found for this signature in database
3 changed files with 9 additions and 4 deletions

View file

@ -108,7 +108,7 @@ dependencies {
debugImplementation(libs.thirdparty.whatthestack) debugImplementation(libs.thirdparty.whatthestack)
} }
debugImplementation(libs.thirdparty.leakcanary) 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

@ -7,7 +7,6 @@ package app.passwordstore
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Build import android.os.Build
import android.os.StrictMode import android.os.StrictMode
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.AppCompatDelegate.* import androidx.appcompat.app.AppCompatDelegate.*
import app.passwordstore.injection.context.FilesDirPath import app.passwordstore.injection.context.FilesDirPath
import app.passwordstore.injection.prefs.SettingsPreferences import app.passwordstore.injection.prefs.SettingsPreferences
@ -15,6 +14,7 @@ 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,6 +25,8 @@ 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
@ -44,11 +46,14 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
instance = this instance = this
LeakCanary.config =
LeakCanary.config.copy(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))
AppWatcher.manualInstall(this)
setVmPolicy() setVmPolicy()
} }
prefs.registerOnSharedPreferenceChangeListener(this) prefs.registerOnSharedPreferenceChangeListener(this)
@ -117,7 +122,7 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
} }
private fun setNightMode() { private fun setNightMode() {
AppCompatDelegate.setDefaultNightMode( setDefaultNightMode(
when (prefs.getString(PreferenceKeys.APP_THEME) ?: getString(R.string.app_theme_def)) { when (prefs.getString(PreferenceKeys.APP_THEME) ?: getString(R.string.app_theme_def)) {
"light" -> MODE_NIGHT_NO "light" -> MODE_NIGHT_NO
"dark" -> MODE_NIGHT_YES "dark" -> MODE_NIGHT_YES

View file

@ -83,7 +83,7 @@ thirdparty-fastscroll = "me.zhanghai.android.fastscroll:library:1.1.8"
thirdparty-flowbinding-android = { module = "io.github.reactivecircus.flowbinding:flowbinding-android", version.ref = "flowbinding" } thirdparty-flowbinding-android = { module = "io.github.reactivecircus.flowbinding:flowbinding-android", version.ref = "flowbinding" }
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 = "com.michael-bull.kotlin-result:kotlin-result:1.1.16" thirdparty-kotlinResult = "com.michael-bull.kotlin-result:kotlin-result:1.1.16"
thirdparty-leakcanary = { module = "com.squareup.leakcanary:leakcanary-android-startup", version.ref = "leakcanary" } thirdparty-leakcanary-core = { module = "com.squareup.leakcanary:leakcanary-android-core", version.ref = "leakcanary" }
thirdparty-logcat = "com.squareup.logcat:logcat:0.1" thirdparty-logcat = "com.squareup.logcat:logcat:0.1"
thirdparty-modernAndroidPrefs = "de.maxr1998:modernandroidpreferences:2.3.1" thirdparty-modernAndroidPrefs = "de.maxr1998:modernandroidpreferences:2.3.1"
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"