/*
- * Copyright © 2021 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2021-2022 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
*
* along with Privacy Cell. If not, see <http://www.gnu.org/licenses/>.
*/
+// 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
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
}
})
- // 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. <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.
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.
// 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)
}
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)
// 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)
}
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), "")
}
}