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

Commit aaeb8a22 authored by Patrick Scott's avatar Patrick Scott
Browse files

Add logs to track missed alarms.

Turn on a few verbose logs to track a couple of cases where an alarm might be
skipped or cancelled.  Add a Log.wtf when an alert cannot be parsed as this is
never supposed to happen.

If we are returning from the AlarmReceiver due to some error, make sure to set
the next alert.

Bug: 3004064
Change-Id: I6879317b233ccb0497a5ed7b8259925cd00cf8e8
parent 6c528aa0
Loading
Loading
Loading
Loading
+0 −2
Original line number Original line Diff line number Diff line
@@ -28,7 +28,6 @@ class AlarmAlertWakeLock {
    private static PowerManager.WakeLock sCpuWakeLock;
    private static PowerManager.WakeLock sCpuWakeLock;


    static void acquireCpuWakeLock(Context context) {
    static void acquireCpuWakeLock(Context context) {
        Log.v("Acquiring cpu wake lock");
        if (sCpuWakeLock != null) {
        if (sCpuWakeLock != null) {
            return;
            return;
        }
        }
@@ -44,7 +43,6 @@ class AlarmAlertWakeLock {
    }
    }


    static void releaseCpuLock() {
    static void releaseCpuLock() {
        Log.v("Releasing cpu wake lock");
        if (sCpuWakeLock != null) {
        if (sCpuWakeLock != null) {
            sCpuWakeLock.release();
            sCpuWakeLock.release();
            sCpuWakeLock = null;
            sCpuWakeLock = null;
+3 −5
Original line number Original line Diff line number Diff line
@@ -31,14 +31,12 @@ public class AlarmInitReceiver extends BroadcastReceiver {
        String action = intent.getAction();
        String action = intent.getAction();
        if (Log.LOGV) Log.v("AlarmInitReceiver" + action);
        if (Log.LOGV) Log.v("AlarmInitReceiver" + action);


        if (context.getContentResolver() == null) {
        // Remove the snooze alarm after a boot.
            Log.e("AlarmInitReceiver: FAILURE unable to get content resolver.  Alarms inactive.");
            return;
        }
        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
            Alarms.saveSnoozeAlert(context, -1, -1);
            Alarms.saveSnoozeAlert(context, -1, -1);
            Alarms.disableExpiredAlarms(context);
        }
        }

        Alarms.disableExpiredAlarms(context);
        Alarms.setNextAlert(context);
        Alarms.setNextAlert(context);
    }
    }
}
}
+23 −25
Original line number Original line Diff line number Diff line
@@ -27,18 +27,15 @@ import android.content.BroadcastReceiver;
import android.database.Cursor;
import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcel;


import java.text.SimpleDateFormat;
import java.util.Date;

/**
/**
 * Glue class: connects AlarmAlert IntentReceiver to AlarmAlert
 * Glue class: connects AlarmAlert IntentReceiver to AlarmAlert
 * activity.  Passes through Alarm ID.
 * activity.  Passes through Alarm ID.
 */
 */
public class AlarmReceiver extends BroadcastReceiver {
public class AlarmReceiver extends BroadcastReceiver {


    /** If the alarm is older than STALE_WINDOW seconds, ignore.  It
    /** If the alarm is older than STALE_WINDOW, ignore.  It
        is probably the result of a time or timezone change */
        is probably the result of a time or timezone change */
    private final static int STALE_WINDOW = 60 * 30;
    private final static int STALE_WINDOW = 30 * 60 * 1000;


    @Override
    @Override
    public void onReceive(Context context, Intent intent) {
    public void onReceive(Context context, Intent intent) {
@@ -51,6 +48,9 @@ public class AlarmReceiver extends BroadcastReceiver {
        } else if (Alarms.CANCEL_SNOOZE.equals(intent.getAction())) {
        } else if (Alarms.CANCEL_SNOOZE.equals(intent.getAction())) {
            Alarms.saveSnoozeAlert(context, -1, -1);
            Alarms.saveSnoozeAlert(context, -1, -1);
            return;
            return;
        } else if (!Alarms.ALARM_ALERT_ACTION.equals(intent.getAction())) {
            // Unknown intent, bail.
            return;
        }
        }


        Alarm alarm = null;
        Alarm alarm = null;
@@ -67,22 +67,31 @@ public class AlarmReceiver extends BroadcastReceiver {
        }
        }


        if (alarm == null) {
        if (alarm == null) {
            Log.v("AlarmReceiver failed to parse the alarm from the intent");
            Log.wtf("Failed to parse the alarm from the intent");
            // Make sure we set the next alert if needed.
            Alarms.setNextAlert(context);
            return;
            return;
        }
        }


        // Disable the snooze alert if this alarm is the snooze.
        Alarms.disableSnoozeAlert(context, alarm.id);
        // 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);
        }

        // Intentionally verbose: always log the alarm time to provide useful
        // Intentionally verbose: always log the alarm time to provide useful
        // information in bug reports.
        // information in bug reports.
        long now = System.currentTimeMillis();
        long now = System.currentTimeMillis();
        SimpleDateFormat format =
        Log.v("Recevied alarm set for " + Log.formatTime(alarm.time));
                new SimpleDateFormat("HH:mm:ss.SSS aaa");
        Log.v("AlarmReceiver.onReceive() id " + alarm.id + " setFor "
                + format.format(new Date(alarm.time)));


        if (now > alarm.time + STALE_WINDOW * 1000) {
        // Always verbose to track down time change problems.
            if (Log.LOGV) {
        if (now > alarm.time + STALE_WINDOW) {
                Log.v("AlarmReceiver ignoring stale alarm");
            Log.v("Ignoring stale alarm");
            }
            return;
            return;
        }
        }


@@ -103,17 +112,6 @@ public class AlarmReceiver extends BroadcastReceiver {
            c = AlarmAlertFullScreen.class;
            c = AlarmAlertFullScreen.class;
        }
        }


        // Disable the snooze alert if this alarm is the snooze.
        Alarms.disableSnoozeAlert(context, alarm.id);
        // 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);
        }

        // Play the alarm alert and vibrate the device.
        // Play the alarm alert and vibrate the device.
        Intent playAlarm = new Intent(Alarms.ALARM_ALERT_ACTION);
        Intent playAlarm = new Intent(Alarms.ALARM_ALERT_ACTION);
        playAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);
        playAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);
