mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
enhance: Load GlobalExceptionHandler before Crashlytics
This commit is contained in:
parent
ad6c0cc358
commit
d60b66ac9f
6 changed files with 73 additions and 19 deletions
|
@ -7,5 +7,8 @@
|
||||||
|
|
||||||
## Other
|
## Other
|
||||||
-->
|
-->
|
||||||
|
## Changes
|
||||||
|
- Crash report can now actually be disabled
|
||||||
|
|
||||||
## Other
|
## Other
|
||||||
- Some more NullPointerException prevention that I missed
|
- Loading GlobalExceptionHandler before Crashlytics
|
||||||
|
|
|
@ -243,6 +243,13 @@
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />
|
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />
|
||||||
|
|
||||||
|
<!-- Loading global exception handler before crashlytics (order: 100) -->
|
||||||
|
<provider
|
||||||
|
android:name="eu.kanade.tachiyomi.AppProvider"
|
||||||
|
android:authorities="${applicationId}.yokai"
|
||||||
|
android:exported="false"
|
||||||
|
android:initOrder="101" />
|
||||||
|
|
||||||
<meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"
|
<meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"
|
||||||
android:value="false" />
|
android:value="false" />
|
||||||
<meta-data android:name="android.webkit.WebView.MetricsOptOut"
|
<meta-data android:name="android.webkit.WebView.MetricsOptOut"
|
||||||
|
|
|
@ -20,4 +20,6 @@ class BasePreferences(private val preferenceStore: PreferenceStore) {
|
||||||
fun displayProfile() = preferenceStore.getString("pref_display_profile_key", "")
|
fun displayProfile() = preferenceStore.getString("pref_display_profile_key", "")
|
||||||
|
|
||||||
fun hasShownOnboarding() = preferenceStore.getBoolean(Preference.appStateKey("onboarding_complete"), false)
|
fun hasShownOnboarding() = preferenceStore.getBoolean(Preference.appStateKey("onboarding_complete"), false)
|
||||||
|
|
||||||
|
fun crashReport() = preferenceStore.getBoolean("pref_crash_report", true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ import coil3.request.allowHardware
|
||||||
import coil3.request.allowRgb565
|
import coil3.request.allowRgb565
|
||||||
import coil3.request.crossfade
|
import coil3.request.crossfade
|
||||||
import coil3.util.DebugLogger
|
import coil3.util.DebugLogger
|
||||||
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
|
import com.google.firebase.ktx.Firebase
|
||||||
import eu.kanade.tachiyomi.appwidget.TachiyomiWidgetManager
|
import eu.kanade.tachiyomi.appwidget.TachiyomiWidgetManager
|
||||||
import eu.kanade.tachiyomi.data.coil.BufferedSourceFetcher
|
import eu.kanade.tachiyomi.data.coil.BufferedSourceFetcher
|
||||||
import eu.kanade.tachiyomi.data.coil.CoilDiskCache
|
import eu.kanade.tachiyomi.data.coil.CoilDiskCache
|
||||||
|
@ -42,6 +44,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import dev.yokai.core.di.AppModule
|
import dev.yokai.core.di.AppModule
|
||||||
import dev.yokai.core.di.DomainModule
|
import dev.yokai.core.di.DomainModule
|
||||||
import dev.yokai.core.di.PreferenceModule
|
import dev.yokai.core.di.PreferenceModule
|
||||||
|
import dev.yokai.domain.base.BasePreferences
|
||||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||||
import eu.kanade.tachiyomi.ui.crash.CrashActivity
|
import eu.kanade.tachiyomi.ui.crash.CrashActivity
|
||||||
import eu.kanade.tachiyomi.ui.crash.GlobalExceptionHandler
|
import eu.kanade.tachiyomi.ui.crash.GlobalExceptionHandler
|
||||||
|
@ -66,6 +69,7 @@ import java.security.Security
|
||||||
open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factory {
|
open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factory {
|
||||||
|
|
||||||
val preferences: PreferencesHelper by injectLazy()
|
val preferences: PreferencesHelper by injectLazy()
|
||||||
|
val basePreferences: BasePreferences by injectLazy()
|
||||||
|
|
||||||
private val disableIncognitoReceiver = DisableIncognitoReceiver()
|
private val disableIncognitoReceiver = DisableIncognitoReceiver()
|
||||||
|
|
||||||
|
@ -73,8 +77,6 @@ open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.F
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super<Application>.onCreate()
|
super<Application>.onCreate()
|
||||||
|
|
||||||
GlobalExceptionHandler.initialize(applicationContext, CrashActivity::class.java)
|
|
||||||
|
|
||||||
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
|
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
|
||||||
|
|
||||||
// TLS 1.3 support for Android 10 and below
|
// TLS 1.3 support for Android 10 and below
|
||||||
|
@ -94,6 +96,16 @@ open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.F
|
||||||
importModule(DomainModule())
|
importModule(DomainModule())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
basePreferences.crashReport().changes()
|
||||||
|
.onEach {
|
||||||
|
try {
|
||||||
|
Firebase.crashlytics.setCrashlyticsCollectionEnabled(it)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// Probably already enabled/disabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.launchIn(ProcessLifecycleOwner.get().lifecycleScope)
|
||||||
|
|
||||||
setupNotificationChannels()
|
setupNotificationChannels()
|
||||||
|
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
|
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
|
||||||
|
|
34
app/src/main/java/eu/kanade/tachiyomi/AppProvider.kt
Normal file
34
app/src/main/java/eu/kanade/tachiyomi/AppProvider.kt
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package eu.kanade.tachiyomi
|
||||||
|
|
||||||
|
import android.content.ContentProvider
|
||||||
|
import android.content.ContentValues
|
||||||
|
import android.database.Cursor
|
||||||
|
import android.net.Uri
|
||||||
|
import eu.kanade.tachiyomi.ui.crash.CrashActivity
|
||||||
|
import eu.kanade.tachiyomi.ui.crash.GlobalExceptionHandler
|
||||||
|
|
||||||
|
class AppProvider : ContentProvider() {
|
||||||
|
override fun onCreate(): Boolean {
|
||||||
|
context?.let {
|
||||||
|
GlobalExceptionHandler.initialize(it, CrashActivity::class.java)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun query(
|
||||||
|
uri: Uri,
|
||||||
|
projection: Array<out String>?,
|
||||||
|
selection: String?,
|
||||||
|
selectionArgs: Array<out String>?,
|
||||||
|
sortOrder: String?,
|
||||||
|
): Cursor? = null
|
||||||
|
|
||||||
|
override fun getType(uri: Uri): String? = null
|
||||||
|
|
||||||
|
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
||||||
|
|
||||||
|
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
||||||
|
|
||||||
|
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ import androidx.core.net.toUri
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.ktx.Firebase
|
|
||||||
import com.hippo.unifile.UniFile
|
import com.hippo.unifile.UniFile
|
||||||
import dev.yokai.domain.base.BasePreferences.ExtensionInstaller
|
import dev.yokai.domain.base.BasePreferences.ExtensionInstaller
|
||||||
import dev.yokai.domain.extension.interactor.TrustExtension
|
import dev.yokai.domain.extension.interactor.TrustExtension
|
||||||
|
@ -105,17 +104,9 @@ class SettingsAdvancedController : SettingsLegacyController() {
|
||||||
titleRes = R.string.advanced
|
titleRes = R.string.advanced
|
||||||
|
|
||||||
switchPreference {
|
switchPreference {
|
||||||
key = "acra.enable"
|
bindTo(basePreferences.crashReport())
|
||||||
titleRes = R.string.send_crash_report
|
titleRes = R.string.send_crash_report
|
||||||
summaryRes = R.string.helps_fix_bugs
|
summaryRes = R.string.helps_fix_bugs
|
||||||
defaultValue = true
|
|
||||||
onChange {
|
|
||||||
try {
|
|
||||||
Firebase.crashlytics.setCrashlyticsCollectionEnabled(it as Boolean)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
preference {
|
preference {
|
||||||
|
@ -436,13 +427,18 @@ class SettingsAdvancedController : SettingsLegacyController() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BuildConfig.DEBUG)
|
preference {
|
||||||
preference {
|
title = "Crash the app!"
|
||||||
title = "Crash the app!"
|
summary = "To test crashes"
|
||||||
onClick {
|
onClick {
|
||||||
throw RuntimeException("Fell into the void")
|
activity!!.materialAlertDialog()
|
||||||
}
|
.setTitle(R.string.warning)
|
||||||
|
.setMessage("I told you this would crash the app, why would you want that?")
|
||||||
|
.setPositiveButton("Crash it anyway") { _, _ -> throw RuntimeException("Fell into the void") }
|
||||||
|
.setNegativeButton("Nevermind", null)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(DelicateCoroutinesApi::class)
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue