+ // 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. <https://source.android.com/devices/tech/connect/acts-5g-testing>
+ 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.insecure))
+
+ // Set the text.
+ summaryTextView.text = getString(R.string.insecure_protocols)
+
+ // Set the text color.
+ 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.
+ val dataNetworkType = getNetworkType(telephonyDisplayInfo.networkType)
+ val additionalNetworkInfo = getAdditionalNetworkInfo(telephonyDisplayInfo.overrideNetworkType)
+
+ // Populate the data network text views.
+ dataNetworkTextView.text = getString(R.string.data_network, dataNetworkType[0])
+ dataNetworkDetailsTextView.text = dataNetworkType[1]
+ additionalNetworkInfoTextView.text = getString(R.string.additional_network_info, additionalNetworkInfo[0])
+ additionalNetworkInfoDetailsTextView.text = additionalNetworkInfo[1]
+
+ // Set the stingray click listener.
+ stingrayLinearLayout.setOnClickListener {
+ // Instantiate the stingray dialog fragment.
+ val stingrayDialogFragment = WebViewDialog().type(summaryDialogTypeInteger)
+
+ // Show the alert dialog.
+ stingrayDialogFragment.show(supportFragmentManager, getString(R.string.stingrays))
+ }
+
+ // Set the data network click listener.
+ dataNetworkLinearLayout.setOnClickListener {
+ // Instantiate the data network dialog fragment according to the network type.
+ val dataNetworkDialogFragment = when (telephonyDisplayInfo.networkType) {
+ TelephonyManager.NETWORK_TYPE_UNKNOWN -> WebViewDialog().type(WebViewDialog.NETWORK_UNKNOWN)
+ TelephonyManager.NETWORK_TYPE_GPRS -> WebViewDialog().type(WebViewDialog.NETWORK_GPRS)
+ TelephonyManager.NETWORK_TYPE_EDGE -> WebViewDialog().type(WebViewDialog.NETWORK_EDGE)
+ TelephonyManager.NETWORK_TYPE_UMTS -> WebViewDialog().type(WebViewDialog.NETWORK_UMTS)
+ TelephonyManager.NETWORK_TYPE_CDMA -> WebViewDialog().type(WebViewDialog.NETWORK_CDMA)
+ TelephonyManager.NETWORK_TYPE_EVDO_0 -> WebViewDialog().type(WebViewDialog.NETWORK_EVDO_0)
+ TelephonyManager.NETWORK_TYPE_EVDO_A -> WebViewDialog().type(WebViewDialog.NETWORK_EVDO_A)
+ TelephonyManager.NETWORK_TYPE_1xRTT -> WebViewDialog().type(WebViewDialog.NETWORK_1xRTT)
+ TelephonyManager.NETWORK_TYPE_HSDPA -> WebViewDialog().type(WebViewDialog.NETWORK_HSDPA)
+ TelephonyManager.NETWORK_TYPE_HSUPA -> WebViewDialog().type(WebViewDialog.NETWORK_HSUPA)
+ TelephonyManager.NETWORK_TYPE_HSPA -> WebViewDialog().type(WebViewDialog.NETWORK_HSPA)
+ TelephonyManager.NETWORK_TYPE_IDEN -> WebViewDialog().type(WebViewDialog.NETWORK_IDEN)
+ TelephonyManager.NETWORK_TYPE_EVDO_B -> WebViewDialog().type(WebViewDialog.NETWORK_EVDO_B)
+ TelephonyManager.NETWORK_TYPE_LTE -> WebViewDialog().type(WebViewDialog.NETWORK_LTE)
+ TelephonyManager.NETWORK_TYPE_EHRPD -> WebViewDialog().type(WebViewDialog.NETWORK_EHRPD)
+ TelephonyManager.NETWORK_TYPE_HSPAP -> WebViewDialog().type(WebViewDialog.NETWORK_HSPAP)
+ TelephonyManager.NETWORK_TYPE_GSM -> WebViewDialog().type(WebViewDialog.NETWORK_GSM)
+ TelephonyManager.NETWORK_TYPE_TD_SCDMA -> WebViewDialog().type(WebViewDialog.NETWORK_TD_SCDMA)
+ TelephonyManager.NETWORK_TYPE_IWLAN -> WebViewDialog().type(WebViewDialog.NETWORK_IWLAN)
+ TelephonyManager.NETWORK_TYPE_NR -> WebViewDialog().type(WebViewDialog.NETWORK_NR)
+ else -> WebViewDialog().type(WebViewDialog.NETWORK_UNKNOWN)
+ }
+
+ // Show the alert dialog.
+ dataNetworkDialogFragment.show(supportFragmentManager, getString(R.string.voice_network))
+ }
+
+ // Set the additional network info click listener.
+ additionalNetworkInfoLinearLayout.setOnClickListener {
+ // Instantiate the initial network info dialog fragment according to the network type.
+ val additionalNetworkInfoDialogFragment = when (telephonyDisplayInfo.overrideNetworkType) {
+ TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE -> WebViewDialog().type(WebViewDialog.OVERRIDE_NETWORK_NONE)
+ 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) // 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.
+ additionalNetworkInfoDialogFragment.show(supportFragmentManager, getString(R.string.voice_network))
+ }
+ }
+
+ override fun onServiceStateChanged(serviceState: ServiceState) {
+ // Get the network registration info for the voice network, which is the second of the three entries (the first appears to be Wi-Fi and the third appears to be the cell data network).
+ val networkRegistrationInfo = serviceState.networkRegistrationInfoList[1]
+
+ // Get the voice network type.
+ val voiceNetworkType = getNetworkType(networkRegistrationInfo.accessNetworkTechnology)
+
+ // Populate the voice network text views.
+ voiceNetworkTextView.text = getString(R.string.voice_network, voiceNetworkType[0])
+ voiceNetworkDetailsTextView.text = voiceNetworkType[1]
+
+ // Set the voice network click listener.
+ voiceNetworkLinearLayout.setOnClickListener {
+ // Instantiate the voice network dialog fragment according to the network type.
+ val voiceNetworkDialogFragment = when (networkRegistrationInfo.accessNetworkTechnology) {
+ TelephonyManager.NETWORK_TYPE_UNKNOWN -> WebViewDialog().type(WebViewDialog.NETWORK_UNKNOWN)
+ TelephonyManager.NETWORK_TYPE_GPRS -> WebViewDialog().type(WebViewDialog.NETWORK_GPRS)
+ TelephonyManager.NETWORK_TYPE_EDGE -> WebViewDialog().type(WebViewDialog.NETWORK_EDGE)
+ TelephonyManager.NETWORK_TYPE_UMTS -> WebViewDialog().type(WebViewDialog.NETWORK_UMTS)
+ TelephonyManager.NETWORK_TYPE_CDMA -> WebViewDialog().type(WebViewDialog.NETWORK_CDMA)
+ TelephonyManager.NETWORK_TYPE_EVDO_0 -> WebViewDialog().type(WebViewDialog.NETWORK_EVDO_0)
+ TelephonyManager.NETWORK_TYPE_EVDO_A -> WebViewDialog().type(WebViewDialog.NETWORK_EVDO_A)
+ TelephonyManager.NETWORK_TYPE_1xRTT -> WebViewDialog().type(WebViewDialog.NETWORK_1xRTT)
+ TelephonyManager.NETWORK_TYPE_HSDPA -> WebViewDialog().type(WebViewDialog.NETWORK_HSDPA)
+ TelephonyManager.NETWORK_TYPE_HSUPA -> WebViewDialog().type(WebViewDialog.NETWORK_HSUPA)
+ TelephonyManager.NETWORK_TYPE_HSPA -> WebViewDialog().type(WebViewDialog.NETWORK_HSPA)
+ TelephonyManager.NETWORK_TYPE_IDEN -> WebViewDialog().type(WebViewDialog.NETWORK_IDEN)
+ TelephonyManager.NETWORK_TYPE_EVDO_B -> WebViewDialog().type(WebViewDialog.NETWORK_EVDO_B)
+ TelephonyManager.NETWORK_TYPE_LTE -> WebViewDialog().type(WebViewDialog.NETWORK_LTE)
+ TelephonyManager.NETWORK_TYPE_EHRPD -> WebViewDialog().type(WebViewDialog.NETWORK_EHRPD)
+ TelephonyManager.NETWORK_TYPE_HSPAP -> WebViewDialog().type(WebViewDialog.NETWORK_HSPAP)
+ TelephonyManager.NETWORK_TYPE_GSM -> WebViewDialog().type(WebViewDialog.NETWORK_GSM)
+ TelephonyManager.NETWORK_TYPE_TD_SCDMA -> WebViewDialog().type(WebViewDialog.NETWORK_TD_SCDMA)
+ TelephonyManager.NETWORK_TYPE_IWLAN -> WebViewDialog().type(WebViewDialog.NETWORK_IWLAN)
+ TelephonyManager.NETWORK_TYPE_NR -> WebViewDialog().type(WebViewDialog.NETWORK_NR)
+ else -> WebViewDialog().type(WebViewDialog.NETWORK_UNKNOWN)
+ }
+
+ // Show the alert dialog.
+ voiceNetworkDialogFragment.show(supportFragmentManager, getString(R.string.voice_network))
+ }
+ }
+ }
+