package com.stoutner.privacycell.fragments
+import android.Manifest
import android.content.Intent
import android.content.SharedPreferences
+import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.provider.Settings
+import androidx.core.app.ActivityCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.work.WorkManager
val insecureNetworkNotificationPreference = findPreference<Preference>(getString(R.string.insecure_network_notification_key))!!
bottomAppBarPreference = findPreference(getString(R.string.bottom_app_bar_key))!!
- // 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 enabled icon.
+ realtimeMonitoringPreference.setIcon(R.drawable.realtime_monitoring_enabled)
+ } else {
+ // Set the disabled icon.
+ realtimeMonitoringPreference.setIcon(R.drawable.realtime_monitoring_disabled)
+ }
} else {
- // Set the disabled icon.
- realtimeMonitoringPreference.setIcon(R.drawable.realtime_monitoring_disabled)
+ // Set the ghosted icon.
+ realtimeMonitoringPreference.setIcon(R.drawable.realtime_monitoring_ghosted)
}
// Set the notification preferences to depend on the realtime monitoring preference.