Fix quarter hour calculation

Bug: 11410710
Change-Id: I0aa6b60352febcd48d4a850778d48ddd7d0edded
(cherry picked from commit 851c662d9f02e76c9fd23426c9e6713521e01aac)
diff --git a/src/com/android/deskclock/Utils.java b/src/com/android/deskclock/Utils.java
index 1aa1601..07219d2 100644
--- a/src/com/android/deskclock/Utils.java
+++ b/src/com/android/deskclock/Utils.java
@@ -352,12 +352,18 @@
         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;
     }