From 7edf7a434f1e07dad2214f05ac7ea023fedafc47 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 24 Dec 2021 09:42:45 -0500 Subject: [PATCH] Avoid crash on Samsung devices on Android 12 Co-authored-by: Jays2Kings --- .../tachiyomi/data/preference/PreferencesHelper.kt | 4 ++-- .../network/interceptor/CloudflareInterceptor.kt | 8 ++++++++ .../tachiyomi/ui/setting/SettingsAdvancedController.kt | 4 ++-- .../tachiyomi/ui/setting/SettingsBackupController.kt | 6 +++--- .../util/system/{MiuiUtil.kt => DeviceUtil.kt} | 10 ++++++---- 5 files changed, 21 insertions(+), 11 deletions(-) rename app/src/main/java/eu/kanade/tachiyomi/util/system/{MiuiUtil.kt => DeviceUtil.kt} (81%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 9ad7e0475..207e0af9a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -18,7 +18,7 @@ import eu.kanade.tachiyomi.ui.library.setting.SortDirectionSetting import eu.kanade.tachiyomi.ui.library.setting.SortModeSetting import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType -import eu.kanade.tachiyomi.util.system.MiuiUtil +import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.widget.ExtendedNavigationView import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.onEach @@ -326,7 +326,7 @@ class PreferencesHelper(val context: Context) { fun extensionInstaller() = flowPrefs.getEnum( Keys.extensionInstaller, - if (MiuiUtil.isMiui()) Values.ExtensionInstaller.LEGACY else Values.ExtensionInstaller.PACKAGEINSTALLER + if (DeviceUtil.isMiui()) Values.ExtensionInstaller.LEGACY else Values.ExtensionInstaller.PACKAGEINSTALLER ) fun verboseLogging() = prefs.getBoolean(Keys.verboseLogging, false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt index f15d598ab..58fbe042a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.network.interceptor import android.annotation.SuppressLint import android.content.Context +import android.os.Build import android.webkit.WebSettings import android.webkit.WebView import android.widget.Toast @@ -10,6 +11,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.util.lang.launchUI +import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.WebViewClientCompat import eu.kanade.tachiyomi.util.system.WebViewUtil import eu.kanade.tachiyomi.util.system.isOutdated @@ -37,6 +39,12 @@ class CloudflareInterceptor(private val context: Context) : Interceptor { * Application class. */ private val initWebView by lazy { + // Avoid crashes on Samsung devices on Android 12 + // See https://bugs.chromium.org/p/chromium/issues/detail?id=1279562 + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.S && DeviceUtil.isSamsung()) { + return@lazy + } + WebSettings.getDefaultUserAgent(context) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index f015cc6bf..23aae9207 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -35,7 +35,7 @@ import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.summaryRes import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes -import eu.kanade.tachiyomi.util.system.MiuiUtil +import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.isPackageInstalled import eu.kanade.tachiyomi.util.system.powerManager import eu.kanade.tachiyomi.util.system.toast @@ -215,7 +215,7 @@ class SettingsAdvancedController : SettingsController() { R.string.ext_installer_shizuku, ) entryValues = PreferenceValues.ExtensionInstaller.values().map { it.name }.toTypedArray() - defaultValue = if (MiuiUtil.isMiui()) { + defaultValue = if (DeviceUtil.isMiui()) { PreferenceValues.ExtensionInstaller.LEGACY } else { PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index 2eeb079ac..2889580bf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -35,7 +35,7 @@ import eu.kanade.tachiyomi.util.preference.preference import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.summaryRes import eu.kanade.tachiyomi.util.preference.titleRes -import eu.kanade.tachiyomi.util.system.MiuiUtil +import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -62,7 +62,7 @@ class SettingsBackupController : SettingsController() { summaryRes = R.string.pref_create_backup_summ onClick { - if (MiuiUtil.isMiui() && MiuiUtil.isMiuiOptimizationDisabled()) { + if (DeviceUtil.isMiui() && DeviceUtil.isMiuiOptimizationDisabled()) { context.toast(R.string.restore_miui_warning, Toast.LENGTH_LONG) } @@ -81,7 +81,7 @@ class SettingsBackupController : SettingsController() { summaryRes = R.string.pref_restore_backup_summ onClick { - if (MiuiUtil.isMiui() && MiuiUtil.isMiuiOptimizationDisabled()) { + if (DeviceUtil.isMiui() && DeviceUtil.isMiuiOptimizationDisabled()) { context.toast(R.string.restore_miui_warning, Toast.LENGTH_LONG) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/MiuiUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt similarity index 81% rename from app/src/main/java/eu/kanade/tachiyomi/util/system/MiuiUtil.kt rename to app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt index 22514ac20..7cb7f8869 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/MiuiUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt @@ -1,13 +1,13 @@ package eu.kanade.tachiyomi.util.system import android.annotation.SuppressLint +import android.os.Build import logcat.LogPriority +import java.util.Locale -object MiuiUtil { +object DeviceUtil { - fun isMiui(): Boolean { - return getSystemProperty("ro.miui.ui.version.name")?.isNotEmpty() ?: false - } + fun isMiui() = getSystemProperty("ro.miui.ui.version.name")?.isNotEmpty() ?: false @SuppressLint("PrivateApi") fun isMiuiOptimizationDisabled(): Boolean { @@ -25,6 +25,8 @@ object MiuiUtil { } } + fun isSamsung() = Build.MANUFACTURER.lowercase(Locale.ENGLISH) == "samsung" + @SuppressLint("PrivateApi") private fun getSystemProperty(key: String?): String? { return try {