Use Android systemTime implementation for host linux.

The Android framework, notably android.view.Choreographer, assumes
that System.nanoTime and SystemClock.uptimeMills return consistent
values. This was true on device, but not on host.

This commit makes those values consistent on host linux. The necessary
support should be in place in kernels 2.6.39 and newer, which have been
available since 2012.

Test: m -j libutils
Change-Id: I833a89a810ae9fb3e8c01f6095ee2aca893c284f
This commit is contained in:
Brett Chabot 2019-09-17 13:23:59 -07:00
parent c21c0ac740
commit 1af6acc4d3

View file

@ -22,7 +22,8 @@
#include <limits.h>
#include <time.h>
#if defined(__ANDROID__)
// host linux support requires Linux 2.6.39+
#if defined(__linux__)
nsecs_t systemTime(int clock)
{
static const clockid_t clocks[] = {
@ -41,8 +42,7 @@ nsecs_t systemTime(int clock)
nsecs_t systemTime(int /*clock*/)
{
// Clock support varies widely across hosts. Mac OS doesn't support
// posix clocks, older glibcs don't support CLOCK_BOOTTIME and Windows
// is windows.
// CLOCK_BOOTTIME, and Windows is windows.
struct timeval t;
t.tv_sec = t.tv_usec = 0;
gettimeofday(&t, nullptr);