/* * Copyright © 2021 Soren Stoutner . * * This file is part of Privacy Cell . * * Privacy Cell is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Privacy Cell is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Privacy Browser. If not, see . */ package com.stoutner.privacycell.activities import android.Manifest import android.content.Context import android.content.pm.PackageManager import android.os.Bundle import android.telephony.PhoneStateListener import android.telephony.TelephonyDisplayInfo import android.telephony.TelephonyManager import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import com.stoutner.privacycell.R class PrivacyCell : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { // Run the default commands. super.onCreate(savedInstanceState) // Set the content view. setContentView(R.layout.privacy_cell_linearlayout) // Get handles for the views. val voiceNetworkTextView = findViewById(R.id.voice_network) val dataNetworkTextView = findViewById(R.id.data_network) val additionalNetworkInfoTextView = findViewById(R.id.additional_network_info) val secureFromStingrayTextView = findViewById(R.id.secure_from_stingray) // TODO. if (ActivityCompat.checkSelfPermission( this, Manifest.permission.READ_PHONE_STATE ) != PackageManager.PERMISSION_GRANTED ) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return } // Get a handle for the the telephone Manager. val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager // Get the voice network type. val voiceNetworkType = getNetworkType(telephonyManager.voiceNetworkType) // Populate the voice network text view. voiceNetworkTextView.text = getString(R.string.voice_network, voiceNetworkType) // Listen to changes in the cell network state. telephonyManager.listen(object : PhoneStateListener() { override fun onDisplayInfoChanged(telephonyDisplayInfo: TelephonyDisplayInfo) { // Get the strings that correspond to the network information. val dataNetworkType = getNetworkType(telephonyDisplayInfo.networkType) val additionalNetworkInfo = getAdditionalNetworkInfo(telephonyDisplayInfo.overrideNetworkType) // Populate the network text views. dataNetworkTextView.text = getString(R.string.data_network, dataNetworkType) additionalNetworkInfoTextView.text = getString(R.string.additional_network_info, additionalNetworkInfo) // Populate the secure from stingray text view. if (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_NR) { secureFromStingrayTextView.text = getString(R.string.secure_from_stingray) } else { secureFromStingrayTextView.text = getString(R.string.not_secure_from_stingray) } } }, PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED) } private fun getNetworkType(networkType: Int) : String { // Return the string that corresponds to the network type. return when(networkType) { TelephonyManager.NETWORK_TYPE_UNKNOWN -> getString(R.string.unknown) TelephonyManager.NETWORK_TYPE_GPRS -> getString(R.string.gprs) TelephonyManager.NETWORK_TYPE_EDGE -> getString(R.string.edge) TelephonyManager.NETWORK_TYPE_UMTS -> getString(R.string.umts) TelephonyManager.NETWORK_TYPE_CDMA -> getString(R.string.cdma) TelephonyManager.NETWORK_TYPE_EVDO_0 -> getString(R.string.evdo_0) TelephonyManager.NETWORK_TYPE_EVDO_A -> getString(R.string.evdo_a) TelephonyManager.NETWORK_TYPE_1xRTT -> getString(R.string.rtt) TelephonyManager.NETWORK_TYPE_HSDPA -> getString(R.string.hsdpa) TelephonyManager.NETWORK_TYPE_HSUPA -> getString(R.string.hsupa) TelephonyManager.NETWORK_TYPE_HSPA -> getString(R.string.hspa) TelephonyManager.NETWORK_TYPE_IDEN -> getString(R.string.iden) TelephonyManager.NETWORK_TYPE_EVDO_B -> getString(R.string.evdo_b) TelephonyManager.NETWORK_TYPE_LTE -> getString(R.string.lte) TelephonyManager.NETWORK_TYPE_EHRPD -> getString(R.string.ehrpd) TelephonyManager.NETWORK_TYPE_HSPAP -> getString(R.string.hspap) TelephonyManager.NETWORK_TYPE_GSM -> getString(R.string.gsm) TelephonyManager.NETWORK_TYPE_TD_SCDMA -> getString(R.string.td_scdma) TelephonyManager.NETWORK_TYPE_IWLAN -> getString(R.string.iwlan) TelephonyManager.NETWORK_TYPE_NR -> getString(R.string.nr) else -> getString(R.string.error) } } private fun getAdditionalNetworkInfo(overrideNetworkType: Int) : String { // Return the string that corresponds to the override network type. return when(overrideNetworkType) { TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE -> getString(R.string.none) TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_CA -> getString(R.string.lte_ca) TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO -> getString(R.string.lte_advanced_pro) TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA -> getString(R.string.lte_nr_nsa) TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE -> getString(R.string.lte_nr_nsa_mmwave) else -> getString(R.string.error) } } }