X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyCell.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Fdialogs%2FWebViewDialog.kt;h=010342457aff73fa6e8a4521912636ff3e9c5d45;hp=5961c2e51c0500773f7dbe6770b3487b4ff0658b;hb=5d8e96c54cad4115e962eac556c10f871807f02f;hpb=70fa89f618b62a9d17064699ec130341069aa77d diff --git a/app/src/main/java/com/stoutner/privacycell/dialogs/WebViewDialog.kt b/app/src/main/java/com/stoutner/privacycell/dialogs/WebViewDialog.kt index 5961c2e..0103424 100644 --- a/app/src/main/java/com/stoutner/privacycell/dialogs/WebViewDialog.kt +++ b/app/src/main/java/com/stoutner/privacycell/dialogs/WebViewDialog.kt @@ -14,19 +14,24 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Privacy Browser. If not, see . + * along with Privacy Cell. If not, see . */ package com.stoutner.privacycell.dialogs import android.app.Dialog +import android.content.Intent import android.content.res.Configuration import android.os.Bundle +import android.webkit.WebResourceRequest +import android.webkit.WebResourceResponse import android.webkit.WebView +import android.webkit.WebViewClient import androidx.appcompat.app.AlertDialog import androidx.fragment.app.DialogFragment import androidx.webkit.WebSettingsCompat +import androidx.webkit.WebViewAssetLoader import androidx.webkit.WebViewFeature import com.stoutner.privacycell.R @@ -41,6 +46,35 @@ class WebViewDialog : DialogFragment() { const val PERMISSIONS = 0 const val PRIVACY_POLICY = 1 const val CHANGELOG = 2 + const val LICENSES = 3 + const val CONTRIBUTORS = 4 + const val STINGRAY = 5 + const val NETWORK_UNKNOWN = 6 + const val NETWORK_GPRS = 7 + const val NETWORK_EDGE = 8 + const val NETWORK_UMTS = 9 + const val NETWORK_CDMA = 10 + const val NETWORK_EVDO_0 = 11 + const val NETWORK_EVDO_A = 12 + const val NETWORK_1xRTT = 13 + const val NETWORK_HSDPA = 14 + const val NETWORK_HSUPA = 15 + const val NETWORK_HSPA = 16 + const val NETWORK_IDEN = 17 + const val NETWORK_EVDO_B = 18 + const val NETWORK_LTE = 19 + const val NETWORK_EHRPD = 20 + const val NETWORK_HSPAP = 21 + const val NETWORK_GSM = 22 + const val NETWORK_TD_SCDMA = 23 + const val NETWORK_IWLAN = 24 + const val NETWORK_NR = 25 + const val OVERRIDE_NETWORK_NONE = 26 + const val OVERRIDE_NETWORK_LTE_CA = 27 + const val OVERRIDE_NETWORK_LTE_ADVANCED_PRO = 28 + const val OVERRIDE_NETWORK_NR_NSA = 29 + const val OVERRIDE_NETWORK_NR_NSA_MMWAVE = 30 // Can be removed once the minimum API >= 31. + const val OVERRIDE_NETWORK_NR_ADVANCED = 31 } // Define the class views. @@ -96,6 +130,238 @@ class WebViewDialog : DialogFragment() { // Set the title. dialogBuilder.setTitle(R.string.changelog) } + + LICENSES -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.licenses) + + // Set the title. + dialogBuilder.setTitle(R.string.licenses) + } + + CONTRIBUTORS -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.contributors) + + // Set the tile. + dialogBuilder.setTitle(R.string.contributors) + } + + STINGRAY -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.secure_5g_nr_sa) + + // Set the tile. + dialogBuilder.setTitle(R.string.stingrays) + } + + NETWORK_UNKNOWN -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.unknown) + } + + NETWORK_GPRS -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.gprs) + } + + NETWORK_EDGE -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.edge) + } + + NETWORK_UMTS -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.umts) + } + + NETWORK_CDMA -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.cdma) + } + + NETWORK_EVDO_0 -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.evdo_0) + } + + NETWORK_EVDO_A -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.evdo_a) + } + + NETWORK_1xRTT -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.rtt) + } + + NETWORK_HSDPA -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.hsdpa) + } + + NETWORK_HSUPA -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.hsupa) + } + + NETWORK_HSPA -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.hspa) + } + + NETWORK_IDEN -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.iden) + } + + NETWORK_EVDO_B -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.evdo_b) + } + + NETWORK_LTE -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.lte) + } + + NETWORK_EHRPD -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.ehrpd) + } + + NETWORK_HSPAP -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.hspap) + } + + NETWORK_GSM -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.gsm) + } + + NETWORK_TD_SCDMA -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.td_scdma) + } + + NETWORK_IWLAN -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.iwlan) + } + + NETWORK_NR -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.nr) + } + + OVERRIDE_NETWORK_NONE -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.none) + } + + OVERRIDE_NETWORK_LTE_CA -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.lte_ca) + } + + OVERRIDE_NETWORK_LTE_ADVANCED_PRO -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.lte_ca) + } + + OVERRIDE_NETWORK_NR_NSA -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.nr_nsa) + } + + OVERRIDE_NETWORK_NR_NSA_MMWAVE -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.nr_nsa_mmwave) + } + + OVERRIDE_NETWORK_NR_ADVANCED -> { + // Set the icon. + dialogBuilder.setIcon(R.drawable.privacy_policy) + + // Set the title. + dialogBuilder.setTitle(R.string.nr_advanced) + } } // Set the view. @@ -122,14 +388,69 @@ class WebViewDialog : DialogFragment() { WebSettingsCompat.setForceDark(webView.settings, WebSettingsCompat.FORCE_DARK_ON) } - // Create a WebView asset loader. TODO. - // val webViewAssetLoader = WebViewAssetLoader.Builder().addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(requireContext())).build() + // Create a WebView asset loader. + val webViewAssetLoader = WebViewAssetLoader.Builder().addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(requireContext())).build() + + // Set a WebView client. + webView.webViewClient = object : WebViewClient() { + // Send external links to a web browser. + override fun shouldOverrideUrlLoading(view: WebView, webResourceRequest: WebResourceRequest): Boolean { + // Create an intent to view the URL. + val urlIntent = Intent(Intent.ACTION_VIEW) + + // Add the URL to the intent. + urlIntent.data = webResourceRequest.url + + // Make it so. + startActivity(urlIntent) + + // Consume the click. + return true + } + + // Process asset requests with the asset loader. + override fun shouldInterceptRequest(webView: WebView, webResourceRequest: WebResourceRequest): WebResourceResponse? { + // This allows using the `appassets.androidplatform.net` URL, which handles the loading of SVG files, which otherwise is prevented by the CORS policy. + return webViewAssetLoader.shouldInterceptRequest(webResourceRequest.url) + } + } // Load the WebView data according to the dialog type. when (dialogType) { - PERMISSIONS -> webView.loadUrl("file:///android_asset/en/permissions.html") - PRIVACY_POLICY -> webView.loadUrl("file:///android_asset/en/privacy_policy.html") - CHANGELOG -> webView.loadUrl("file:///android_asset/en/changelog.html") + PERMISSIONS -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/permissions.html") + PRIVACY_POLICY -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/privacy_policy.html") + CHANGELOG -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/changelog.html") + LICENSES -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/licenses.html") + CONTRIBUTORS -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/contributors.html") + STINGRAY -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/stingrays.html") + NETWORK_UNKNOWN -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_unknown.html") + NETWORK_GPRS -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_gprs.html") + NETWORK_EDGE -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_edge.html") + NETWORK_UMTS -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_umts.html") + NETWORK_CDMA -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_cdma.html") + NETWORK_EVDO_0 -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_evdo_0.html") + NETWORK_EVDO_A -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_evdo_a.html") + NETWORK_1xRTT -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_1xrtt.html") + NETWORK_HSDPA -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_hsdpa.html") + NETWORK_HSUPA -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_hsupa.html") + NETWORK_HSPA -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_hspa.html") + NETWORK_IDEN -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_iden.html") + NETWORK_EVDO_B -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_evdo_b.html") + NETWORK_LTE -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_lte.html") + NETWORK_EHRPD -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_ehrpd.html") + NETWORK_HSPAP -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_hspap.html") + NETWORK_GSM -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_gsm.html") + NETWORK_TD_SCDMA -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_td_scdma.html") + NETWORK_IWLAN -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_iwlan.html") + NETWORK_NR -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/network_nr.html") + OVERRIDE_NETWORK_NONE -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/override_network_none.html") + OVERRIDE_NETWORK_LTE_CA -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/override_network_lte_ca.html") + OVERRIDE_NETWORK_LTE_ADVANCED_PRO -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + + "/explanations/override_network_lte_advanced_pro.html") + OVERRIDE_NETWORK_NR_NSA -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/override_network_nr_nsa.html") + // The item below can be removed once the minimum API >= 31. + OVERRIDE_NETWORK_NR_NSA_MMWAVE -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/override_network_nr_nsa_mmwave.html") + OVERRIDE_NETWORK_NR_ADVANCED -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/explanations/override_network_nr_advanced.html") } // Scroll the WebView if the saved instance state is not null.