/* * 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.ImageView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.content.res.AppCompatResources 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 secureFromStingrayImageView = findViewById(R.id.secure_from_stingray_imageview) val secureFromStingrayTextView = findViewById(R.id.secure_from_stingray_textview) val voiceNetworkTextView = findViewById(R.id.voice_network) val voiceNetworkDetailsTextView = findViewById(R.id.voice_network_details) val dataNetworkTextView = findViewById(R.id.data_network) val dataNetworkDetailsTextView = findViewById(R.id.data_network_details) val additionalNetworkInfoTextView = findViewById(R.id.additional_network_info) val additionalNetworkInfoDetailsTextView = findViewById(R.id.additional_network_info_details) // 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 and the context. val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager val context: Context = this // Get the voice network type. val voiceNetworkType = getNetworkType(telephonyManager.voiceNetworkType) // Populate the voice network text views. voiceNetworkTextView.text = getString(R.string.voice_network, voiceNetworkType[0]) voiceNetworkDetailsTextView.text = voiceNetworkType[1] // Listen to changes in the cell network state. telephonyManager.listen(object : PhoneStateListener() { override fun onDisplayInfoChanged(telephonyDisplayInfo: TelephonyDisplayInfo) {// Populate the secure from stingray text view. // Populate the stingray security information. if (telephonyDisplayInfo.networkType == TelephonyManager.NETWORK_TYPE_NR) { // This is a secure 5G NR SA network. // Populate the image view. secureFromStingrayImageView.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.secure_5g_nr_sa)) // Set the text. secureFromStingrayTextView.text = getString(R.string.secure_from_stingray) // Set the text color. secureFromStingrayTextView.setTextColor(getColor(R.color.blue_700)) } else { // This is not a secure 5G NR SA network. // Populate the image view. secureFromStingrayImageView.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.not_secure)) // Set the text. secureFromStingrayTextView.text = getString(R.string.not_secure_from_stingray) // Set the text color. secureFromStingrayTextView.setTextColor(getColor(R.color.red_700)) // 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] } } }, PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED) } private fun getNetworkType(networkType: Int) : Array { // Return the string that corresponds to the network type. return when(networkType) { TelephonyManager.NETWORK_TYPE_UNKNOWN -> arrayOf(getString(R.string.unknown), getString(R.string.unknown)) TelephonyManager.NETWORK_TYPE_GPRS -> arrayOf(getString(R.string.gprs), getString(R.string.gprs_detal)) TelephonyManager.NETWORK_TYPE_EDGE -> arrayOf(getString(R.string.edge), getString(R.string.edge_detail)) TelephonyManager.NETWORK_TYPE_UMTS -> arrayOf(getString(R.string.umts), getString(R.string.umts_detail)) TelephonyManager.NETWORK_TYPE_CDMA -> arrayOf(getString(R.string.cdma), getString(R.string.cdma_detail)) TelephonyManager.NETWORK_TYPE_EVDO_0 -> arrayOf(getString(R.string.evdo_0), getString(R.string.evdo_0_detail)) TelephonyManager.NETWORK_TYPE_EVDO_A -> arrayOf(getString(R.string.evdo_a), getString(R.string.evdo_a_detail)) TelephonyManager.NETWORK_TYPE_1xRTT -> arrayOf(getString(R.string.rtt), getString(R.string.rtt_detail)) TelephonyManager.NETWORK_TYPE_HSDPA -> arrayOf(getString(R.string.hsdpa), getString(R.string.hsdpa_detail)) TelephonyManager.NETWORK_TYPE_HSUPA -> arrayOf(getString(R.string.hsupa), getString(R.string.hsupa_detail)) TelephonyManager.NETWORK_TYPE_HSPA -> arrayOf(getString(R.string.hspa), getString(R.string.hspa_detail)) TelephonyManager.NETWORK_TYPE_IDEN -> arrayOf(getString(R.string.iden), getString(R.string.iden_detail)) TelephonyManager.NETWORK_TYPE_EVDO_B -> arrayOf(getString(R.string.evdo_b), getString(R.string.evdo_b_detail)) TelephonyManager.NETWORK_TYPE_LTE -> arrayOf(getString(R.string.lte), getString(R.string.lte_detail)) TelephonyManager.NETWORK_TYPE_EHRPD -> arrayOf(getString(R.string.ehrpd), getString(R.string.ehrpd_detail)) TelephonyManager.NETWORK_TYPE_HSPAP -> arrayOf(getString(R.string.hspap), getString(R.string.hspap_detail)) TelephonyManager.NETWORK_TYPE_GSM -> arrayOf(getString(R.string.gsm), getString(R.string.gsm_detail)) TelephonyManager.NETWORK_TYPE_TD_SCDMA -> arrayOf(getString(R.string.td_scdma), getString(R.string.td_scdma_detail)) TelephonyManager.NETWORK_TYPE_IWLAN -> arrayOf(getString(R.string.iwlan), getString(R.string.iwlan_detail)) TelephonyManager.NETWORK_TYPE_NR -> arrayOf(getString(R.string.nr), getString(R.string.nr_detail)) else -> arrayOf(getString(R.string.error), getString(R.string.error)) } } private fun getAdditionalNetworkInfo(overrideNetworkType: Int) : Array { // Return the string that corresponds to the override network type. return when(overrideNetworkType) { TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE -> arrayOf(getString(R.string.none), "") 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.lte_nr_nsa), getString(R.string.lte_nr_nsa_detail)) TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE -> arrayOf(getString(R.string.lte_nr_nsa_mmwave), getString(R.string.lte_nr_nsa_mmwave_detail)) else -> arrayOf(getString(R.string.error), "") } } }