-
Notifications
You must be signed in to change notification settings - Fork 10
Guard WebViewActivity against MissingWebViewPackageException #2994
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,20 +3,39 @@ package com.flowfoundation.wallet.page.common | |
| import android.content.Context | ||
| import android.content.Intent | ||
| import android.os.Bundle | ||
| import android.util.AndroidRuntimeException | ||
| import android.view.MenuItem | ||
| import android.widget.Toast | ||
| import com.flowfoundation.wallet.R | ||
| import com.flowfoundation.wallet.base.activity.BaseActivity | ||
| import com.flowfoundation.wallet.page.browser.widgets.LilicoWebView | ||
| import com.flowfoundation.wallet.utils.loge | ||
| import com.flowfoundation.wallet.utils.toast | ||
|
|
||
| class WebViewActivity : BaseActivity() { | ||
|
|
||
| private val url by lazy { intent.getStringExtra(URL) } | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_webview) | ||
| findViewById<LilicoWebView>(R.id.webview).apply { | ||
| loadUrl(this@WebViewActivity.url!!) | ||
| // Inflating the WebView can throw AndroidRuntimeException wrapping | ||
| // WebViewFactory$MissingWebViewPackageException on devices where the | ||
| // Android System WebView package is missing, disabled, or being updated. | ||
| // Crashing the activity in that case (issue #1256) leaves the user | ||
| // with no recourse. Catch it, surface a clear message and finish. | ||
| try { | ||
| setContentView(R.layout.activity_webview) | ||
| findViewById<LilicoWebView>(R.id.webview).apply { | ||
| loadUrl(this@WebViewActivity.url!!) | ||
| } | ||
| } catch (e: AndroidRuntimeException) { | ||
| loge(e) | ||
| toast(R.string.webview_unavailable, Toast.LENGTH_LONG) | ||
| finish() | ||
| } catch (e: Exception) { | ||
| loge(e) | ||
| toast(R.string.webview_unavailable, Toast.LENGTH_LONG) | ||
| finish() | ||
|
Comment on lines
+26
to
+38
|
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toast(R.string.webview_unavailable, Toast.LENGTH_LONG)does not match thetoast(msgRes: Int = 0, msg: String? = null, duration: Int = ...)helper signature (the second positional parameter ismsg: String?). This should be passed as a named argument (duration = Toast.LENGTH_LONG) or by providingmsg = nullexplicitly; otherwise this will not compile.