@@ -34,14 +34,14 @@ import kotlinx.coroutines.Dispatchers
3434import kotlinx.coroutines.withContext
3535import timber.log.Timber
3636
37- internal const val OLDEST_WORKING_WEBVIEW_VERSION_CODE = 418306960L
38- internal const val OLDEST_WORKING_WEBVIEW_VERSION = 85
37+ internal const val OLDEST_WORKING_WEBVIEW_VERSION_CODE = 443000000L
38+ internal const val OLDEST_WORKING_WEBVIEW_VERSION = 90
3939
4040/* *
4141 * Shows a dialog if the current WebView version is older than the last supported version.
4242 */
43- fun checkWebviewVersion (activity : AnkiActivity ) {
44- val userVisibleCode = getChromeLikeWebViewVersionIfOutdated(activity) ? : return
43+ fun checkWebviewVersion (activity : AnkiActivity ): Boolean {
44+ val userVisibleCode = getChromeLikeWebViewVersionIfOutdated(activity) ? : return false
4545
4646 // Provide guidance to the user if the WebView is outdated
4747 val webviewPackageInfo = getAndroidSystemWebViewPackageInfo(activity.packageManager)
@@ -54,6 +54,7 @@ fun checkWebviewVersion(activity: AnkiActivity) {
5454 Timber .w(" WebView is outdated. %s: %s" , webviewPackageInfo?.packageName, webviewPackageInfo?.versionName)
5555 showOutdatedWebViewDialog(activity, userVisibleCode, R .string.link_webview_update)
5656 }
57+ return true
5758}
5859
5960@MainThread
@@ -96,33 +97,33 @@ fun checkWebViewVersionComponents(
9697 versionCode : Long ,
9798 userAgent : String? ,
9899): Int? {
99- // Checking the version code works for most webview packages
100- if (versionCode >= OLDEST_WORKING_WEBVIEW_VERSION_CODE ) {
101- Timber .d(
102- " WebView is up to date. %s: %s(%s)" ,
103- packageName,
104- webviewVersion,
105- versionCode.toString(),
106- )
107- return null
108- }
109-
110100 // Sometimes the webview version code appears too old, and the package name does as well,
111101 // but it's a webview that advertises modern capabilities via User-Agent in "Chrome" section
112102 // Our warning is purely advisory, so, let's let those through if User-Agent looks okay
113103 userAgent?.let {
114104 val chromeRegex = """ Chrome/(\d+)""" .toRegex()
115105 val matchResult = chromeRegex.find(userAgent)?.groupValues?.get(1 )
116106 matchResult?.toInt()?.let {
117- if (it < OLDEST_WORKING_WEBVIEW_VERSION ) {
118- // If we got here, even the User-Agent says it's incompatible, return something
119- // potentially useful to the user as a browser version
107+ if (it >= OLDEST_WORKING_WEBVIEW_VERSION ) {
108+ // If the User-Agent says we are modern, trust it and skip further checks.
109+ return null
110+ } else {
111+ // If the User-Agent is explicitly below the floor, return it immediately.
120112 return it
121113 }
122114 }
123115 }
124-
125- return null
116+ // Checking the version code works for most webview packages
117+ if (versionCode >= OLDEST_WORKING_WEBVIEW_VERSION_CODE ) {
118+ Timber .d(
119+ " WebView is up to date. %s: %s(%s)" ,
120+ packageName,
121+ webviewVersion,
122+ versionCode.toString(),
123+ )
124+ return null
125+ }
126+ return webviewVersion.split(' .' ).firstOrNull()?.toIntOrNull()
126127}
127128
128129data class WebViewInfo (
0 commit comments