Merge pull request #3908 from deltachat/adb/issue-3893

show warning if background notifications will be unreliable
This commit is contained in:
adb 2025-09-02 18:12:46 +02:00 committed by GitHub
commit 32eefaab42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 3 deletions

View file

@ -9,6 +9,7 @@
* fix: don't show error message when cancelling profile creation
* enable permanent notification by default if push notifications are not available
* hide "clone chat" and member list for incoming channels
* show warning if background notifications will be unreliable
## v2.11.0
2025-08

View file

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

View file

@ -1051,6 +1051,7 @@
<string name="notify_name_only">Name only</string>
<string name="notify_no_name_or_message">No name or message</string>
<string name="notifications_disabled">Notifications disabled</string>
<string name="unreliable_bg_notifications">Enable \"Force Background Connection\" for reliable notifications</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 -->
<string name="new_messages_body">You have new messages</string>