- // Set the realtime monitoring preference icon.
- if (sharedPreferences.getBoolean(getString(R.string.realtime_monitoring_key), false)) {
- // Set the enabled icon.
- realtimeMonitoringPreference.setIcon(R.drawable.realtime_monitoring_enabled)
+ // Only enable the realtime monitoring preference if the READ_PHONE_STATE permission has been granted.
+ realtimeMonitoringPreference.isEnabled = (ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)
+
+ // Set the realtime monitoring icon according to the status.
+ if (realtimeMonitoringPreference.isEnabled) {
+ // Set the realtime monitoring preference icon.
+ if (sharedPreferences.getBoolean(getString(R.string.realtime_monitoring_key), false)) {
+ // Set the icons.
+ realtimeMonitoringPreference.setIcon(R.drawable.secure_notification_enabled)
+ secureNetworkNotificationPreference.setIcon(R.drawable.secure_notification_enabled)
+ insecureNetworkNotificationPreference.setIcon(R.drawable.insecure_notification_enabled)
+ antiquatedNetworkNotificationPreference.setIcon(R.drawable.antiquated_notification_enabled)
+ } else {
+ // Set the icons.
+ realtimeMonitoringPreference.setIcon(R.drawable.secure_notification_disabled)
+ secureNetworkNotificationPreference.setIcon(R.drawable.secure_notification_disabled)
+ insecureNetworkNotificationPreference.setIcon(R.drawable.insecure_notification_disabled)
+ antiquatedNetworkNotificationPreference.setIcon(R.drawable.antiquated_notification_disabled)
+ }