Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa66f1e4 authored by Greg Hackmann's avatar Greg Hackmann
Browse files

toolbox: uptime: use clock_gettime() on devices without /dev/alarm



Change-Id: Id7287ca179cc0b8390c054803a25a961dd550a34
Signed-off-by: default avatarGreg Hackmann <ghackmann@google.com>
parent 7f625ed0
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -54,18 +54,28 @@ static void format_time(int time, char* buffer) {
        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);
    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;
    return -1;