+4 −4
Original line number Original line Diff line number Diff line
@@ -293,6 +293,8 @@ public class Alarms {
                    if (a.time == 0) {
                    if (a.time == 0) {
                        a.time = calculateAlarm(a);
                        a.time = calculateAlarm(a);
                    } else if (a.time < now) {
                    } else if (a.time < now) {
                        Log.v("Disabling expired alarm set for " +
                              Log.formatTime(a.time));
                        // Expired alarm, disable it and move along.
                        // Expired alarm, disable it and move along.
                        enableAlarmInternal(context, a, false);
                        enableAlarmInternal(context, a, false);
                        continue;
                        continue;
@@ -322,10 +324,8 @@ public class Alarms {
                // A time of 0 means this alarm repeats. If the time is
                // A time of 0 means this alarm repeats. If the time is
                // non-zero, check if the time is before now.
                // non-zero, check if the time is before now.
                if (alarm.time != 0 && alarm.time < now) {
                if (alarm.time != 0 && alarm.time < now) {
                    if (Log.LOGV) {
                    Log.v("Disabling expired alarm set for " +
                        Log.v("** DISABLE " + alarm.id + " now " + now +" set "
                          Log.formatTime(alarm.time));
                                + alarm.time);
                    }
                    enableAlarmInternal(context, alarm, false);
                    enableAlarmInternal(context, alarm, false);
                }
                }
            } while (cur.moveToNext());
            } while (cur.moveToNext());
+11 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,9 @@ package com.android.deskclock;
import android.os.SystemClock;
import android.os.SystemClock;
import android.util.Config;
import android.util.Config;


import java.text.SimpleDateFormat;
import java.util.Date;

class Log {
class Log {
    public final static String LOGTAG = "AlarmClock";
    public final static String LOGTAG = "AlarmClock";


@@ -43,4 +46,12 @@ class Log {
    static void e(String logMe, Exception ex) {
    static void e(String logMe, Exception ex) {
        android.util.Log.e(LOGTAG, logMe, ex);
        android.util.Log.e(LOGTAG, logMe, ex);
    }
    }

    static void wtf(String logMe) {
        android.util.Log.wtf(LOGTAG, logMe);
    }

    static String formatTime(long millis) {
        return new SimpleDateFormat("HH:mm:ss.SSS aaa").format(new Date(millis));
    }
}
}