+ // 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)
+ }
+ } else {
+ // Set the icons.
+ realtimeMonitoringPreference.setIcon(R.drawable.secure_notification_ghosted)
+ secureNetworkNotificationPreference.setIcon(R.drawable.secure_notification_ghosted)
+ insecureNetworkNotificationPreference.setIcon(R.drawable.insecure_notification_ghosted)
+ antiquatedNetworkNotificationPreference.setIcon(R.drawable.antiquated_notification_ghosted)
+ }
+
+ // Set the notification preferences to depend on the realtime monitoring preference.
+ secureNetworkNotificationPreference.dependency = getString(R.string.realtime_monitoring_key)
+ insecureNetworkNotificationPreference.dependency = getString(R.string.realtime_monitoring_key)
+ antiquatedNetworkNotificationPreference.dependency = getString(R.string.realtime_monitoring_key)
+
+ // Create the notification intents.
+ val secureNetworkNotificationIntent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
+ .putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
+ .putExtra(Settings.EXTRA_CHANNEL_ID, RealtimeMonitoringService.SECURE_NETWORK)
+ val insecureNetworkNotificationIntent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
+ .putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
+ .putExtra(Settings.EXTRA_CHANNEL_ID, RealtimeMonitoringService.INSECURE_NETWORK)
+ val antiquatedNetworkNotificationIntent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
+ .putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
+ .putExtra(Settings.EXTRA_CHANNEL_ID, RealtimeMonitoringService.ANTIQUATED_NETWORK)
+
+ // Set the notification preference intents.
+ secureNetworkNotificationPreference.intent = secureNetworkNotificationIntent
+ insecureNetworkNotificationPreference.intent = insecureNetworkNotificationIntent
+ antiquatedNetworkNotificationPreference.intent = antiquatedNetworkNotificationIntent
+
+ // Set the consider 3G antiquated preference icon.
+ if (sharedPreferences.getBoolean(getString(R.string.consider_3g_antiquated_key), false)) {
+ consider3gAntiquatedPreference.setIcon(R.drawable.antiquated_3g_enabled)
+ } else {
+ consider3gAntiquatedPreference.setIcon(R.drawable.antiquated_3g_disabled)
+ }
+