From de92b1351f10f9211830358bd225bb768131d6b4 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 22 Sep 2023 16:42:04 -0400 Subject: [PATCH] Add WebView-based user agent string to debug info Could probably use this when choosing a user agent later on. --- .../eu/kanade/tachiyomi/util/CrashLogUtil.kt | 2 ++ .../tachiyomi/util/system/WebViewUtil.kt | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt index aa9830de82..c495c70082 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt @@ -4,6 +4,7 @@ import android.content.Context import android.os.Build import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.util.storage.getUriCompat +import eu.kanade.tachiyomi.util.system.WebViewUtil import eu.kanade.tachiyomi.util.system.createFileInCacheDir import eu.kanade.tachiyomi.util.system.toShareIntent import eu.kanade.tachiyomi.util.system.toast @@ -35,6 +36,7 @@ class CrashLogUtil(private val context: Context) { Device name: ${Build.DEVICE} Device model: ${Build.MODEL} Device product name: ${Build.PRODUCT} + WebView user agent: ${WebViewUtil.getInferredUserAgent(context)} """.trimIndent() } } diff --git a/core/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt b/core/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt index 4fcaaceed2..eb1ad9617e 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt @@ -14,7 +14,24 @@ import kotlin.coroutines.resume object WebViewUtil { const val SPOOF_PACKAGE_NAME = "org.chromium.chrome" - const val MINIMUM_WEBVIEW_VERSION = 111 + const val MINIMUM_WEBVIEW_VERSION = 114 + + /** + * Uses the WebView's user agent string to create something similar to what Chrome on Android + * would return. + * + * Example of WebView user agent string: + * Mozilla/5.0 (Linux; Android 13; Pixel 7 Build/TQ3A.230901.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36 + * + * Example of Chrome on Android: + * Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.3 + */ + fun getInferredUserAgent(context: Context): String { + return WebView(context) + .getDefaultUserAgentString() + .replace("; Android .*?\\)".toRegex(), "; Android 10; K)") + .replace("Version/.* Chrome/".toRegex(), "Chrome/") + } fun supportsWebView(context: Context): Boolean { try {