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

Commit c9189ee8 authored by Isaac Katzenelson's avatar Isaac Katzenelson Committed by Isaac Katzenelson
Browse files

Fix quarter hour calculation

Bug: 11410710
Change-Id: I0aa6b60352febcd48d4a850778d48ddd7d0edded
(cherry picked from commit 851c662d)
parent 9fb37858
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -352,12 +352,18 @@ public class Utils {
        Calendar nextQuarter = Calendar.getInstance();
        //  Set 1 second to ensure quarter-hour threshold passed.
        nextQuarter.set(Calendar.SECOND, 1);
        nextQuarter.set(Calendar.MILLISECOND, 0);
        int minute = nextQuarter.get(Calendar.MINUTE);
        nextQuarter.add(Calendar.MINUTE, 15 - (minute % 15));
        long alarmOnQuarterHour = nextQuarter.getTimeInMillis();
        if (0 >= (alarmOnQuarterHour - System.currentTimeMillis())
                || (alarmOnQuarterHour - System.currentTimeMillis()) > 901000) {
            Log.wtf("quarterly alarm calculation error");
        long now = System.currentTimeMillis();
        long delta = alarmOnQuarterHour - now;
        if (0 >= delta || delta > 901000) {
            Log.wtf("quarterly alarm calculation error: nextq hour = " + alarmOnQuarterHour
                    + " now = " + now + " delta = " + delta);
            // Something went wrong in the calculation, schedule something that is
            // about 15 minutes. Next time , it will align with the 15 minutes border.
            alarmOnQuarterHour = now + 901000;
        }
        return alarmOnQuarterHour;
    }