Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Productionised Webview Check using Dialog Boxes #15876

Closed
wants to merge 16 commits into from

Conversation

aayush-tripathi
Copy link
Contributor

@aayush-tripathi aayush-tripathi commented Mar 13, 2024

Purpose / Description

Added dialog boxes which inform the users in older android devices of their old WebView versions (<=77) and also helps them update the WebView to a newer version.

Fixes

Approach

The earlier debug only test informed the devs whether the WebView version was outdated , I have worked on that further and have introduced a dialog box for the users with a link to Wiki (Exact page can be changed by modifying the
const val WEBVIEW_UPDATION_LINK with information regarding updating to the latest version.

Also , I tried to differentiate between the packages com.android.webview and com.google.android.webview as this requires special steps : com.android.webview has to be disabled and com.google.android.webview has to be installed as of #15847 (comment).

How Has This Been Tested?

  • Unit Tests (./gradlew jacocoUnitTestReport)

  • Ran on a virtual device (Android 7.0 , API 24 ) containing an older webview version to ensure the dialog box works

    ( I was unable to test whether the dialog box works for devices having "com.android.webview" )

oldwebviewerror.1.mp4

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Copy link
Contributor

Message to maintainers, this PR contains strings changes.

  1. Before merging this PR, it is best to run the "Sync Translations" GitHub action, then make and merge a PR from the i18n_sync branch to get translations cleaned out.
  2. Then merge this PR, and immediately do another translation PR so the huge change made by this PR's key changes are all by themselves.

Read more about updating strings on the wiki,

@@ -141,6 +144,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
const val WEBVIEW_UPDATION_LINK = "https://github.com/ankidroid/Anki-Android/wiki"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use constants.xml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should link to an actual page with information

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! I have been working to fix this, but I was unable to find a page in the wiki relating to updating WebView. So, I was wondering if you had an external wiki in mind.

AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt Outdated Show resolved Hide resolved
…out Older WebView Version and Information to Correct it.
…out Older WebView Version and Information to Correct it.
…out Older WebView Version and Information to Correct it.
…box code structure and added support for translations
@aayush-tripathi
Copy link
Contributor Author

Hey, I have made some changes. Could you please review them?

…box code structure and added support for translations
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial round of feedback, we'll need some more time on the strings, perhaps bring the conversation to #ankidroid-dev, then detail the results of this conversation on the pull request


if (webviewPackageInfo == null) {
// User is missing both com.android.webview and com.google.android.webview
AlertDialog.Builder(context).show {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you extract each of these into methods

It's difficult to follow the dialog selection logic because this method contains both the selection and implementation logc

Uri.parse(context.getString(R.string.webview_update_link))
context.startActivity(openURL)
}
neutralButton(R.string.deck_picker_disable_older_webview) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a user going to know what to do here?

@@ -296,4 +296,5 @@
<string name="show_onboarding" maxLength="41">Show onboarding walkthrough</string>
<string name="show_onboarding_desc">Display feature tutorial to learn more about the app</string>
<string name="reset_onboarding_desc">Show all tutorials again</string>
<string name="webview_update_link">https://github.com/ankidroid/Anki-Android/wiki/FAQ#other-questions</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a specific page which you have created, don't leave it in the FAQ

@@ -260,5 +260,10 @@
</string>

<string name="deck_already_exists">Deck already exists</string>
<string name="deck_picker_disable_older_webview">Disable WebView</string>
<string name="deck_picker_updation_older_webview">Install Now </string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should likely be 'learn more', which we already have a string for

<string name="deck_picker_updation_older_webview">Install Now </string>
<string name="webview_update_message">The WebView version %1$s is outdated (less than %2$s). You can update it by following the given link.</string>
<string name="missing_webview">"AnkiDroid relies on the System WebView which is unavailable"</string>
<string name="older_webview_found_alert">"The WebView Package com.android.webview is not supported.You must disable the existing WebView Package and Install com.google.android.webview ."</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="older_webview_found_alert">"The WebView Package com.android.webview is not supported.You must disable the existing WebView Package and Install com.google.android.webview ."</string>
<string name="older_webview_found_alert">"The WebView package com.android.webview is not supported. You must disable the existing WebView package and install com.google.android.webview ."</string>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string will need a lot more thought to best communicate the problem to a non-technical user

@aayush-tripathi
Copy link
Contributor Author

Screenshot 2024-03-20 192302 Screenshot 2024-03-20 192249

Is this good as per the discord messages?

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better, thanks!

Probably a couple of rounds of feedback, then let's get this in!

@@ -164,11 +165,20 @@ sealed class AnkiDroidFolder(val permissionSet: PermissionSet) {
}

@Parcelize
enum class PermissionSet(val permissions: List<String>, val permissionsFragment: Class<out PermissionsFragment>?) : Parcelable {
LEGACY_ACCESS(Permissions.legacyStorageAccessPermissions, PermissionsUntil29Fragment::class.java),
enum class PermissionSet(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this change intentional? If not, please revert

}
cancelable(false)
}
// Nothing as already checked inside webViewFailedToLoad
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use val webviewPackageInfo = getAndroidSystemWebViewPackageInfo(packageManager) ?: return

AnkiDroid/src/main/java/com/ichi2/anki/InitialActivity.kt Outdated Show resolved Hide resolved
neutralButton(R.string.help_title_get_help) {
// Show the HelpDialog
val helpDialog = HelpDialog.newHelpInstance()
helpDialog.show(fragmentManager, "HelpDialog")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukstbit I'd expect something along the lines of requireAnkiActivity().showDialogFragment() here, did you have an intended pattern for opening the Dialog outside the Help button?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing special, the two factory methods just return a plain instance of the help dialog that can be used with showDialogFragment().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aayush-tripathi best to provide an AnkiActivity here instead of a Context

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still pending, change also needs to be applied in the other method

Comment on lines 271 to 274
val openURL = Intent(Intent.ACTION_VIEW)
openURL.data =
Uri.parse(context.getString(R.string.webview_update_link))
context.startActivity(openURL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use AnkiActivity.openUrl()

@@ -296,4 +296,5 @@
<string name="show_onboarding" maxLength="41">Show onboarding walkthrough</string>
<string name="show_onboarding_desc">Display feature tutorial to learn more about the app</string>
<string name="reset_onboarding_desc">Show all tutorials again</string>
<string name="webview_update_link">https://github.com/ankidroid/Anki-Android/wiki/WebView-Detection-and-Updation</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updation isn't a word.

Try: WebView Package Updates

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect different links for 'Learn more' on the two screens

@@ -260,5 +260,7 @@
</string>

<string name="deck_already_exists">Deck already exists</string>
<string name="webview_update_message">The WebView version is outdated (must be >= %1$s)</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only use positional arg syntax if there's more than 1 arg

Suggested change
<string name="webview_update_message">The WebView version is outdated (must be >= %1$s)</string>
<string name="webview_update_message">The WebView version is outdated (must be >= %s)</string>

@@ -197,11 +220,85 @@ internal fun selectAnkiDroidFolder(
}

fun selectAnkiDroidFolder(context: Context): AnkiDroidFolder {
val canAccessLegacyStorage = Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || Environment.isExternalStorageLegacy()
val currentFolderIsAccessibleAndLegacy = canAccessLegacyStorage && isLegacyStorage(context, setCollectionPath = false) == true
val canAccessLegacyStorage =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, please revert if this was an accidental change

@@ -260,5 +260,7 @@
</string>

<string name="deck_already_exists">Deck already exists</string>
<string name="webview_update_message">The WebView version is outdated (must be >= %1$s)</string>
<string name="older_webview_found_alert">Android System WebView is out of date. You may need to use com.google.android.webview</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel these strings should list the current package name and version, as is done on my suggested dialog in Discord

@aayush-tripathi
Copy link
Contributor Author

Screenshot 2024-03-21 000717

Added the package name and version.

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, generally looks good, needs a bit of work on the messages

neutralButton(R.string.help_title_get_help) {
// Show the HelpDialog
val helpDialog = HelpDialog.newHelpInstance()
helpDialog.show(fragmentManager, "HelpDialog")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aayush-tripathi best to provide an AnkiActivity here instead of a Context

Comment on lines 234 to 236
if (versionCode < OLDEST_WORKING_WEBVIEW_VERSION) {
showOutdatedWebViewDialog(context, fragmentManager, webviewPackageInfo.versionName)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this check above if (webviewOlder == null) { and invert it to return early if the condition is met

If a user is using a WebView with a valid version (even if it's an unexpected package), then we shouldn't block the user from using the app

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so that any version of com.android.webview is valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* inform the user with a dialog box containing further instructions.
*/
fun checkWebviewVersion(packageManager: PackageManager, context: Context, fragmentManager: FragmentManager) {
val webviewPackageInfo = getAndroidSystemWebViewPackageInfo(packageManager) ?: return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add Timber.w warnings if the user does have an outdated WebView

And a Timber.d if the WebView is good

@@ -260,5 +260,7 @@
</string>

<string name="deck_already_exists">Deck already exists</string>
<string name="webview_update_message">The Android System WebView is out of date\n\ncom.google.android.webview : %s</string>
<string name="older_native_webview_found_alert">"The WebView Package com.android.webview is not supported.You must disable the existing WebView Package and Install com.google.android.webview\n\ncom.android.webview %s</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I'd go back and use the strings I supplied on Discord
  2. Provide the package name as an argument
  3. Add a space after a full stop

@@ -260,5 +260,7 @@
</string>

<string name="deck_already_exists">Deck already exists</string>
<string name="webview_update_message">The Android System WebView is out of date\n\ncom.google.android.webview : %s</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, and remove the space before the colon

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Mar 24, 2024
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small change, then good to go I think, looks great!

neutralButton(R.string.help_title_get_help) {
// Show the HelpDialog
val helpDialog = HelpDialog.newHelpInstance()
helpDialog.show(fragmentManager, "HelpDialog")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still pending, change also needs to be applied in the other method

AnkiDroid/src/main/res/values/03-dialogs.xml Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/InitialActivity.kt Outdated Show resolved Hide resolved
@david-allison david-allison added the GSoC Pull requests authored by a Google Summer of Code participant [Candidate/Selected], for GSoC mentors label Apr 2, 2024
@neeldoshii
Copy link
Contributor

The branch seems to have conflict. Can you try fixing the conflict.

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +1118 to +1119
// In case the user returns to the App without making the required updates to WebView
// As without a "onResume()" , the dialog box is removed on resume.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the comment above the line

}
}

private fun showOutdatedWebViewDialog(context: AnkiActivity, webview: PackageInfo) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename context -> activity

}
}

private fun showNativeOutdatedWebViewDialog(context: AnkiActivity, webview: PackageInfo) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@david-allison david-allison added the Needs Second Approval Has one approval, one more approval to merge label Apr 2, 2024
@neeldoshii
Copy link
Contributor

neeldoshii commented Apr 4, 2024

Just a feedback @aayush-tripathi, next time instead of using [Merge branch 'main' into main] use git rebase.

@david-allison david-allison added squash-merge The pull request currently requires maintainers to "Squash Merge" and removed Needs Author Reply Waiting for a reply from the original author labels Apr 5, 2024
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build is failing

Pretty much there, thanks!

One minor comment-based change on the XML, then let's get this in

Comment on lines 52 to 55
<string name="answering_error_report">Report error</string>
<string name="storage_full_message">There is not enough free storage space to open AnkiDroid. Free up some space to continue. </string>
<string name="storage_full_message">There is not enough free storage space to open AnkiDroid. Free up some space to continue. </string>
<string name="repair_deck_dialog">Do you really want to try to repair the database?\n\nBefore starting the attempt, a copy will be created in subfolder “%s”.</string>
<string name="intent_aedict_empty">Category “default” is empty</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this, it'll ping our translators unnecessarily

@@ -271,3 +275,4 @@ also changes the interval of the card"
<string name="range_delimiter" comment="Placed between two input boxes to denote a range">–</string>

</resources>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert - it'll be picked up by our translation sync

@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author and removed Has Conflicts labels Apr 14, 2024
Copy link
Contributor

Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Apr 28, 2024
@david-allison david-allison added Keep Open avoids the stale bot Needs a new dev For PR that were good start but the original dev' left. Any dev can take over and finish it. labels Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GSoC Pull requests authored by a Google Summer of Code participant [Candidate/Selected], for GSoC mentors Has Conflicts Keep Open avoids the stale bot Needs a new dev For PR that were good start but the original dev' left. Any dev can take over and finish it. Needs Author Reply Waiting for a reply from the original author Needs Second Approval Has one approval, one more approval to merge squash-merge The pull request currently requires maintainers to "Squash Merge" Stale Strings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Productionise WebView >= 77 check
4 participants