X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Factivities%2FPrivacyCellActivity.kt;h=86e7be51dfdec9270bd4d606cc1ee03053300d77;hb=b11b84b24c660fac3a69f2dbe4bd615d73811219;hp=13cfe7bda17cd00a996ae16b5303fb76b3160e91;hpb=fb7c0422487bfb7cbb65427468c2688c24b4b99b;p=PrivacyCell.git diff --git a/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCellActivity.kt b/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCellActivity.kt index 13cfe7b..86e7be5 100644 --- a/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCellActivity.kt +++ b/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCellActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Soren Stoutner . + * Copyright © 2021-2022 Soren Stoutner . * * This file is part of Privacy Cell . * @@ -17,16 +17,20 @@ * along with Privacy Cell. If not, see . */ +// The suppression of deprecation lint can be removed once the minimum API >= 31. +@file:Suppress("DEPRECATION") + package com.stoutner.privacycell.activities import android.Manifest +import android.annotation.SuppressLint import android.app.ActivityManager import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle -import android.telephony.PhoneStateListener +import android.telephony.PhoneStateListener // This can be replaced by `TelephonyCallback` once the minimum API >= 31. import android.telephony.ServiceState import android.telephony.TelephonyDisplayInfo import android.telephony.TelephonyManager @@ -56,11 +60,11 @@ import com.stoutner.privacycell.services.RealtimeMonitoringService class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener, PhonePermissionDialog.StoragePermissionDialogListener { // Declare the class variables. private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle - private lateinit var phoneStateListener: PhoneStateListener + private lateinit var phoneStateListener: PhoneStateListener // The `PhoneStateListener` can be replaced by `TelephonyCallback` once the minimum API >= 31. // Declare the class views. private lateinit var drawerLayout: DrawerLayout - private lateinit var stingrayTextView: TextView + private lateinit var summaryTextView: TextView override fun onCreate(savedInstanceState: Bundle?) { // Run the default commands. @@ -71,6 +75,7 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem // Get the preferences. val realtimeMonitoring = sharedPreferences.getBoolean(getString(R.string.realtime_monitoring_key), false) + val consider3gAntiquated = sharedPreferences.getBoolean(getString(R.string.consider_3g_antiquated_key), false) val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false) // Set the content view. @@ -85,7 +90,7 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem val toolbar = findViewById(R.id.toolbar) val stingrayLinearLayout = findViewById(R.id.stingray_linearlayout) val stingrayImageView = findViewById(R.id.stingray_imageview) - stingrayTextView = findViewById(R.id.stingray_textview) + summaryTextView = findViewById(R.id.summary_textview) val voiceNetworkLinearLayout = findViewById(R.id.voice_network_linearlayout) val voiceNetworkTextView = findViewById(R.id.voice_network) val voiceNetworkDetailsTextView = findViewById(R.id.voice_network_details) @@ -135,28 +140,57 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem } }) - // Define the phone state listener. + // Define the phone state listener. The `PhoneStateListener` can be replaced by `TelephonyCallback` once the minimum API >= 31. phoneStateListener = object : PhoneStateListener() { + @SuppressLint("SwitchIntDef") override fun onDisplayInfoChanged(telephonyDisplayInfo: TelephonyDisplayInfo) { + // Declare the stingray dialog type integer. + val summaryDialogTypeInteger: Int + // Populate the stingray security information. - if (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_NR) { // This is a secure 5G NR SA network. + if ((telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_NR) || (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_IWLAN) || + (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_UNKNOWN)) { // This is a secure network. // Populate the image view. - stingrayImageView.setImageDrawable(AppCompatResources.getDrawable(applicationContext, R.drawable.secure_5g_nr_sa)) + stingrayImageView.setImageDrawable(AppCompatResources.getDrawable(applicationContext, R.drawable.secure)) // Set the text. - stingrayTextView.text = getString(R.string.secure_from_stingray) + summaryTextView.text = getString(R.string.secure_protocols) // Set the text color. - stingrayTextView.setTextColor(getColor(R.color.blue_text)) - } else { // This is not a secure 5G NR SA network. + summaryTextView.setTextColor(getColor(R.color.blue_text)) + + // Set the stingray dialog type integer. + summaryDialogTypeInteger = WebViewDialog.STINGRAY + } else if ((telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_LTE) || (!consider3gAntiquated && (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_1xRTT || + (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_EVDO_0) || (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_EVDO_A) || + (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_EVDO_B) || (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_EHRPD) || + (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_UMTS) || (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_TD_SCDMA) || + (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_HSDPA) || (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_HSUPA) || + (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_HSPA) || (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_HSPAP)))) { + // This is an insecure network. // Populate the image view. - stingrayImageView.setImageDrawable(AppCompatResources.getDrawable(applicationContext, R.drawable.not_secure)) + stingrayImageView.setImageDrawable(AppCompatResources.getDrawable(applicationContext, R.drawable.insecure)) // Set the text. - stingrayTextView.text = getString(R.string.not_secure_from_stingray) + summaryTextView.text = getString(R.string.insecure_protocols) // Set the text color. - stingrayTextView.setTextColor(getColor(R.color.red_text)) + summaryTextView.setTextColor(getColor(R.color.yellow_900)) + + // Set the stingray dialog type integer. + summaryDialogTypeInteger = WebViewDialog.STINGRAY + } else { // This is an antiquated network. + // Populate the image view. + stingrayImageView.setImageDrawable(AppCompatResources.getDrawable(applicationContext, R.drawable.antiquated)) + + // Set the text. + summaryTextView.text = getString(R.string.antiquated_protocols) + + // Set the text color. + summaryTextView.setTextColor(getColor(R.color.red_text)) + + // Set the stingray dialog type integer. + summaryDialogTypeInteger = WebViewDialog.ANTIQUATED_NETWORK } // Get the strings that correspond to the network information. @@ -172,7 +206,7 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem // Set the stingray click listener. stingrayLinearLayout.setOnClickListener { // Instantiate the stingray dialog fragment. - val stingrayDialogFragment = WebViewDialog().type(WebViewDialog.STINGRAY) + val stingrayDialogFragment = WebViewDialog().type(summaryDialogTypeInteger) // Show the alert dialog. stingrayDialogFragment.show(supportFragmentManager, getString(R.string.stingrays)) @@ -217,8 +251,9 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_CA -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_LTE_CA) TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_LTE_ADVANCED_PRO) TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_NR_NSA) - TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_NR_NSA_MMWAVE) - else -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_NR_NSA_MMWAVE) + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_NR_NSA_MMWAVE) // Can be removed once the minimum API >= 31. + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_NR_ADVANCED) + else -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_NONE) } // Show the alert dialog. @@ -326,7 +361,7 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem // Get a handle for the telephony manager. val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager - // Unregister the telephony manager listener. + // Unregister the telephony manager listener. The `PhoneStateListener` can be replaced by `TelephonyCallback` once the minimum API >= 31. telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE) } @@ -341,6 +376,14 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem startActivity(settingsIntent) } + R.id.protocols -> { + // Create an intent to load the Protocols activity. + val protocolsIntent = Intent(this, ProtocolsActivity::class.java) + + // Make it so. + startActivity(protocolsIntent) + } + R.id.logcat -> { // Logcat. // Create an intent to load the Logcat activity. val logcatIntent = Intent(this, LogcatActivity::class.java) @@ -469,7 +512,7 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem registerTelephonyManagerListener() } else { // The read phone state permission was denied. // Display the phone permission text on the main activity. - stingrayTextView.text = getString(R.string.phone_permission_text) + summaryTextView.text = getString(R.string.phone_permission_text) } } } @@ -478,7 +521,7 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem // Get a handle for the telephony manager. val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager - // Listen to changes in the cell network state. + // Listen to changes in the cell network state. The `PhoneStateListener` can be replaced by `TelephonyCallback` once the minimum API >= 31. telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED or PhoneStateListener.LISTEN_SERVICE_STATE) } @@ -516,7 +559,8 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_CA -> arrayOf(getString(R.string.lte_ca), getString(R.string.lte_ca_detail)) TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO -> arrayOf(getString(R.string.lte_advanced_pro), getString(R.string.lte_advanced_pro_detail)) TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA -> arrayOf(getString(R.string.nr_nsa), getString(R.string.nr_nsa_detail)) - TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE -> arrayOf(getString(R.string.nr_nsa_mmwave), getString(R.string.nr_nsa_mmwave_detail)) + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE -> arrayOf(getString(R.string.nr_nsa_mmwave), getString(R.string.nr_nsa_mmwave_detail)) // Can be removed once the minimum API >= 31. + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED -> arrayOf(getString(R.string.nr_advanced), getString(R.string.nr_advanced_detail)) else -> arrayOf(getString(R.string.error), "") } }