Add a higher level warning for antiquated protocols. https://redmine.stoutner.com...
[PrivacyCell.git] / app / src / main / java / com / stoutner / privacycell / activities / PrivacyCellActivity.kt
index 7d6fd776b7d36726bb069521309de934bcbf1df5..86e7be51dfdec9270bd4d606cc1ee03053300d77 100644 (file)
@@ -64,7 +64,7 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem
 
     // 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.
@@ -75,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.
@@ -89,7 +90,7 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem
         val toolbar = findViewById<Toolbar>(R.id.toolbar)
         val stingrayLinearLayout = findViewById<LinearLayout>(R.id.stingray_linearlayout)
         val stingrayImageView = findViewById<ImageView>(R.id.stingray_imageview)
-        stingrayTextView = findViewById(R.id.stingray_textview)
+        summaryTextView = findViewById(R.id.summary_textview)
         val voiceNetworkLinearLayout = findViewById<LinearLayout>(R.id.voice_network_linearlayout)
         val voiceNetworkTextView = findViewById<TextView>(R.id.voice_network)
         val voiceNetworkDetailsTextView = findViewById<TextView>(R.id.voice_network_details)
@@ -143,25 +144,53 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem
         phoneStateListener = object : PhoneStateListener() {
             @SuppressLint("SwitchIntDef")
             override fun onDisplayInfoChanged(telephonyDisplayInfo: TelephonyDisplayInfo) {
+                // Declare the stingray dialog type integer.
+                val summaryDialogTypeInteger: Int
+
                 // Populate the stingray security information.  <https://source.android.com/devices/tech/connect/acts-5g-testing>
-                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))
+
+                    // Set the text.
+                    summaryTextView.text = getString(R.string.secure_protocols)
+
+                    // Set the text color.
+                    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.secure_5g_nr_sa))
+                    stingrayImageView.setImageDrawable(AppCompatResources.getDrawable(applicationContext, R.drawable.insecure))
 
                     // Set the text.
-                    stingrayTextView.text = getString(R.string.secure_from_stingray)
+                    summaryTextView.text = getString(R.string.insecure_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.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.not_secure))
+                    stingrayImageView.setImageDrawable(AppCompatResources.getDrawable(applicationContext, R.drawable.antiquated))
 
                     // Set the text.
-                    stingrayTextView.text = getString(R.string.not_secure_from_stingray)
+                    summaryTextView.text = getString(R.string.antiquated_protocols)
 
                     // Set the text color.
-                    stingrayTextView.setTextColor(getColor(R.color.red_text))
+                    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.
@@ -177,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))
@@ -483,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)
             }
         }
     }