- val secureFromStingrayImageView = findViewById<ImageView>(R.id.secure_from_stingray_imageview)
- val secureFromStingrayTextView = findViewById<TextView>(R.id.secure_from_stingray_textview)
- val voiceNetworkTextView = findViewById<TextView>(R.id.voice_network)
- val voiceNetworkDetailsTextView = findViewById<TextView>(R.id.voice_network_details)
- val dataNetworkTextView = findViewById<TextView>(R.id.data_network)
- val dataNetworkDetailsTextView = findViewById<TextView>(R.id.data_network_details)
- val additionalNetworkInfoTextView = findViewById<TextView>(R.id.additional_network_info)
- val additionalNetworkInfoDetailsTextView = findViewById<TextView>(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
+ secureFromStingrayImageView = findViewById(R.id.secure_from_stingray_imageview)
+ secureFromStingrayTextView = findViewById(R.id.secure_from_stingray_textview)
+ voiceNetworkTextView = findViewById(R.id.voice_network)
+ voiceNetworkDetailsTextView = findViewById(R.id.voice_network_details)
+ dataNetworkTextView = findViewById(R.id.data_network)
+ dataNetworkDetailsTextView = findViewById(R.id.data_network_details)
+ additionalNetworkInfoTextView = findViewById(R.id.additional_network_info)
+ additionalNetworkInfoDetailsTextView = findViewById(R.id.additional_network_info_details)
+
+ // Get handles for the context and the telephony manager.
+ context = this
+ telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
+
+ // Check to see if the read phone state permission has been granted.
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { // The storage permission has been granted.
+ // Populate Privacy Cell.
+ populatePrivacyCell()
+ } else { // The phone permission has not been granted.
+ // Check if the user has previously denied the storage permission.
+ if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_PHONE_STATE)) { // Show a dialog explaining the request first.
+ // Check to see if a phone permission dialog is already displayed. This happens if the app is restarted when the dialog is shown.
+ if (supportFragmentManager.findFragmentByTag(getString(R.string.phone_permission)) == null) { // No dialog is currently shown.
+ // Instantiate the phone permission dialog fragment.
+ val phonePermissionDialogFragment: DialogFragment = PhonePermissionDialog()
+
+ // Show the phone permission alert dialog. The permission will be requested when the dialog is closed.
+ phonePermissionDialogFragment.show(supportFragmentManager, getString(R.string.phone_permission))
+ }
+ } else { // Show the permission request directly.
+ // Request the read phone state permission. There is only one permission request in the app, so it has a request code of 0.
+ ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_PHONE_STATE), 0)
+ }