From 0b9d436753f22479254dff46b5b1292ba45addcf Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 2 Jan 2022 11:25:35 -0500 Subject: [PATCH] Fix some crashes --- .../tachiyomi/data/download/DownloadService.kt | 14 ++++++++------ .../network/interceptor/CloudflareInterceptor.kt | 15 +++++++++------ .../kanade/tachiyomi/ui/reader/ReaderActivity.kt | 16 +++++++++------- .../kanade/tachiyomi/util/system/DeviceUtil.kt | 5 +++++ .../widget/preference/ThemesPreference.kt | 4 ++++ 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt index da175e1802..90d8c802cc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt @@ -176,13 +176,15 @@ class DownloadService : Service() { * Listens to downloader status. Enables or disables the wake lock depending on the status. */ private fun listenDownloaderState() { - subscriptions += downloadManager.runningRelay.subscribe { running -> - if (running) { - wakeLock.acquireIfNeeded() - } else { - wakeLock.releaseIfNeeded() + subscriptions += downloadManager.runningRelay + .doOnError { /* Swallow wakelock error */ } + .subscribe { running -> + if (running) { + wakeLock.acquireIfNeeded() + } else { + wakeLock.releaseIfNeeded() + } } - } } /** 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 cf9303073e..e519c10f40 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,13 +39,14 @@ class CloudflareInterceptor(private val context: Context) : Interceptor { * Application class. */ private val initWebView by lazy { - try { - WebSettings.getDefaultUserAgent(context) - } catch (_: Exception) { - // Crashes on some devices. We just ignore it since the only impact is slower - // WebView init in those rare cases. - // See https://bugs.chromium.org/p/chromium/issues/detail?id=1279562 + // Crashes on some devices. We skip this in some cases since the only impact is slower + // WebView init in those rare cases. + // 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) } @Synchronized diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index ddd077e564..0e346b6c3d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -159,14 +159,16 @@ class ReaderActivity : BaseRxActivity() applyAppTheme(preferences) // Setup shared element transitions - window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS) - findViewById(android.R.id.content).transitionName = SHARED_ELEMENT_NAME - setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback()) - window.sharedElementEnterTransition = buildContainerTransform(true) - window.sharedElementReturnTransition = buildContainerTransform(false) + findViewById(android.R.id.content)?.let { contentView -> + window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS) + contentView.transitionName = SHARED_ELEMENT_NAME + setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback()) + window.sharedElementEnterTransition = buildContainerTransform(true) + window.sharedElementReturnTransition = buildContainerTransform(false) - // Postpone custom transition until manga ready - postponeEnterTransition() + // Postpone custom transition until manga ready + postponeEnterTransition() + } super.onCreate(savedInstanceState) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt index 8cd20dac8b..33a132408a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.util.system import android.annotation.SuppressLint +import android.os.Build import logcat.LogPriority object DeviceUtil { @@ -25,6 +26,10 @@ object DeviceUtil { } } + val isSamsung by lazy { + Build.MANUFACTURER.equals("samsung", ignoreCase = true) + } + @SuppressLint("PrivateApi") private fun getSystemProperty(key: String?): String? { return try { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreference.kt index f51372fef7..836ba1359f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreference.kt @@ -47,6 +47,10 @@ class ThemesPreference @JvmOverloads constructor(context: Context, attrs: Attrib } override fun onItemClick(position: Int) { + if (position !in 0..entries.size) { + return + } + callChangeListener(value) value = entries[position].name }