Don't recompute constant device info

This commit is contained in:
arkon 2021-12-24 10:20:08 -05:00
parent 09b6a3b41e
commit 448645d83a
5 changed files with 11 additions and 8 deletions

View File

@ -326,7 +326,7 @@ class PreferencesHelper(val context: Context) {
fun extensionInstaller() = flowPrefs.getEnum( fun extensionInstaller() = flowPrefs.getEnum(
Keys.extensionInstaller, Keys.extensionInstaller,
if (DeviceUtil.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) fun verboseLogging() = prefs.getBoolean(Keys.verboseLogging, false)

View File

@ -41,7 +41,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
private val initWebView by lazy { private val initWebView by lazy {
// Avoid crashes on Samsung devices on Android 12 // Avoid crashes on Samsung devices on Android 12
// See https://bugs.chromium.org/p/chromium/issues/detail?id=1279562 // See https://bugs.chromium.org/p/chromium/issues/detail?id=1279562
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.S && DeviceUtil.isSamsung()) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.S && DeviceUtil.isSamsung) {
return@lazy return@lazy
} }

View File

@ -215,7 +215,7 @@ class SettingsAdvancedController : SettingsController() {
R.string.ext_installer_shizuku, R.string.ext_installer_shizuku,
) )
entryValues = PreferenceValues.ExtensionInstaller.values().map { it.name }.toTypedArray() entryValues = PreferenceValues.ExtensionInstaller.values().map { it.name }.toTypedArray()
defaultValue = if (DeviceUtil.isMiui()) { defaultValue = if (DeviceUtil.isMiui) {
PreferenceValues.ExtensionInstaller.LEGACY PreferenceValues.ExtensionInstaller.LEGACY
} else { } else {
PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER

View File

@ -62,7 +62,7 @@ class SettingsBackupController : SettingsController() {
summaryRes = R.string.pref_create_backup_summ summaryRes = R.string.pref_create_backup_summ
onClick { onClick {
if (DeviceUtil.isMiui() && DeviceUtil.isMiuiOptimizationDisabled()) { if (DeviceUtil.isMiui && DeviceUtil.isMiuiOptimizationDisabled()) {
context.toast(R.string.restore_miui_warning, Toast.LENGTH_LONG) context.toast(R.string.restore_miui_warning, Toast.LENGTH_LONG)
} }
@ -81,7 +81,7 @@ class SettingsBackupController : SettingsController() {
summaryRes = R.string.pref_restore_backup_summ summaryRes = R.string.pref_restore_backup_summ
onClick { onClick {
if (DeviceUtil.isMiui() && DeviceUtil.isMiuiOptimizationDisabled()) { if (DeviceUtil.isMiui && DeviceUtil.isMiuiOptimizationDisabled()) {
context.toast(R.string.restore_miui_warning, Toast.LENGTH_LONG) context.toast(R.string.restore_miui_warning, Toast.LENGTH_LONG)
} }

View File

@ -3,11 +3,12 @@ package eu.kanade.tachiyomi.util.system
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Build import android.os.Build
import logcat.LogPriority import logcat.LogPriority
import java.util.Locale
object DeviceUtil { object DeviceUtil {
fun isMiui() = getSystemProperty("ro.miui.ui.version.name")?.isNotEmpty() ?: false val isMiui by lazy {
getSystemProperty("ro.miui.ui.version.name")?.isNotEmpty() ?: false
}
@SuppressLint("PrivateApi") @SuppressLint("PrivateApi")
fun isMiuiOptimizationDisabled(): Boolean { fun isMiuiOptimizationDisabled(): Boolean {
@ -25,7 +26,9 @@ object DeviceUtil {
} }
} }
fun isSamsung() = Build.MANUFACTURER.lowercase(Locale.ENGLISH) == "samsung" val isSamsung by lazy {
Build.MANUFACTURER.equals("samsung", ignoreCase = true)
}
@SuppressLint("PrivateApi") @SuppressLint("PrivateApi")
private fun getSystemProperty(key: String?): String? { private fun getSystemProperty(key: String?): String? {