#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
if (settimeofday(&tv, NULL) != 0) {
LOGW("Unable to set clock to %d.%d: %s\n",
(int) tv.tv_sec, (int) tv.tv_usec, strerror(errno));
ret = -1;
}
#endif
可以看到 Android 設定系統時間,用 ioctl,不能直接 call settimeofday.settimeofday ,系統時間會改,但是 RTC 不會改, 所以 system reboot 後,時間還是沒變更。
手動設會有
D/SystemClock( 2399): Setting time of day to sec=31622433
D/ ( 2269): enter Cmd: L
D/dalvikvm( 2269): GC_CONCURRENT freed 1061K, 45% free 2224K/3971K, external 3688K/4325K, paused 3ms+3ms
D/AlarmManagerService( 2269): Kernel timezone updated to -540 minutes west of GMT
沒有留言:
張貼留言