diff options
author | Ethan Chen <intervigil@gmail.com> | 2015-12-07 16:05:57 -0800 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2015-12-08 11:47:41 -0800 |
commit | fa8fc29194db4642342c39d8f928afc27cdf4d7d (patch) | |
tree | c42d895c2728fddf35ee1db8e6892e9b16fc7e44 | |
parent | d2bec52c76a3bb2c9a7fa3533e40f782fa592826 (diff) | |
download | frameworks_base-fa8fc29194db4642342c39d8f928afc27cdf4d7d.zip frameworks_base-fa8fc29194db4642342c39d8f928afc27cdf4d7d.tar.gz frameworks_base-fa8fc29194db4642342c39d8f928afc27cdf4d7d.tar.bz2 |
Alarm: Don't use invalid timerfd alarm types
* The additional CLOCK_POWEROFF_ALARM entry is invalid for timerfd, and
causes _ALL_ timerfd creation to fail, resulting in mostly
nonfunctional alarms systemwide.
Change-Id: I5366ed8296635ab51599bce1b988d54060da22ac
-rw-r--r-- | services/core/jni/Android.mk | 3 | ||||
-rw-r--r-- | services/core/jni/com_android_server_AlarmManagerService.cpp | 14 |
2 files changed, 11 insertions, 6 deletions
diff --git a/services/core/jni/Android.mk b/services/core/jni/Android.mk index 69488b1..0496592 100644 --- a/services/core/jni/Android.mk +++ b/services/core/jni/Android.mk @@ -79,3 +79,6 @@ $(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 diff --git a/services/core/jni/com_android_server_AlarmManagerService.cpp b/services/core/jni/com_android_server_AlarmManagerService.cpp index 5d1e7af..80b8923 100644 --- a/services/core/jni/com_android_server_AlarmManagerService.cpp +++ b/services/core/jni/com_android_server_AlarmManagerService.cpp @@ -48,16 +48,18 @@ extern "C" { namespace android { -static const size_t N_ANDROID_TIMERFDS = ANDROID_ALARM_TYPE_COUNT + 1; -static const clockid_t android_alarm_to_clockid[N_ANDROID_TIMERFDS] = { +static const clockid_t android_alarm_to_clockid[] = { 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 */ @@ -180,7 +182,7 @@ AlarmImplTimerFd::~AlarmImplTimerFd() int AlarmImplTimerFd::set(int type, struct timespec *ts) { - if (type > ANDROID_ALARM_TYPE_COUNT) { + if (type >= static_cast<int>(N_ANDROID_TIMERFDS)) { errno = EINVAL; return -1; } @@ -200,7 +202,7 @@ int AlarmImplTimerFd::set(int type, struct timespec *ts) int AlarmImplTimerFd::clear(int type, struct timespec *ts) { - if (type > ANDROID_ALARM_TYPE_COUNT) { + if (type >= static_cast<int>(N_ANDROID_TIMERFDS)) { errno = EINVAL; return -1; } @@ -281,7 +283,7 @@ int AlarmImplTimerFd::waitForAlarm() uint64_t unused; ssize_t err = read(fds[alarm_idx], &unused, sizeof(unused)); if (err < 0) { - if (alarm_idx == ANDROID_ALARM_TYPE_COUNT && errno == ECANCELED) { + if (alarm_idx == (N_ANDROID_TIMERFDS - 1) && errno == ECANCELED) { result |= ANDROID_ALARM_TIME_CHANGE_MASK; } else { return err; @@ -453,7 +455,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[ANDROID_ALARM_TYPE_COUNT], + int err = timerfd_settime(fds[N_ANDROID_TIMERFDS - 1], TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &spec, NULL); if (err < 0) { ALOGV("timerfd_settime() failed: %s", strerror(errno)); |