diff options
| author | Greg Hackmann <ghackmann@google.com> | 2013-12-17 13:57:28 -0800 |
|---|---|---|
| committer | Greg Hackmann <ghackmann@google.com> | 2013-12-17 14:45:39 -0800 |
| commit | fa66f1e49458e7745511416d72ac15c190a13e6f (patch) | |
| tree | ae11a97062f7fbf89182fe107334372a412a3b10 /toolbox | |
| parent | 7f625ed026006fafeaec49e21e34ee18ac28dbc3 (diff) | |
| download | system_core-fa66f1e49458e7745511416d72ac15c190a13e6f.tar.gz system_core-fa66f1e49458e7745511416d72ac15c190a13e6f.tar.bz2 system_core-fa66f1e49458e7745511416d72ac15c190a13e6f.zip | |
toolbox: uptime: use clock_gettime() on devices without /dev/alarm
Change-Id: Id7287ca179cc0b8390c054803a25a961dd550a34
Signed-off-by: Greg Hackmann <ghackmann@google.com>
Diffstat (limited to 'toolbox')
| -rw-r--r-- | toolbox/uptime.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/toolbox/uptime.c b/toolbox/uptime.c index 455e7be44..3fb46061d 100644 --- a/toolbox/uptime.c +++ b/toolbox/uptime.c @@ -54,17 +54,27 @@ 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); - 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; |
