From d583b937b72466423223e148ee7065cf1a7a60bf Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 20 Feb 2023 10:29:00 +0100 Subject: [PATCH] fix: Fixed acra bug reporting. --- .../apps/readerforselfossv2/android/MyApp.kt | 1 + .../apps/readerforselfossv2/DI/modules.kt | 1 - .../service/ACRASettings.kt | 70 +++++++++++++++++++ .../service/AppSettingsService.kt | 4 +- 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/ACRASettings.kt diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt index 26149ac..a4a4d38 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt @@ -34,6 +34,7 @@ import org.kodein.di.* class MyApp : MultiDexApplication(), DIAware { override val di by DI.lazy { + bind() with singleton { AppSettingsService(ACRA.isACRASenderServiceProcess()) } import(networkModule) bind() with singleton { DriverFactory(applicationContext) } bind() with singleton { ReaderForSelfossDB(driverFactory.createDriver()) } diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/DI/modules.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/DI/modules.kt index 170dc2f..e7c2a2b 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/DI/modules.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/DI/modules.kt @@ -9,7 +9,6 @@ import org.kodein.di.instance import org.kodein.di.singleton val networkModule by DI.Module { - bind() with singleton { AppSettingsService() } bind() with singleton { SelfossApi(instance()) } bind() with singleton { MercuryApi() } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/ACRASettings.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/ACRASettings.kt new file mode 100644 index 0000000..ec0b3d4 --- /dev/null +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/ACRASettings.kt @@ -0,0 +1,70 @@ +package bou.amine.apps.readerforselfossv2.service + +import com.russhwolf.settings.Settings + +// This will be used in ACRA process. For now, it does nothing. +// This is to fix ACRA not sending reports anymore. +// See https://www.acra.ch/docs/Troubleshooting-Guide#applicationoncreate +class ACRASettings : Settings { + override val keys: Set = emptySet() + override val size: Int = 0 + + override fun clear() { + // Nothing + } + + override fun getBoolean(key: String, defaultValue: Boolean): Boolean = false + + override fun getBooleanOrNull(key: String): Boolean? = null + + override fun getDouble(key: String, defaultValue: Double): Double = 0.0 + + override fun getDoubleOrNull(key: String): Double? = null + + override fun getFloat(key: String, defaultValue: Float): Float = 0.0F + + override fun getFloatOrNull(key: String): Float? = null + + override fun getInt(key: String, defaultValue: Int): Int = 0 + + override fun getIntOrNull(key: String): Int? = null + + override fun getLong(key: String, defaultValue: Long): Long = 0 + + override fun getLongOrNull(key: String): Long? = null + + override fun getString(key: String, defaultValue: String): String = "0" + + override fun getStringOrNull(key: String): String? = null + + override fun hasKey(key: String): Boolean = false + + override fun putBoolean(key: String, value: Boolean) { + // Nothing + } + + override fun putDouble(key: String, value: Double) { + // Nothing + } + + override fun putFloat(key: String, value: Float) { + // Nothing + } + + override fun putInt(key: String, value: Int) { + // Nothing + } + + override fun putLong(key: String, value: Long) { + // Nothing + } + + override fun putString(key: String, value: String) { + // Nothing + } + + override fun remove(key: String) { + // Nothing + } + +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt index 35716a9..9699f97 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/AppSettingsService.kt @@ -2,8 +2,8 @@ package bou.amine.apps.readerforselfossv2.service import com.russhwolf.settings.Settings -class AppSettingsService { - val settings: Settings = Settings() +class AppSettingsService(acraSenderServiceProcess: Boolean = false) { + val settings: Settings = if (acraSenderServiceProcess) { ACRASettings() } else { Settings() } // Api related private var _apiVersion: Int = -1