show warning if background notifications will be unreliable

This commit is contained in:
adbenitez 2025-09-01 15:52:10 +02:00
parent fcc1ab1079
commit 2deb61477f
3 changed files with 18 additions and 3 deletions

View file

@ -28,6 +28,7 @@ import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.connect.KeepAliveService; import org.thoughtcrime.securesms.connect.KeepAliveService;
import org.thoughtcrime.securesms.notifications.FcmReceiveService;
import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.Prefs;
public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragment implements Preference.OnPreferenceChangeListener { public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragment implements Preference.OnPreferenceChangeListener {
@ -99,6 +100,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
notificationsEnabled.setOnPreferenceChangeListener((preference, newValue) -> { notificationsEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
boolean enabled = (Boolean) newValue; boolean enabled = (Boolean) newValue;
dcContext.setMuted(!enabled); dcContext.setMuted(!enabled);
notificationsEnabled.setSummary(getSummary(getContext(), ""));
return true; return true;
}); });
} }
@ -126,6 +128,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
// update ignoreBattery in onResume() to reflects changes done in the system settings // update ignoreBattery in onResume() to reflects changes done in the system settings
ignoreBattery.setChecked(isIgnoringBatteryOptimizations()); ignoreBattery.setChecked(isIgnoringBatteryOptimizations());
notificationsEnabled.setChecked(!dcContext.isMuted()); notificationsEnabled.setChecked(!dcContext.isMuted());
notificationsEnabled.setSummary(getSummary(getContext(), ""));
mentionNotifEnabled.setChecked(dcContext.isMentionsEnabled()); mentionNotifEnabled.setChecked(dcContext.isMentionsEnabled());
// set without altering "unset" state of the preference // set without altering "unset" state of the preference
@ -160,6 +163,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
} else { } else {
context.stopService(new Intent(context, KeepAliveService.class)); context.stopService(new Intent(context, KeepAliveService.class));
} }
notificationsEnabled.setSummary(getSummary(context, ""));
return true; return true;
} }
@ -239,11 +243,21 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
} }
public static CharSequence getSummary(Context context) { public static CharSequence getSummary(Context context) {
return getSummary(context, context.getString(R.string.on));
}
public static CharSequence getSummary(Context context, String defaultOnValue) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || notificationManager.areNotificationsEnabled()) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || notificationManager.areNotificationsEnabled()) {
return context.getString(DcHelper.getContext(context).isMuted() ? R.string.off : R.string.on); if (DcHelper.getContext(context).isMuted()) {
return "⚠️ " + context.getString(R.string.notifications_disabled);
}
if (FcmReceiveService.getToken() == null && !Prefs.reliableService(context)) {
return "⚠️ " + context.getString(R.string.unreliable_bg_notifications);
}
return defaultOnValue;
} else { } else {
return context.getString(R.string.disabled_in_system_settings); return "⚠️ " + context.getString(R.string.disabled_in_system_settings);
} }
} }
} }

View file

@ -228,7 +228,7 @@ public class Prefs {
} }
// if the key was unset, then calculate default value // if the key was unset, then calculate default value
return isPushEnabled(context) || !DcHelper.getAccounts(context).isAllChatmail(); return !isPushEnabled(context) || !DcHelper.getAccounts(context).isAllChatmail();
} }
// vibrate // vibrate

View file

@ -1035,6 +1035,7 @@
<string name="notify_name_only">Name only</string> <string name="notify_name_only">Name only</string>
<string name="notify_no_name_or_message">No name or message</string> <string name="notify_no_name_or_message">No name or message</string>
<string name="notifications_disabled">Notifications disabled</string> <string name="notifications_disabled">Notifications disabled</string>
<string name="unreliable_bg_notifications">Push-notifications unavailable, please enable Force Background Connection for reliable notifications</string>
<string name="new_messages">New messages</string> <string name="new_messages">New messages</string>
<!-- Body text for a generic "New messages" notification. Shown if we do not have more information about a new messages. Note, that the string is also referenced at https://github.com/deltachat/notifiers --> <!-- Body text for a generic "New messages" notification. Shown if we do not have more information about a new messages. Note, that the string is also referenced at https://github.com/deltachat/notifiers -->
<string name="new_messages_body">You have new messages</string> <string name="new_messages_body">You have new messages</string>