summaryrefslogtreecommitdiffstats
path: root/services/jni
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2010-03-31 15:29:40 -0700
committerJeff Brown <jeffbrown@google.com>2010-03-31 15:38:08 -0700
commit11c5f1a65d6c495cc60f9f15d408c776baed9f73 (patch)
tree1a82c873340eabb636e04091c0fd59be3b271984 /services/jni
parent966fcb81eece9096040ccc185bb662335d3964cf (diff)
downloadframeworks_base-11c5f1a65d6c495cc60f9f15d408c776baed9f73.zip
frameworks_base-11c5f1a65d6c495cc60f9f15d408c776baed9f73.tar.gz
frameworks_base-11c5f1a65d6c495cc60f9f15d408c776baed9f73.tar.bz2
Fix alarms with negative or very large wakup times.
When the wakeup time is negative, the kernel /dev/alarm driver never triggers the alarm. This can cause alarms to back up in the priority queue since an alarm at the head with a negative wakup time will never be triggered. Now we use 0 as the wakup time which causes an immediate triggering. When the wakeup time is very large, it is possible for a numeric overflow to occur when converting the timestamp from milliseconds since epoch to nanoseconds. This has been fixed by avoiding the intermediate conversion in the JNI call so that overflow cannot occur. Bug: b/2558820 Change-Id: I4f5b4646a04090cc749a9fc5d3982a68402954ef
Diffstat (limited to 'services/jni')
-rw-r--r--services/jni/com_android_server_AlarmManagerService.cpp14
1 files changed, 5 insertions, 9 deletions
diff --git a/services/jni/com_android_server_AlarmManagerService.cpp b/services/jni/com_android_server_AlarmManagerService.cpp
index 85d63c9..0e162bd 100644
--- a/services/jni/com_android_server_AlarmManagerService.cpp
+++ b/services/jni/com_android_server_AlarmManagerService.cpp
@@ -38,10 +38,6 @@
#include <linux/android_alarm.h>
#endif
-#define ONE_NANOSECOND 1000000000LL
-#define NANOSECONDS_TO_SECONDS(x) (x / ONE_NANOSECOND)
-#define SECONDS_TO_NANOSECONDS(x) (x * ONE_NANOSECOND)
-
namespace android {
static jint android_server_AlarmManagerService_setKernelTimezone(JNIEnv* env, jobject obj, jint fd, jint minswest)
@@ -82,17 +78,17 @@ static void android_server_AlarmManagerService_close(JNIEnv* env, jobject obj, j
#endif
}
-static void android_server_AlarmManagerService_set(JNIEnv* env, jobject obj, jint fd, jint type, jlong nanoseconds)
+static void android_server_AlarmManagerService_set(JNIEnv* env, jobject obj, jint fd, jint type, jlong seconds, jlong nanoseconds)
{
#if HAVE_ANDROID_OS
struct timespec ts;
- ts.tv_sec = NANOSECONDS_TO_SECONDS(nanoseconds);
- ts.tv_nsec = nanoseconds - SECONDS_TO_NANOSECONDS(ts.tv_sec);
+ ts.tv_sec = seconds;
+ ts.tv_nsec = nanoseconds;
int result = ioctl(fd, ANDROID_ALARM_SET(type), &ts);
if (result < 0)
{
- LOGE("Unable to set alarm to %lld: %s\n", nanoseconds, strerror(errno));
+ LOGE("Unable to set alarm to %lld.%09lld: %s\n", seconds, nanoseconds, strerror(errno));
}
#endif
}
@@ -121,7 +117,7 @@ static JNINativeMethod sMethods[] = {
/* name, signature, funcPtr */
{"init", "()I", (void*)android_server_AlarmManagerService_init},
{"close", "(I)V", (void*)android_server_AlarmManagerService_close},
- {"set", "(IIJ)V", (void*)android_server_AlarmManagerService_set},
+ {"set", "(IIJJ)V", (void*)android_server_AlarmManagerService_set},
{"waitForAlarm", "(I)I", (void*)android_server_AlarmManagerService_waitForAlarm},
{"setKernelTimezone", "(II)I", (void*)android_server_AlarmManagerService_setKernelTimezone},
};