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

Commit 6c9a758e authored by Keith Mok's avatar Keith Mok Committed by Gerrit Code Review
Browse files

Revert "Alarm: Don't use invalid timerfd alarm types"

We have too many BOARD_HAVE_ flags, and this can
be completely done dynamically by changing two lines of codes.

This reverts commit fa8fc291.

SAMBAR-1287

Change-Id: I5d23ce93fa9d2b5110803bf44168f1a56bfc2cdd
(cherry picked from commit 69f8fca4)
parent 724576a4
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -79,6 +79,3 @@ $(shell mkdir -p $(OUT)/obj/SHARED_LIBRARIES/libtime_genoff_intermediates/)
$(shell touch $(OUT)/obj/SHARED_LIBRARIES/libtime_genoff_intermediates/export_includes)
endif
ifeq ($(BOARD_HAVE_TIMERFD_POWEROFF_ALARM),true)
LOCAL_CFLAGS += -DWITH_TIMERFD_POWEROFF_ALARM
endif
+6 −8
Original line number Diff line number Diff line
@@ -48,18 +48,16 @@ extern "C" {

namespace android {

static const clockid_t android_alarm_to_clockid[] = {
static const size_t N_ANDROID_TIMERFDS = ANDROID_ALARM_TYPE_COUNT + 1;
static const clockid_t android_alarm_to_clockid[N_ANDROID_TIMERFDS] = {
    CLOCK_REALTIME_ALARM,
    CLOCK_REALTIME,
    CLOCK_BOOTTIME_ALARM,
    CLOCK_BOOTTIME,
    CLOCK_MONOTONIC,
#ifdef WITH_TIMERFD_POWEROFF_ALARM
    CLOCK_POWEROFF_ALARM,
#endif
    CLOCK_REALTIME,
};
static const size_t N_ANDROID_TIMERFDS = sizeof(android_alarm_to_clockid)/sizeof(clockid_t);
/* to match the legacy alarm driver implementation, we need an extra
   CLOCK_REALTIME fd which exists specifically to be canceled on RTC changes */

@@ -182,7 +180,7 @@ AlarmImplTimerFd::~AlarmImplTimerFd()

int AlarmImplTimerFd::set(int type, struct timespec *ts)
{
    if (type >= static_cast<int>(N_ANDROID_TIMERFDS)) {
    if (type > ANDROID_ALARM_TYPE_COUNT) {
        errno = EINVAL;
        return -1;
    }
@@ -202,7 +200,7 @@ int AlarmImplTimerFd::set(int type, struct timespec *ts)

int AlarmImplTimerFd::clear(int type, struct timespec *ts)
{
    if (type >= static_cast<int>(N_ANDROID_TIMERFDS)) {
    if (type > ANDROID_ALARM_TYPE_COUNT) {
        errno = EINVAL;
        return -1;
    }
@@ -283,7 +281,7 @@ int AlarmImplTimerFd::waitForAlarm()
        uint64_t unused;
        ssize_t err = read(fds[alarm_idx], &unused, sizeof(unused));
        if (err < 0) {
            if (alarm_idx == (N_ANDROID_TIMERFDS - 1) && errno == ECANCELED) {
            if (alarm_idx == ANDROID_ALARM_TYPE_COUNT && errno == ECANCELED) {
                result |= ANDROID_ALARM_TIME_CHANGE_MASK;
            } else {
                return err;
@@ -459,7 +457,7 @@ static jlong init_timerfd()
    /* 0 = disarmed; the timerfd doesn't need to be armed to get
       RTC change notifications, just set up as cancelable */

    int err = timerfd_settime(fds[N_ANDROID_TIMERFDS - 1],
    int err = timerfd_settime(fds[ANDROID_ALARM_TYPE_COUNT],
            TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &spec, NULL);
    if (err < 0) {
        ALOGV("timerfd_settime() failed: %s", strerror(errno));