From bad17a63b18ff3c8b5ae24ab467f423bbfbddd98 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 29 Nov 2022 13:48:57 -0700 Subject: [PATCH] Disable swiping to dismiss realtime notifications. https://redmine.stoutner.com/issues/894 --- .../privacycell/activities/SettingsActivity.kt | 13 +++++++++++-- .../privacycell/fragments/SettingsFragment.kt | 17 +++++++++++++++++ .../services/RealtimeMonitoringService.kt | 12 ++++++++++++ app/src/main/res/values-de/strings.xml | 4 +++- app/src/main/res/values-es/strings.xml | 4 +++- app/src/main/res/values-fr/strings.xml | 4 +++- app/src/main/res/values-it/strings.xml | 4 +++- app/src/main/res/values-ru/strings.xml | 4 +++- app/src/main/res/values/strings.xml | 3 ++- app/src/main/res/xml/preferences.xml | 1 - 10 files changed, 57 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/stoutner/privacycell/activities/SettingsActivity.kt b/app/src/main/java/com/stoutner/privacycell/activities/SettingsActivity.kt index 098f45f..f1923b3 100644 --- a/app/src/main/java/com/stoutner/privacycell/activities/SettingsActivity.kt +++ b/app/src/main/java/com/stoutner/privacycell/activities/SettingsActivity.kt @@ -37,6 +37,9 @@ import com.stoutner.privacycell.fragments.SettingsFragment import com.stoutner.privacycell.services.RealtimeMonitoringService class SettingsActivity : AppCompatActivity(), NotificationPermissionDialogListener { + // Declare the class variables. + private lateinit var settingsFragment: SettingsFragment + override fun onCreate(savedInstanceState: Bundle?) { // Run the default commands. super.onCreate(savedInstanceState) @@ -66,8 +69,11 @@ class SettingsActivity : AppCompatActivity(), NotificationPermissionDialogListen // Display the home arrow on the action bar. actionBar.setDisplayHomeAsUpEnabled(true) - // Load the preferences fragment. - supportFragmentManager.beginTransaction().replace(R.id.preferences_framelayout, SettingsFragment()).commit() + // Instantiate the settings fragment. + settingsFragment = SettingsFragment() + + // Load the settings fragment. + supportFragmentManager.beginTransaction().replace(R.id.preferences_framelayout, settingsFragment).commitNow() } override fun onCloseNotificationPermissionDialog() { @@ -96,6 +102,9 @@ class SettingsActivity : AppCompatActivity(), NotificationPermissionDialogListen if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // The notification permission was granted. // Start the realtime monitoring service. startService(Intent(this, RealtimeMonitoringService::class.java)) + + // Update the realtime monitoring preference summary. + settingsFragment.updateRealtimeMonitoringSummary() } } } diff --git a/app/src/main/java/com/stoutner/privacycell/fragments/SettingsFragment.kt b/app/src/main/java/com/stoutner/privacycell/fragments/SettingsFragment.kt index b5acce9..9adae22 100644 --- a/app/src/main/java/com/stoutner/privacycell/fragments/SettingsFragment.kt +++ b/app/src/main/java/com/stoutner/privacycell/fragments/SettingsFragment.kt @@ -155,6 +155,9 @@ class SettingsFragment : PreferenceFragmentCompat() { // Re-register the shared preference listener. sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener) + + // Update the realtime monitoring preference summary. + updateRealtimeMonitoringSummary() } private fun getSharedPreferenceChangeListener(): OnSharedPreferenceChangeListener { @@ -260,4 +263,18 @@ class SettingsFragment : PreferenceFragmentCompat() { // Restart the activity after 400 milliseconds, so that the app has enough time to save the change to the preference. restartHandler.postDelayed(restartRunnable, 400) } + + fun updateRealtimeMonitoringSummary() { + // Update the summary according to the API. + if (Build.VERSION.SDK_INT >= 33) { // The API >= 33. + // Set the summary according to the notification permission status. + if (ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) + realtimeMonitoringPreference.summary = getString(R.string.realtime_monitoring_summary) + else + realtimeMonitoringPreference.summary = (getString(R.string.realtime_monitoring_summary) + " " + getString(R.string.notification_permission_denied)) + } else { // The API is < 33. + // Set the realtime monitoring summary. + realtimeMonitoringPreference.summary = getString(R.string.realtime_monitoring_summary) + } + } } diff --git a/app/src/main/java/com/stoutner/privacycell/services/RealtimeMonitoringService.kt b/app/src/main/java/com/stoutner/privacycell/services/RealtimeMonitoringService.kt index 11af7b7..19e1a3e 100644 --- a/app/src/main/java/com/stoutner/privacycell/services/RealtimeMonitoringService.kt +++ b/app/src/main/java/com/stoutner/privacycell/services/RealtimeMonitoringService.kt @@ -148,6 +148,9 @@ class RealtimeMonitoringService : Service() { // Set the color. notificationBuilder.setColor(getColor(R.color.red_notification_icon)) + // Prevent swiping to dismiss the notification. + notificationBuilder.setOngoing(true) + // Start the foreground notification. startForeground(NOTIFICATION_ID, notificationBuilder.build()) @@ -251,6 +254,9 @@ class RealtimeMonitoringService : Service() { // Set the color. antiquatedNetworkNotificationBuilder.setColor(getColor(R.color.red_notification_icon)) + // Prevent swiping to dismiss the notification. + antiquatedNetworkNotificationBuilder.setOngoing(true) + // Update the notification. notificationManager.notify(NOTIFICATION_ID, antiquatedNetworkNotificationBuilder.build()) @@ -275,6 +281,9 @@ class RealtimeMonitoringService : Service() { // Set the color. insecureNetworkNotificationBuilder.setColor(getColor(R.color.yellow_notification_icon)) + // Prevent swiping to dismiss the notification. + insecureNetworkNotificationBuilder.setOngoing(true) + // Update the notification. notificationManager.notify(NOTIFICATION_ID, insecureNetworkNotificationBuilder.build()) @@ -299,6 +308,9 @@ class RealtimeMonitoringService : Service() { // Set the color. secureNetworkNotificationBuilder.setColor(getColor(R.color.blue_icon)) + // Prevent swiping to dismiss the notification. + secureNetworkNotificationBuilder.setOngoing(true) + // Update the notification. notificationManager.notify(NOTIFICATION_ID, secureNetworkNotificationBuilder.build()) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 77a6ce5..ed21f7e 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -116,9 +116,11 @@ NR Advanced – 5G New Radio Advanced - + Telefon-Berechtigung Privacy Cell benötigt lesenden Zugriff auf den Status Ihres Telefons, um das Sicherheits-Niveau Ihrer Mobilfunk-Verbindung zu ermitteln. + Benachrichtigungs-Berechtigung + Privacy Cell benötigt die Benachrichtigungs-Berechtigung, um Benachrichtigungen des Echtzeit-Monitorings anzeigen zu können. OK diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 2f38a43..7ff040c 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -116,9 +116,11 @@ NR Avanzado – 5G Nueva Radio Avanzada - + Permiso telefónico Privacy Cell necesita el permiso del teléfono "Leer estado del teléfono" para determinar el nivel de seguridad de su conexión celular. + Permiso de notificación + Privacy Cell necesita el permiso Post Notification para mostrar las notificaciones de monitoreo en tiempo real. OK diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index c7b481f..c10878e 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -117,9 +117,11 @@ NR Advanced – 5G New Radio Advanced - + Autorisations Privacy Cell a besoin de l\'autorisation READ PHONE STATE pour déterminer le niveau de sécurité de votre connexion cellulaire. + Autorisation de notification + Privacy Cell a besoin de l\'autorisation Post Notification pour afficher les notifications de surveillance en temps réel. OK diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index b4e0347..cea32ce 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -116,9 +116,11 @@ NR Advanced – 5G New Radio Advanced - + Autorizzazioni sul dispositivo Privacy Cell ha bisogno dell\'autorizzazione di lettura dello stato del telefono per poter determinare il livello si sicurezza della connessione. + Autorizzazione per le notifiche + Privacy Cell ha bisogno dell\'autorizzazione "Post Notification" per mostrare le notifiche del monitoraggio in tempo reale. OK diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index b073e5e..97855a8 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -114,9 +114,11 @@ NR усовершенствованное – 5G Новое радио усовершенствованное - + Разрешение телефона Privacy Cell необходимо разрешение на чтение состояния телефона для определения степени безопасности вашего мобильного подключения. + Разрешение на уведомления + Privacy Cell требуется разрешение на отправку уведомлений для отображения уведомлений мониторинга в реальном времени. OK diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 22281a1..2b47728 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -118,7 +118,7 @@ NR Advanced – 5G New Radio Advanced - + Phone Permission Privacy Cell needs the Read Phone State permission to determine the safety level of your cell connection. Notification Permission @@ -134,6 +134,7 @@ Monitoring Realtime monitoring Place an icon in the status bar that monitors the cell network. + The Post Notification permission is currently denied, so no notifications will be displayed. Secure network notification Insecure network notification Antiquated network notification diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 95d0515..d49d9b6 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -28,7 +28,6 @@