From 75e32f6f4700c7c915218490c7afa2dd25fbb392 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 10 Mar 2020 00:00:29 -0700 Subject: [PATCH] Create WebViewUtil.kt --- .../tachiyomi/util/system/WebViewUtil.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt new file mode 100644 index 0000000000..83e864a05a --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt @@ -0,0 +1,33 @@ +package eu.kanade.tachiyomi.util.system + +import android.webkit.WebView + +private val WEBVIEW_UA_VERSION_REGEX by lazy { + Regex(""".*Chrome/(\d+)\..*""") +} + +private const val MINIMUM_WEBVIEW_VERSION = 70 + +fun WebView.isOutdated(): Boolean { + return getWebviewMajorVersion(this) < MINIMUM_WEBVIEW_VERSION +} + +// Based on https://stackoverflow.com/a/29218966 +private fun getWebviewMajorVersion(webview: WebView): Int { + val originalUA: String = webview.settings.userAgentString + + // Next call to getUserAgentString() will get us the default + webview.settings.userAgentString = null + + val uaRegexMatch = WEBVIEW_UA_VERSION_REGEX.matchEntire(webview.settings.userAgentString) + val webViewVersion: Int = if (uaRegexMatch != null && uaRegexMatch.groupValues.size > 1) { + uaRegexMatch.groupValues[1].toInt() + } else { + 0 + } + + // Revert to original UA string + webview.settings.userAgentString = originalUA + + return webViewVersion +}