Skip to content

Commit

Permalink
Warning when WebView (<77) is outdated (ankidroid#14957)
Browse files Browse the repository at this point in the history
* Dialog warning for outdated WebView version
* Snackbar warning for outdated WebView version
* Make WebView Warning developer only

Only check if the WebView version is outdated when debugging

Co-authored-by: Mike Hardy <[email protected]>

* Add debug-only comment

---------

Co-authored-by: Mike Hardy <[email protected]>
  • Loading branch information
elli-hae and mikehardy authored Dec 13, 2023
1 parent 49dc7bd commit 68137d6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package com.ichi2.anki

import android.app.Activity
import android.content.*
import android.content.pm.PackageManager
import android.database.SQLException
import android.graphics.PixelFormat
import android.graphics.drawable.Drawable
Expand Down Expand Up @@ -134,6 +135,7 @@ import kotlin.time.measureTimedValue

const val MIGRATION_WAS_LAST_POSTPONED_AT_SECONDS = "secondWhenMigrationWasPostponedLast"
const val TIMES_STORAGE_MIGRATION_POSTPONED_KEY = "timesStorageMigrationPostponed"
const val OLDEST_WORKING_WEBVIEW_VERSION = 77

/**
* The current entry point for AnkiDroid. Displays decks, allowing users to study. Many other functions.
Expand Down Expand Up @@ -461,6 +463,9 @@ open class DeckPicker :
Onboarding.DeckPicker(this, mRecyclerViewLayoutManager).onCreate()

launchShowingHidingEssentialFileMigrationProgressDialog()
if (BuildConfig.DEBUG) {
checkWebviewVersion()
}
}

private fun hasShownAppIntro(): Boolean {
Expand All @@ -480,6 +485,28 @@ open class DeckPicker :
return prefs.getBoolean(IntroductionActivity.INTRODUCTION_SLIDES_SHOWN, false)
}

/**
* Check if the current WebView version is older than the last supported version and if it is,
* inform the developer with a snackbar.
*/
private fun checkWebviewVersion() {
// Doesn't need to be translated as it's debug only
// Specifically check for Android System WebView
try {
val androidSystemWebViewPackage = "com.google.android.webview"
val webviewPackageInfo = packageManager.getPackageInfo(androidSystemWebViewPackage, 0)
val versionCode = webviewPackageInfo.versionName.split(".")[0].toInt()
if (versionCode < OLDEST_WORKING_WEBVIEW_VERSION) {
val snackbarMessage =
"The WebView version $versionCode is outdated (<$OLDEST_WORKING_WEBVIEW_VERSION)."
showSnackbar(snackbarMessage, Snackbar.LENGTH_INDEFINITE)
}
} catch (_: PackageManager.NameNotFoundException) {
val snackbarMessage = "No Android System WebView found"
showSnackbar(snackbarMessage, Snackbar.LENGTH_INDEFINITE)
}
}

/**
* The first call in showing dialogs for startup
*
Expand Down

0 comments on commit 68137d6

Please sign in to comment.