Skip to content

Commit 11af848

Browse files
committed
feat: include webview provider and versionCode in debug info
1 parent 77002d5 commit 11af848

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/DebugInfoService.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import com.ichi2.anki.BuildConfig
2222
import com.ichi2.anki.CollectionManager
2323
import com.ichi2.anki.CrashReportService
2424
import com.ichi2.utils.VersionUtils.pkgVersionName
25-
import com.ichi2.utils.getWebviewUserAgent
26-
import kotlinx.coroutines.Dispatchers
27-
import kotlinx.coroutines.withContext
25+
import com.ichi2.utils.getWebViewInfo
2826
import org.acra.util.Installation
2927
import timber.log.Timber
3028
import net.ankiweb.rsdroid.BuildConfig as BackendBuildConfig
@@ -36,7 +34,7 @@ object DebugInfoService {
3634
* Note that the `FSRS` parameter can be null if the collection doesn't exist or the config is not set.
3735
*/
3836
suspend fun getDebugInfo(info: Context): String {
39-
val webviewUserAgent = withContext(Dispatchers.Main) { getWebviewUserAgent(info) }
37+
val webviewInfo = getWebViewInfo(info)
4038
// isFSRSEnabled is null on startup
4139
val isFSRSEnabled = getFSRSStatus()
4240
return """
@@ -45,7 +43,7 @@ object DebugInfoService {
4543
Android Version = ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT})
4644
ProductFlavor = ${BuildConfig.FLAVOR}
4745
Device Info = ${Build.MANUFACTURER} | ${Build.BRAND} | ${Build.DEVICE} | ${Build.PRODUCT} | ${Build.MODEL} | ${Build.HARDWARE}
48-
Webview User Agent = $webviewUserAgent
46+
WebView Info = [${webviewInfo.packageName} | ${webviewInfo.versionCode}]: ${webviewInfo.userAgent}
4947
ACRA UUID = ${Installation.id(info)}
5048
FSRS = ${BackendBuildConfig.FSRS_VERSION} (Enabled: $isFSRSEnabled)
5149
Crash Reports Enabled = ${isSendingCrashReports(info)}

AnkiDroid/src/main/java/com/ichi2/utils/WebViewUtils.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ import androidx.annotation.StringRes
2626
import androidx.annotation.VisibleForTesting
2727
import androidx.appcompat.app.AlertDialog
2828
import androidx.core.content.pm.PackageInfoCompat
29+
import androidx.webkit.WebViewCompat
2930
import com.ichi2.anki.AnkiActivity
3031
import com.ichi2.anki.CrashReportService
3132
import com.ichi2.anki.R
33+
import kotlinx.coroutines.Dispatchers
34+
import kotlinx.coroutines.withContext
3235
import timber.log.Timber
3336

3437
internal 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+
125155
private fun showOutdatedWebViewDialog(
126156
activity: AnkiActivity,
127157
installedVersion: Int,

0 commit comments

Comments
 (0)