From 0ab2528a7e7bf718eea3a857aaf91688262d7424 Mon Sep 17 00:00:00 2001 From: jim-daf Date: Wed, 22 Apr 2026 21:33:52 +0200 Subject: [PATCH] Guard WebViewActivity against MissingWebViewPackageException When the Android System WebView package is missing, disabled, or being updated, inflating the WebView throws an AndroidRuntimeException wrapping WebViewFactory.MissingWebViewPackageException. The activity then dies with no useful feedback for the user. Wrap the inflation and initial load in try/catch, log the failure, show a localized message and finish gracefully so the user can recover by reinstalling or enabling Android System WebView. --- .../wallet/page/common/WebViewActivity.kt | 25 ++++++++++++++++--- app/src/main/res/values/strings.xml | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/flowfoundation/wallet/page/common/WebViewActivity.kt b/app/src/main/java/com/flowfoundation/wallet/page/common/WebViewActivity.kt index d0379cc91..8dad64d52 100644 --- a/app/src/main/java/com/flowfoundation/wallet/page/common/WebViewActivity.kt +++ b/app/src/main/java/com/flowfoundation/wallet/page/common/WebViewActivity.kt @@ -3,10 +3,14 @@ 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() { @@ -14,9 +18,24 @@ class WebViewActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_webview) - findViewById(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(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() } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 372bebd54..987f8b61e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -830,4 +830,5 @@ 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. EVM on Flow address Recover profile + Android System WebView is unavailable on this device. Please install or enable it from the Play Store and try again.