Skip to content

Commit

Permalink
Correctly handle WebView update exception. (#4463)
Browse files Browse the repository at this point in the history
* Correctly handle WebView update exception.

* Simplify a bit.

* Clean up a bit.

* Clean up some more.
  • Loading branch information
dbrant authored Feb 9, 2024
1 parent 7ffaf29 commit db2df5c
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions app/src/main/java/org/wikipedia/page/PageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,7 @@ class PageActivity : BaseActivity(), PageFragment.Callback, LinkPreviewDialog.Lo
super.onCreate(savedInstanceState)
PreferenceManager.setDefaultValues(this, R.xml.preferences, false)
binding = ActivityPageBinding.inflate(layoutInflater)

try {
setContentView(binding.root)
} catch (e: Exception) {
if (!e.message.isNullOrEmpty() && e.message!!.lowercase(Locale.getDefault()).contains(EXCEPTION_MESSAGE_WEBVIEW) ||
!ThrowableUtil.getInnermostThrowable(e).message.isNullOrEmpty() &&
ThrowableUtil.getInnermostThrowable(e).message!!.lowercase(Locale.getDefault()).contains(EXCEPTION_MESSAGE_WEBVIEW)) {
// If the system failed to inflate our activity because of the WebView (which could
// be one of several types of exceptions), it likely means that the system WebView
// is in the process of being updated. In this case, show the user a message and
// bail immediately.
Toast.makeText(app, R.string.error_webview_updating, Toast.LENGTH_LONG).show()
finish()
return
}
throw e
}
setContentView(binding.root)

disposables.add(app.bus.subscribe(EventBusConsumer()))
updateProgressBar(false)
Expand Down Expand Up @@ -257,6 +241,24 @@ class PageActivity : BaseActivity(), PageFragment.Callback, LinkPreviewDialog.Lo
}
}

override fun onStart() {
try {
super.onStart()
} catch (e: Exception) {
if (e.message.orEmpty().contains(EXCEPTION_MESSAGE_WEBVIEW, true) ||
ThrowableUtil.getInnermostThrowable(e).message.orEmpty().contains(EXCEPTION_MESSAGE_WEBVIEW, true)) {
// If the system failed to inflate our activity because of the WebView (which could
// be one of several types of exceptions), it likely means that the system WebView
// is in the process of being updated. In this case, show the user a message and
// bail immediately.
Toast.makeText(app, R.string.error_webview_updating, Toast.LENGTH_LONG).show()
finish()
return
}
throw e
}
}

override fun onPrepareOptionsMenu(menu: Menu): Boolean {
if (!isDestroyed) {
binding.pageToolbarButtonTabs.updateTabCount(false)
Expand Down

0 comments on commit db2df5c

Please sign in to comment.