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

Commit cffe7c04 authored by Mao Jinlong's avatar Mao Jinlong Committed by Gerrit - the friendly Code Review server
Browse files

Start alarm when boot is complete

There are some resources for power off alarm that will be ready only after
system is boot completed. So start alarm when boot is complete.

CRs-Fixed: 1063853

Change-Id: I18325e04432c0172dee4541b073067bc75d744a2
parent 3d114b3f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -125,8 +125,8 @@ public class AlarmInitReceiver extends BroadcastReceiver {
        //     1. Normal mode: just get next firing alarm and pass it to alarm activity
        //     2. Encryption mode: We need to create an alarm as there is no firing alarm
        //        in this mode.
        if (ACTION_POWER_OFF_ALARM.equals(action)) {
            AlarmInstance instance = AlarmStateManager.getNextFiringAlarm(context);
        if (Intent.ACTION_BOOT_COMPLETED.equals(action) && isAlarmBoot) {
            AlarmInstance instance = AlarmInstance.getFirstAlarmInstance(cr);
            String cryptState = SystemProperties.get(DECRYPT_PROP);
            if (instance == null && (ENCRYPTING_STATE.equals(cryptState) ||
                    ENCRYPTED_STATE.equals(cryptState))) {
+28 −0
Original line number Diff line number Diff line
@@ -284,6 +284,34 @@ public final class AlarmInstance implements ClockContract.InstancesColumns {
        }
    }

    /**
     * Get first alarm instance of power off alarm which is the closest missed alarm.
     *
     * @param contentResolver to access the content provider
     */
    public static AlarmInstance getFirstAlarmInstance(ContentResolver contentResolver) {
        List<AlarmInstance> alertAlarms = getInstances(contentResolver, null);
        long currentTime = System.currentTimeMillis();

        AlarmInstance firstAlarm = null;
        long closestMissAlarmElapse = 0;

        for (AlarmInstance ai : alertAlarms) {
            long time = currentTime - ai.getAlarmTime().getTimeInMillis();

            if (time < 0) {
                continue;
            }

            if (firstAlarm == null || closestMissAlarmElapse > time) {
                firstAlarm = ai;
                closestMissAlarmElapse = time;
            }
        }

        return firstAlarm;
    }

    // Public fields
    public long mId;
    public int mYear;