import android.database.Cursor;
import android.os.Parcel;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
/**
* Glue class: connects AlarmAlert IntentReceiver to AlarmAlert
* activity. Passes through Alarm ID.
return;
}
+ // Intentionally verbose: always log the alarm time to provide useful
+ // information in bug reports.
long now = System.currentTimeMillis();
- /* FIXME Intentionally verbose: always log this until we've
- fully debugged the app failing to start up */
+ SimpleDateFormat format =
+ new SimpleDateFormat("HH:mm:ss.SSS aaa");
Log.v("AlarmReceiver.onReceive() id " + alarm.id + " setFor "
- + alarm.time + " now " + now);
+ + format.format(new Date(alarm.time)));
if (now > alarm.time + STALE_WINDOW * 1000) {
if (Log.LOGV) {
- Log.v("AlarmReceiver ignoring stale alarm intent id" + alarm.id
- + " setFor " + alarm.time + " now " + now);
+ Log.v("AlarmReceiver ignoring stale alarm");
}
return;
}
// Disable this alarm if it does not repeat.
if (!alarm.daysOfWeek.isRepeatSet()) {
Alarms.enableAlarm(context, alarm.id, false);
+ } else {
+ // Enable the next alert if there is one. The above call to
+ // enableAlarm will call setNextAlert so avoid calling it twice.
+ Alarms.setNextAlert(context);
}
- // Enable the next alert if there is one.
- Alarms.setNextAlert(context);
// Play the alarm alert and vibrate the device.
Intent playAlarm = new Intent(Alarms.ALARM_ALERT_ACTION);
public static Alarm calculateNextAlert(final Context context) {
Alarm alarm = null;
long minTime = Long.MAX_VALUE;
+ long now = System.currentTimeMillis();
Cursor cursor = getFilteredAlarmsCursor(context.getContentResolver());
if (cursor != null) {
if (cursor.moveToFirst()) {
if (a.time == 0) {
a.time = calculateAlarm(a.hour, a.minutes, a.daysOfWeek)
.getTimeInMillis();
+ } else if (a.time < now) {
+ // Expired alarm, disable it and move along.
+ enableAlarmInternal(context, a, false);
+ continue;
}
if (a.time < minTime) {
minTime = a.time;