+ // 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 enabled icon.
+ realtimeMonitoringPreference.setIcon(R.drawable.realtime_monitoring_enabled)
+ } else {
+ // Set the disabled icon.
+ realtimeMonitoringPreference.setIcon(R.drawable.realtime_monitoring_disabled)
+ }
+ } else {
+ // Set the ghosted icon.
+ realtimeMonitoringPreference.setIcon(R.drawable.realtime_monitoring_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)
+
+ // 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)
+
+ // Set the notification preference intents.
+ secureNetworkNotificationPreference.intent = secureNetworkNotificationIntent
+ insecureNetworkNotificationPreference.intent = insecureNetworkNotificationIntent
+