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

Commit b26ef356 authored by Matthew Qin's avatar Matthew Qin Committed by Linux Build Service Account
Browse files

Alarm: Use dedicated alarm type for poweroff alarm.

RTC_POWEROFF_WAKEUP is a new alarm type introduced by framework
to perform poweroff alarm. The time (RTC_WAKEUP) set to framework
is not the same as the alarm time set in deskclock.  In this case
the RTC register might not be correctly set. So both RTC_WAKEUP
and RTC_POWEROFF_WAKEUP types need to be set at the same time:
RTC_WAKEUP type will handle the normal alarm process, and
RTC_POWEROFF_WAKEUP is used to set the correct alarm time to RTC
register.

Change-Id: Ic03f87018e163adf6f6e6013963a497d340fbec7
parent d32875c2
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -226,10 +226,19 @@ public final class AlarmStateManager extends BroadcastReceiver {
                stateChangeIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent stateChangePowerOffIntent = createStateChangeIntent(context, ALARM_MANAGER_TAG,
                instance, AlarmInstance.POWER_OFF_ALARM_STATE);
        PendingIntent pendingPowerOffIntent = PendingIntent.getBroadcast(context,
                instance.hashCode(), stateChangePowerOffIntent, PendingIntent.FLAG_ONE_SHOT);
        if (Utils.isKitKatOrLater()) {
            am.setExact(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);

            am.setExact(AlarmManager.RTC_POWEROFF_WAKEUP, instance.getAlarmTime().getTimeInMillis(),
                    pendingPowerOffIntent);
        } else {
            am.set(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
            am.set(AlarmManager.RTC_POWEROFF_WAKEUP, instance.getAlarmTime().getTimeInMillis(),
                    pendingPowerOffIntent);
        }
    }

@@ -247,7 +256,14 @@ public final class AlarmStateManager extends BroadcastReceiver {
                createStateChangeIntent(context, ALARM_MANAGER_TAG, instance, null),
                PendingIntent.FLAG_UPDATE_CURRENT);

        PendingIntent pendingPowerOffIntent = PendingIntent.getBroadcast(context,
                instance.hashCode(),
                createStateChangeIntent(context, ALARM_MANAGER_TAG, instance, null),
                PendingIntent.FLAG_ONE_SHOT);

        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

        am.cancel(pendingPowerOffIntent);
        am.cancel(pendingIntent);
    }

@@ -715,6 +731,13 @@ public final class AlarmStateManager extends BroadcastReceiver {
            if (alarmState >= 0) {
                setAlarmState(context, instance, alarmState);
            } else {
                // No need to register instance again when alarmState
                // equals POWER_OFF_ALARM_STATE. POWER_OFF_ALARM_STATE
                // is an invalid state for rtc power off alarm.
                if (alarmState == AlarmInstance.POWER_OFF_ALARM_STATE)
                {
                    return;
                }
                registerInstance(context, instance, true);
            }
        } else if (SHOW_AND_DISMISS_ALARM_ACTION.equals(action)) {
+6 −0
Original line number Diff line number Diff line
@@ -136,6 +136,12 @@ public final class ClockContract {
         */
        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/instances");


        /**
         * Alarm state for rtc power off alarm
         */
        public static final int POWER_OFF_ALARM_STATE = -1;

        /**
         * Alarm state when to show no notification.
         *