summaryrefslogtreecommitdiff
path: root/android/2.0
diff options
context:
space:
mode:
authorCyan_Hsieh <cyanhsieh@google.com>2019-11-19 13:30:14 +0800
committerCyan_Hsieh <cyanhsieh@google.com>2019-11-19 13:33:43 +0800
commit771e6abea8d6abf7acf215d58a990a32c27a0d05 (patch)
tree96c65fc86d6186be633fb3077d767b998e44a3df /android/2.0
parent17b63a71b11600dd4b25c8a8a8c284978e35b81e (diff)
parent1a16cbc20ca334b0a0a2793db3aa2984a6b6b66a (diff)
downloadgps-771e6abea8d6abf7acf215d58a990a32c27a0d05.tar.gz
Merge remote-tracking branch 'goog/qcom/release/LA.UM.8.1.C9.09.00.00.518.327' into qt-qpr1-dev
Bug: 144672341 Change-Id: Iaf7900aaa2105c25f50bd85ab68e6b421f0c2ea1
Diffstat (limited to 'android/2.0')
-rw-r--r--android/2.0/location_api/LocationUtil.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/android/2.0/location_api/LocationUtil.cpp b/android/2.0/location_api/LocationUtil.cpp
index 38a083a..8a30066 100644
--- a/android/2.0/location_api/LocationUtil.cpp
+++ b/android/2.0/location_api/LocationUtil.cpp
@@ -88,10 +88,41 @@ void convertGnssLocation(Location& in, V2_0::GnssLocation& out)
struct timespec sinceBootTime;
struct timespec currentTime;
- if (0 == clock_gettime(CLOCK_BOOTTIME,&sinceBootTime) &&
- 0 == clock_gettime(CLOCK_REALTIME,&currentTime)) {
+ struct timespec sinceBootTimeTest;
+ int64_t sinceBootTimeNanos = 0;
+ bool clockGetTimeSuccess = false;
+ const uint32_t MAX_TIME_DELTA_VALUE_NANOS = 10000;
+ const uint32_t MAX_GET_TIME_COUNT = 20;
+ /* Attempt to get CLOCK_REALTIME and CLOCK_BOOTIME in succession without an interruption
+ or context switch (for up to MAX_GET_TIME_COUNT times) to avoid errors in the calculation */
+ for (uint32_t i=0; i < MAX_GET_TIME_COUNT; i++) {
+ if (clock_gettime(CLOCK_BOOTTIME, &sinceBootTime) != 0) {
+ break;
+ };
+ if (clock_gettime(CLOCK_REALTIME, &currentTime) != 0) {
+ break;
+ }
+ if (clock_gettime(CLOCK_BOOTTIME, &sinceBootTimeTest) != 0) {
+ break;
+ };
+ sinceBootTimeNanos = sinceBootTime.tv_sec*1000000000 + sinceBootTime.tv_nsec;
+ int64_t sinceBootTimeTestNanos =
+ sinceBootTimeTest.tv_sec*1000000000 + sinceBootTimeTest.tv_nsec;
+ int64_t sinceBootTimeDeltaNanos = sinceBootTimeTestNanos - sinceBootTimeNanos;
- int64_t sinceBootTimeNanos = sinceBootTime.tv_sec*1000000000 + sinceBootTime.tv_nsec;
+ /* sinceBootTime and sinceBootTimeTest should have a close value if there was no
+ interruption or context switch between clock_gettime for CLOCK_BOOTIME and
+ clock_gettime for CLOCK_REALTIME */
+ if (sinceBootTimeDeltaNanos < MAX_TIME_DELTA_VALUE_NANOS) {
+ clockGetTimeSuccess = true;
+ break;
+ } else {
+ LOC_LOGD("%s]: Delta:%" PRIi64 "ns time too large, retry number #%u...",
+ __FUNCTION__, sinceBootTimeDeltaNanos, i+1);
+ }
+ }
+
+ if (clockGetTimeSuccess) {
int64_t currentTimeNanos = currentTime.tv_sec*1000000000 + currentTime.tv_nsec;
int64_t locationTimeNanos = in.timestamp*1000000;
LOC_LOGD("%s]: sinceBootTimeNanos:%" PRIi64 " currentTimeNanos:%" PRIi64 ""
@@ -110,8 +141,10 @@ void convertGnssLocation(Location& in, V2_0::GnssLocation& out)
__FUNCTION__, out.elapsedRealtime.timestampNs);
}
}
+ } else {
+ LOC_LOGE("%s]: Failed to calculate elapsedRealtimeNanos timestamp after %u tries",
+ __FUNCTION__, MAX_GET_TIME_COUNT);
}
-
}
void convertGnssLocation(const V1_0::GnssLocation& in, Location& out)