diff --git a/app/src/main/java/io/heckel/ntfy/db/Repository.kt b/app/src/main/java/io/heckel/ntfy/db/Repository.kt index 423c716..71b0309 100644 --- a/app/src/main/java/io/heckel/ntfy/db/Repository.kt +++ b/app/src/main/java/io/heckel/ntfy/db/Repository.kt @@ -292,6 +292,16 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas .apply() } + fun getUnifiedPushEnabled(): Boolean { + return sharedPrefs.getBoolean(SHARED_PREFS_UNIFIEDPUSH_ENABLED, true) // Enabled by default + } + + fun setUnifiedPushEnabled(enabled: Boolean) { + sharedPrefs.edit() + .putBoolean(SHARED_PREFS_UNIFIEDPUSH_ENABLED, enabled) + .apply() + } + fun getInsistentMaxPriorityEnabled(): Boolean { return sharedPrefs.getBoolean(SHARED_PREFS_INSISTENT_MAX_PRIORITY_ENABLED, false) // Disabled by default } @@ -477,6 +487,7 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas const val SHARED_PREFS_CONNECTION_PROTOCOL = "ConnectionProtocol" const val SHARED_PREFS_DARK_MODE = "DarkMode" const val SHARED_PREFS_BROADCAST_ENABLED = "BroadcastEnabled" + const val SHARED_PREFS_UNIFIEDPUSH_ENABLED = "UnifiedPushEnabled" const val SHARED_PREFS_INSISTENT_MAX_PRIORITY_ENABLED = "InsistentMaxPriority" const val SHARED_PREFS_RECORD_LOGS_ENABLED = "RecordLogs" const val SHARED_PREFS_BATTERY_OPTIMIZATIONS_REMIND_TIME = "BatteryOptimizationsRemindTime" diff --git a/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt index a03942a..f4ef5d8 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/SettingsActivity.kt @@ -364,6 +364,26 @@ class SettingsActivity : AppCompatActivity(), PreferenceFragmentCompat.OnPrefere } } + // Enable UnifiedPush + val unifiedPushEnabledPrefId = context?.getString(R.string.settings_advanced_unifiedpush_key) ?: return + val unifiedPushEnabled: SwitchPreference? = findPreference(unifiedPushEnabledPrefId) + unifiedPushEnabled?.isChecked = repository.getUnifiedPushEnabled() + unifiedPushEnabled?.preferenceDataStore = object : PreferenceDataStore() { + override fun putBoolean(key: String?, value: Boolean) { + repository.setUnifiedPushEnabled(value) + } + override fun getBoolean(key: String?, defValue: Boolean): Boolean { + return repository.getUnifiedPushEnabled() + } + } + unifiedPushEnabled?.summaryProvider = Preference.SummaryProvider { pref -> + if (pref.isChecked) { + getString(R.string.settings_advanced_unifiedpush_summary_enabled) + } else { + getString(R.string.settings_advanced_unifiedpush_summary_disabled) + } + } + // Export logs val exportLogsPrefId = context?.getString(R.string.settings_advanced_export_logs_key) ?: return val exportLogs: ListPreference? = findPreference(exportLogsPrefId) diff --git a/app/src/main/java/io/heckel/ntfy/up/BroadcastReceiver.kt b/app/src/main/java/io/heckel/ntfy/up/BroadcastReceiver.kt index 20cf963..46a0bcb 100644 --- a/app/src/main/java/io/heckel/ntfy/up/BroadcastReceiver.kt +++ b/app/src/main/java/io/heckel/ntfy/up/BroadcastReceiver.kt @@ -38,6 +38,11 @@ class BroadcastReceiver : android.content.BroadcastReceiver() { val repository = app.repository val distributor = Distributor(app) Log.d(TAG, "REGISTER received for app $appId (connectorToken=$connectorToken)") + if (!repository.getUnifiedPushEnabled()) { + Log.w(TAG, "Refusing registration because 'EnableUP' is disabled") + distributor.sendRegistrationFailed(appId, connectorToken, "UnifiedPush is disabled in ntfy") + return + } if (appId.isBlank()) { Log.w(TAG, "Refusing registration: Empty application") distributor.sendRegistrationFailed(appId, connectorToken, "Empty application string") diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b7f57f3..c775990 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -320,6 +320,9 @@ Broadcast messages Apps can receive incoming notifications as broadcasts Apps cannot receive notifications as broadcasts + Enable UnifiedPush + ntfy will act as a UnifiedPush distributor + ntfy will not act as a UnifiedPush distributor Record logs Logging (up to 1,000 entries) to device … Turn on logging, so you can share logs later to diagnose issues. diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index ebab08b..f94a598 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -25,6 +25,7 @@ Backup Restore BroadcastEnabled + UnifiedPushEnabled RecordLogs ExportLogs ClearLogs diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index d7178a6..0be2442 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -76,6 +76,10 @@ app:key="@string/settings_advanced_broadcast_key" app:title="@string/settings_advanced_broadcast_title" app:enabled="true"/> +