Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +33 to +37
Copy link

Copilot AI Apr 22, 2026

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 the toast(msgRes: Int = 0, msg: String? = null, duration: Int = ...) helper signature (the second positional parameter is msg: String?). This should be passed as a named argument (duration = Toast.LENGTH_LONG) or by providing msg = null explicitly; otherwise this will not compile.

Suggested change
toast(R.string.webview_unavailable, Toast.LENGTH_LONG)
finish()
} catch (e: Exception) {
loge(e)
toast(R.string.webview_unavailable, Toast.LENGTH_LONG)
toast(R.string.webview_unavailable, duration = Toast.LENGTH_LONG)
finish()
} catch (e: Exception) {
loge(e)
toast(R.string.webview_unavailable, duration = Toast.LENGTH_LONG)

Copilot uses AI. Check for mistakes.
finish()
Comment on lines +26 to +38
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

The new broad catch (e: Exception) will also catch unrelated failures (e.g., url!! NPE if the intent extra is missing after process death / external launch) and then shows webview_unavailable, which would be misleading and make debugging harder. Consider validating url before entering the WebView inflate/load block (and handling a missing URL separately), and limit the webview_unavailable toast to the specific WebView-provider failure (e.g., only for the known WebView inflation exception), while letting unexpected exceptions surface or showing a generic error.

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +38
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Both catch blocks have identical handling. If the intent is just to guard WebView inflation, this can be simplified (single catch + type/cause check, or a small helper) to avoid duplication and reduce the chance the handlers diverge later.

Copilot uses AI. Check for mistakes.
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,5 @@
<string name="confirm_copy_address_tips">You have copied an EVM address on the Flow network, please make sure you only send assets on the Flow network to this address otherwise they will be lost.</string>
<string name="evm_on_flow_address">EVM on Flow address</string>
<string name="recover_profile">Recover profile</string>
<string name="webview_unavailable">Android System WebView is unavailable on this device. Please install or enable it from the Play Store and try again.</string>
</resources>
Loading