Merge "toolbox: uptime: use clock_gettime() on devices without /dev/alarm"
This commit is contained in:
commit
215f78ae55
1 changed files with 14 additions and 4 deletions
|
|
@ -54,17 +54,27 @@ static void format_time(int time, char* buffer) {
|
||||||
sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
|
sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t elapsedRealtime()
|
static int elapsedRealtimeAlarm(struct timespec *ts)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
|
||||||
int fd, result;
|
int fd, result;
|
||||||
|
|
||||||
fd = open("/dev/alarm", O_RDONLY);
|
fd = open("/dev/alarm", O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
result = ioctl(fd, ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts);
|
result = ioctl(fd, ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), ts);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t elapsedRealtime()
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
int result = elapsedRealtimeAlarm(&ts);
|
||||||
|
if (result < 0)
|
||||||
|
result = clock_gettime(CLOCK_BOOTTIME, &ts);
|
||||||
|
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
return ts.tv_sec;
|
return ts.tv_sec;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue