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

Commit 10ca9e19 authored by Matthew Qin's avatar Matthew Qin Committed by Steve Kondik
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 c3f61f11
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -223,10 +223,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, -1);
        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);
        }
    }

@@ -244,7 +253,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);
    }