@@ -26,9 +26,12 @@ import androidx.annotation.StringRes
2626import androidx.annotation.VisibleForTesting
2727import androidx.appcompat.app.AlertDialog
2828import androidx.core.content.pm.PackageInfoCompat
29+ import androidx.webkit.WebViewCompat
2930import com.ichi2.anki.AnkiActivity
3031import com.ichi2.anki.CrashReportService
3132import com.ichi2.anki.R
33+ import kotlinx.coroutines.Dispatchers
34+ import kotlinx.coroutines.withContext
3235import timber.log.Timber
3336
3437internal const val OLDEST_WORKING_WEBVIEW_VERSION_CODE = 418306960L
@@ -122,6 +125,33 @@ fun checkWebViewVersionComponents(
122125 return null
123126}
124127
128+ data class WebViewInfo (
129+ val userAgent : String? ,
130+ val packageName : String? ,
131+ val versionCode : Long? ,
132+ )
133+
134+ /* *
135+ * Retrieves [WebViewInfo] containing the current User Agent and system WebView package details.
136+ *
137+ * It is called on the main thread because [WebViewCompat.getCurrentWebViewPackage]
138+ * and [getWebviewUserAgent] require main thread access to the WebView system.
139+ *
140+ * It does not throw; if the WebView provider is missing or an error occurs
141+ * during retrieval, a [WebViewInfo] object with null values is returned.
142+ *
143+ * @return A [WebViewInfo] object with WebView package details.
144+ */
145+ suspend fun getWebViewInfo (context : Context ): WebViewInfo =
146+ withContext(Dispatchers .Main ) {
147+ val packageInfo = runCatching { WebViewCompat .getCurrentWebViewPackage(context) }.getOrNull()
148+ WebViewInfo (
149+ userAgent = getWebviewUserAgent(context),
150+ packageName = packageInfo?.packageName,
151+ versionCode = runCatching { packageInfo?.let { PackageInfoCompat .getLongVersionCode(it) } }.getOrNull(),
152+ )
153+ }
154+
125155private fun showOutdatedWebViewDialog (
126156 activity : AnkiActivity ,
127157 installedVersion : Int ,
0 commit comments