目的:手机一旦重启后,让系统认为手机不是刚刚启动的,而是之前某个时间开机的。
int64_t elapsedRealtimeNano()
{
#if defined(__linux__)
struct timespec ts;
int err = clock_gettime(CLOCK_BOOTTIME, &ts);
if (CC_UNLIKELY(err)) {
// This should never happen, but just in case ...
ALOGE("clock_gettime(CLOCK_BOOTTIME) failed: %s", strerror(errno));
return 0;
}
//改大时间
ts.tv_sec = ts.tv_sec + 289*000;
//
return seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec;
#else
return systemTime(SYSTEM_TIME_MONOTONIC);
#endif
}
源码文件:
system/core/libutils/SystemClock.cpp