分类: 嵌入式
2010-12-20 17:18:55
native public static boolean setCurrentTimeMillis(long millis);
其JNI实现在文件frameworks/base/core/jni/android_os_SystemClock.cpp中:
static jboolean android_os_SystemClock_setCurrentTimeMillis(JNIEnv* env,
jobject clazz, jlong millis)
{
return (setCurrentTimeMillis(millis) == 0);
}
转向如下文件
文件:frameworks/base/libs/utils/SystemClock.cpp
int setCurrentTimeMillis(int64_t millis)
{
...
#if HAVE_ANDROID_OS
fd = open("/dev/alarm", O_RDWR);
if(fd < 0) {
LOGW("Unable to open alarm driver: %s\n", strerror(errno));
return -1;
}
ts.tv_sec = tv.tv_sec;
ts.tv_nsec = tv.tv_usec * 1000;
res = ioctl(fd, ANDROID_ALARM_SET_RTC, &ts);
if(res < 0) {
LOGW("Unable to set rtc to %ld: %s\n", tv.tv_sec, strerror(errno));
ret = -1;
}
close(fd);
#else
...
}
也就是对设备/dev/alarm进行操作