X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyCell.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Factivities%2FPrivacyCellActivity.kt;h=7d6fd776b7d36726bb069521309de934bcbf1df5;hp=13cfe7bda17cd00a996ae16b5303fb76b3160e91;hb=dc76c6f07fd9a5718049d160e079842fa60ff406;hpb=fb7c0422487bfb7cbb65427468c2688c24b4b99b 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..7d6fd77 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,7 +60,7 @@ 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 @@ -135,8 +139,9 @@ 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) { // Populate the stingray security information. if (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_NR) { // This is a secure 5G NR SA network. @@ -217,8 +222,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 +332,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 +347,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) @@ -478,7 +492,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 +530,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), "") } }