am 0e23a3d4: am 215f78ae: Merge "toolbox: uptime: use clock_gettime() on devices without /dev/alarm"
* commit '0e23a3d4830e6a45bf9b4968da7553fab79205a8':
toolbox: uptime: use clock_gettime() on devices without /dev/alarm
diff --git a/toolbox/uptime.c b/toolbox/uptime.c
index 455e7be..3fb4606 100644
--- a/toolbox/uptime.c
+++ b/toolbox/uptime.c
@@ -54,17 +54,27 @@
sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
}
-int64_t elapsedRealtime()
+static int elapsedRealtimeAlarm(struct timespec *ts)
{
- struct timespec ts;
int fd, result;
fd = open("/dev/alarm", O_RDONLY);
if (fd < 0)
return fd;
- result = ioctl(fd, ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts);
- close(fd);
+ result = ioctl(fd, ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), ts);
+ 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)
return ts.tv_sec;