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

Handle failures to parse system WebView version #17441

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

lukstbit
Copy link
Member

@lukstbit lukstbit commented Nov 14, 2024

Purpose / Description

There are several reports in acra about crashes in checkWebviewVersion() when parsing the system WebView version. It seems some of those versions appear as "Developer Build" and not a simple number like we expect.

https://ankidroid.org/acra/app/1/bug/256775/report/e8bb99dc-2cb8-4a73-ab66-3491c1e2752f
https://ankidroid.org/acra/app/1/bug/253230/report/6d761065-e7d6-498a-9323-84a68f7fbfd4

Stacktrace:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ichi2.anki/com.ichi2.anki.DeckPicker}: java.lang.NumberFormatException: For input string: "Developer Build"
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2683)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2744)
	at android.app.ActivityThread.-wrap12(ActivityThread.java)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1495)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:154)
	at android.app.ActivityThread.main(ActivityThread.java:6181)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
Caused by: java.lang.NumberFormatException: For input string: "Developer Build"
	at java.lang.Integer.parseInt(Integer.java:521)
	at java.lang.Integer.parseInt(Integer.java:556)
	at com.ichi2.anki.InitialActivity.checkWebviewVersion(InitialActivity.java:147)
	at com.ichi2.anki.DeckPicker.onCreate(DeckPicker.kt:573)
	at android.app.Activity.performCreate(Activity.java:6785)

The fix consists in catching exceptions from version parsing and displaying a dialog about the minimum WebView version. I also added a checkbox to this dialog to hide the dialog on future runs, if the users have a developer build it seems reasonable to expect it's above our minimum WebView version requirements.

The dialog:
zz

I added the Review High Priority label because I think these users can't access the DeckPicker.

How Has This Been Tested?

Not tested, just opened the dialog to see how it looks.

Checklist

  • 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

@lukstbit lukstbit added the Review High Priority Request for high priority review label Nov 14, 2024
@lukstbit lukstbit added this to the 2.19.2 release milestone Nov 14, 2024
Copy link
Contributor

Important

Maintainers: This PR contains Strings changes

  1. Sync Translations before merging this PR and wait for the action to complete
  2. Review and merge the auto-generated PR in order to sync all user-submitted translations
  3. Sync Translations again and merge the PR so the huge automated string changes caused by merging this PR are by themselves and easy to review

@lukstbit lukstbit changed the title Handle failures to parse system WebView versions Handle failures to parse system WebView version Nov 14, 2024
@mikehardy
Copy link
Member

I was tempted to say "this was mostly for developers using really old emulators that can't update so just let it pass if we can't parse it" but then I saw that one of them was actually out of date - our minimum is 77 and this was M74:

App_Chromium_M74_for_AFP_dvlp_20191128_1

Which is kind of crazy.

So I think experimentation with Brayan's suggestion is really worthwhile - we can likely not crash and only allow webviews that are actually new enough

There's a compat API that allows us to use longVersionCode for all APIs

https://developer.android.com/reference/kotlin/androidx/core/content/pm/PackageInfoCompat?hl=en#getLongVersionCode(android.content.pm.PackageInfo)

As an incremental improvement - that may be sufficient without any ability to suppress+continue so could be cherry-picked easily if it was in one nice commit

As a feature, the ability to suppress + continue seems nice but strings are hard to cherry-pick across branches so that would be better as a 2.20 commit and it would need to be separate

@BrayanDSO BrayanDSO added the Needs Author Reply Waiting for a reply from the original author label Nov 14, 2024
I used the first stable WebView versionCode that I could find,
corresponding to version 77.0.3865.73.
See https://www.apkmirror.com/apk/google-inc/android-system-webview/android-system-webview-77-0-3865-73-release/

The code will still display the app version to the user if it's available or
0 otherwise with the dialog's text to be modified in the future.
@lukstbit
Copy link
Member Author

I switched to using the compat longVersionCode that Brayan suggested. Hope the version code I found is ok, see commit message.
I've also not made any changes to strings to not mess cherry-picking and left a TODO for that for now.

@lukstbit lukstbit removed Needs Author Reply Waiting for a reply from the original author Strings labels Nov 15, 2024
Copy link
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

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

AFAICT, the webview version code is alright. It looks like it follows a pattern and starts with the third element in the version name.

e.g. 119.0.6045.193604519326

@BrayanDSO BrayanDSO added the Needs Second Approval Has one approval, one more approval to merge label Nov 15, 2024
@mikehardy mikehardy added the Needs Author Reply Waiting for a reply from the original author label Nov 15, 2024
@mikehardy mikehardy added this pull request to the merge queue Nov 15, 2024
@mikehardy mikehardy added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Author Reply Waiting for a reply from the original author Review High Priority Request for high priority review Needs Second Approval Has one approval, one more approval to merge labels Nov 15, 2024
Merged via the queue into ankidroid:main with commit 60a8363 Nov 15, 2024
9 checks passed
@github-actions github-actions bot modified the milestones: 2.19.2 release, 2.20 Release Nov 15, 2024
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Nov 15, 2024
@lukstbit lukstbit deleted the fix_handleDevWebViewVersion branch November 15, 2024 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants