From 6cd34614f607c51a62eed68d98996990969e5909 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 2 May 2020 19:03:48 -0400 Subject: [PATCH] More extreme method for enforcing WebView availability --- app/src/main/AndroidManifest.xml | 5 ++++ app/src/main/java/eu/kanade/tachiyomi/App.kt | 10 +++++++ .../tachiyomi/ui/main/ForceCloseActivity.kt | 28 +++++++++++++++++++ .../kanade/tachiyomi/ui/main/MainActivity.kt | 7 ----- .../tachiyomi/util/system/WebViewUtil.kt | 11 +++++++- 5 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/main/ForceCloseActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 261df31e8..95e93bd14 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -40,6 +40,11 @@ android:name="android.app.shortcuts" android:resource="@xml/shortcuts" /> + () { binding = MainActivityBinding.inflate(layoutInflater) - // Enforce WebView availability - if (!WebViewUtil.supportsWebView(this)) { - toast(R.string.information_webview_required, Toast.LENGTH_LONG) - finishAndRemoveTask() - } - // Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079 if (!isTaskRoot) { finish() diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt index 3eeb60bc3..6eaf6bc9f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.util.system import android.content.Context import android.content.pm.PackageManager +import android.webkit.CookieManager import android.webkit.WebView object WebViewUtil { @@ -9,9 +10,17 @@ object WebViewUtil { Regex(""".*Chrome/(\d+)\..*""") } - const val MINIMUM_WEBVIEW_VERSION = 79 + const val MINIMUM_WEBVIEW_VERSION = 80 fun supportsWebView(context: Context): Boolean { + try { + // May throw android.webkit.WebViewFactory$MissingWebViewPackageException if WebView + // is not installed + CookieManager.getInstance() + } catch (e: Exception) { + return false + } + return context.packageManager.hasSystemFeature(PackageManager.FEATURE_WEBVIEW) } }