Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58688ec2 authored by Giorgos Logiotatidis's avatar Giorgos Logiotatidis Committed by Gitsaibot
Browse files

Fix duplicate contact birthday notifications

The calendar provider may re-insert SCHEDULED alert entries when
contact events are re-synced, causing notifications to fire again
with sound/vibrate. Before treating a SCHEDULED alert as new, check
SharedPrefs (BYPASS_DB) to see if it was already fired.
parent 61395265
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -535,12 +535,25 @@ public class AlertService {
                if (sendAlert) {
                    if (state == CalendarAlerts.STATE_SCHEDULED || newAlertOverride) {
                        newState = CalendarAlerts.STATE_FIRED;

                        // When using local storage to track alert state (BYPASS_DB),
                        // check if this alert was already fired previously.  The
                        // calendar provider may re-insert SCHEDULED alert entries
                        // when events are re-synced (e.g. contact birthday events
                        // during a contact sync), which would otherwise cause
                        // duplicate notifications with sound/vibrate.
                        boolean alreadyFired = AlertUtils.BYPASS_DB
                                && AlertUtils.hasAlertFiredInSharedPrefs(
                                        context, eventId, beginTime, alarmTime);

                        if (!alreadyFired) {
                            numFired++;
                            // If quiet hours are forcing the alarm to be silent,
                            // keep newAlert as false so it will not make noise.
                            if (!forceQuiet) {
                                newAlert = true;
                            }
                        }

                        // Record the received time in the CalendarAlerts table.
                        // This is useful for finding bugs that cause alarms to be