Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import com.ichi2.anki.BuildConfig
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.CrashReportService
import com.ichi2.utils.VersionUtils.pkgVersionName
import com.ichi2.utils.getWebviewUserAgent
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import com.ichi2.utils.getWebViewInfo
import org.acra.util.Installation
import timber.log.Timber
import net.ankiweb.rsdroid.BuildConfig as BackendBuildConfig
Expand All @@ -36,7 +34,7 @@ object DebugInfoService {
* Note that the `FSRS` parameter can be null if the collection doesn't exist or the config is not set.
*/
suspend fun getDebugInfo(info: Context): String {
val webviewUserAgent = withContext(Dispatchers.Main) { getWebviewUserAgent(info) }
val webviewInfo = getWebViewInfo(info)
// isFSRSEnabled is null on startup
val isFSRSEnabled = getFSRSStatus()
return """
Expand All @@ -45,7 +43,7 @@ object DebugInfoService {
Android Version = ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT})
ProductFlavor = ${BuildConfig.FLAVOR}
Device Info = ${Build.MANUFACTURER} | ${Build.BRAND} | ${Build.DEVICE} | ${Build.PRODUCT} | ${Build.MODEL} | ${Build.HARDWARE}
Webview User Agent = $webviewUserAgent
WebView Info = [${webviewInfo.packageName} | ${webviewInfo.versionCode}]: ${webviewInfo.userAgent}
ACRA UUID = ${Installation.id(info)}
FSRS = ${BackendBuildConfig.FSRS_VERSION} (Enabled: $isFSRSEnabled)
Crash Reports Enabled = ${isSendingCrashReports(info)}
Expand Down
30 changes: 30 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/utils/WebViewUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import androidx.annotation.StringRes
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.core.content.pm.PackageInfoCompat
import androidx.webkit.WebViewCompat
import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.CrashReportService
import com.ichi2.anki.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber

internal const val OLDEST_WORKING_WEBVIEW_VERSION_CODE = 418306960L
Expand Down Expand Up @@ -122,6 +125,33 @@ fun checkWebViewVersionComponents(
return null
}

data class WebViewInfo(
val userAgent: String?,
val packageName: String?,
val versionCode: Long?,
)

/**
* Retrieves [WebViewInfo] containing the current User Agent and system WebView package details.
*
* It is called on the main thread because [WebViewCompat.getCurrentWebViewPackage]
* and [getWebviewUserAgent] require main thread access to the WebView system.
*
* It does not throw; if the WebView provider is missing or an error occurs
* during retrieval, a [WebViewInfo] object with null values is returned.
*
* @return A [WebViewInfo] object with WebView package details.
*/
suspend fun getWebViewInfo(context: Context): WebViewInfo =
withContext(Dispatchers.Main) {
val packageInfo = runCatching { WebViewCompat.getCurrentWebViewPackage(context) }.getOrNull()
WebViewInfo(
userAgent = getWebviewUserAgent(context),
packageName = packageInfo?.packageName,
versionCode = runCatching { packageInfo?.let { PackageInfoCompat.getLongVersionCode(it) } }.getOrNull(),
)
}

private fun showOutdatedWebViewDialog(
activity: AnkiActivity,
installedVersion: Int,
Expand Down