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.os.Build
val protocolHelper = ProtocolHelper()
// Get a handle for the subscription manager.
- val subscriptionManager = getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager
+ val subscriptionManager = getSystemService(TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager
// Define the phone state listener. The `PhoneStateListener` can be replaced by `TelephonyCallback` once the minimum API >= 31.
phoneStateListener = object : PhoneStateListener() {
additionalNetworkInfoTextView.text = getString(R.string.additional_network_info, additionalNetworkInfoStringArray[0])
additionalNetworkInfoDetailsTextView.text = additionalNetworkInfoStringArray[1]
- // Set the color of the data network.
+ // Set the color of the data network text views.
when (dataNetworkSecurityStatus) {
- ProtocolHelper.SECURE -> dataNetworkTextView.setTextColor(getColor(R.color.blue_text))
- ProtocolHelper.INSECURE -> dataNetworkTextView.setTextColor(getColor(R.color.yellow_text))
- ProtocolHelper.ANTIQUATED -> dataNetworkTextView.setTextColor(getColor(R.color.red_text))
- }
+ ProtocolHelper.SECURE -> {
+ // Set the color of the data network text views to be blue.
+ dataNetworkTextView.setTextColor(getColor(R.color.blue_text))
+ additionalNetworkInfoTextView.setTextColor(getColor(R.color.blue_text))
+ }
- // Set the color of the additional network info.
- when (protocolHelper.checkAdditionalNetworkInfo(additionalNetworkInfoTypeInt)) {
- ProtocolHelper.SECURE -> additionalNetworkInfoTextView.setTextColor(getColor(R.color.blue_text))
- ProtocolHelper.INSECURE -> additionalNetworkInfoTextView.setTextColor(getColor(R.color.yellow_text))
- ProtocolHelper.ANTIQUATED -> additionalNetworkInfoTextView.setTextColor(getColor(R.color.red_text))
+ ProtocolHelper.INSECURE -> {
+ // Set the color of the data network text views to be yellow.
+ dataNetworkTextView.setTextColor(getColor(R.color.yellow_text))
+ additionalNetworkInfoTextView.setTextColor(getColor(R.color.yellow_text))
+ }
+
+ ProtocolHelper.ANTIQUATED -> {
+ // Set the color of the data network text views to be red.
+ dataNetworkTextView.setTextColor(getColor(R.color.red_text))
+ additionalNetworkInfoTextView.setTextColor(getColor(R.color.red_text))
+ }
}
// Set the data network click listener.
// Start the realtime monitoring service if it is enabled.
if (realtimeMonitoring) {
// Get a handle for the activity manager.
- val activityManager: ActivityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
+ val activityManager: ActivityManager = getSystemService(ACTIVITY_SERVICE) as ActivityManager
// Get a list of the running service info. The deprecated `getRunningServices()` now only returns services stared by Privacy Cell, but that is all we want to know anyway.
val runningServiceInfoList: List<ActivityManager.RunningServiceInfo> = activityManager.getRunningServices(1)
super.onStop()
// Get a handle for the telephony manager.
- val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
+ val telephonyManager = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
// Unregister the telephony manager listener. The `PhoneStateListener` can be replaced by `TelephonyCallback` once the minimum API >= 31.
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE)
private fun registerTelephonyManagerListener() {
// Get a handle for the telephony manager.
- val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
+ val telephonyManager = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
// 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_SERVICE_STATE or PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED)
/* SPDX-License-Identifier: GPL-3.0-or-later
- * SPDX-FileCopyrightText: 2022-2023 Soren Stoutner <soren@stoutner.com>
+ * SPDX-FileCopyrightText: 2022-2023, 2025 Soren Stoutner <soren@stoutner.com>
*
* This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell/>.
*
}
}
- fun checkAdditionalNetworkInfo(additionalNetworkInfoType: Int): Int {
- return if ((additionalNetworkInfoType == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE) ||
- (additionalNetworkInfoType == TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED)) {
- // The additional network info is secure.
- SECURE
- } else {
- // The additional network info is insecure.
- // TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_CA
- // TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO
- // TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA
- // TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE -- Can be removed once the minimum API >= 31.
- INSECURE
- }
- }
-
fun getNetworkTypeStringArray(networkType: Int, context: Context) : Array<String> {
// Return the string array that corresponds to the network type. The deprecated `NETWORK_TYPE_IDEN` can be removed once the minimum API >= 34.
@Suppress("DEPRECATION")