From e50607efab69c62d1a7b5ba9bb3dff47449483c9 Mon Sep 17 00:00:00 2001 From: Lifu Tang Date: Thu, 7 Apr 2016 19:25:24 -0700 Subject: [PATCH] Fixed the sign error in GnssClock Bug: 28068514 Change-Id: I71b68acb70d4139f94f3829bd4a280d926e251de --- location/java/android/location/GnssClock.java | 10 ++++---- ...d_server_location_GnssLocationProvider.cpp | 25 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/location/java/android/location/GnssClock.java b/location/java/android/location/GnssClock.java index d1b1be9393743..25d247deff24d 100644 --- a/location/java/android/location/GnssClock.java +++ b/location/java/android/location/GnssClock.java @@ -97,7 +97,7 @@ public final class GnssClock implements Parcelable { * *

The sign of the value is defined by the following equation: *

-     *     UtcTimeNanos = TimeNanos + (FullBiasNanos + BiasNanos) - LeapSecond * 1,000,000,000
+ * UtcTimeNanos = TimeNanos - (FullBiasNanos + BiasNanos) - LeapSecond * 1,000,000,000 * *

The value is only available if {@link #hasLeapSecond()} is {@code true}. */ @@ -130,9 +130,9 @@ public final class GnssClock implements Parcelable { * *

This value is expected to be monotonically increasing while the hardware clock remains * powered on. For the case of a hardware clock that is not continuously on, see the - * {@link #getHardwareClockDiscontinuityCount} field. The GPS time can be derived by adding - * {@link #getFullBiasNanos()} and {@link #getBiasNanos()} (when they are available) to this - * value. Sub-nanosecond accuracy can be provided by means of {@link #getBiasNanos()}. + * {@link #getHardwareClockDiscontinuityCount} field. The GPS time can be derived by subtracting + * the sum of {@link #getFullBiasNanos()} and {@link #getBiasNanos()} (when they are available) + * from this value. Sub-nanosecond accuracy can be provided by means of {@link #getBiasNanos()}. * *

The error estimate for this value (if applicable) is {@link #getTimeUncertaintyNanos()}. */ @@ -213,7 +213,7 @@ public final class GnssClock implements Parcelable { *

The sign of the value is defined by the following equation: * *

-     *     local estimate of GPS time = TimeNanos + (FullBiasNanos + BiasNanos)
+ * local estimate of GPS time = TimeNanos - (FullBiasNanos + BiasNanos) */ public long getFullBiasNanos() { return mFullBiasNanos; diff --git a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp index ae050429efed5..78b0844e8ed44 100644 --- a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp +++ b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp @@ -1112,7 +1112,7 @@ static jobject translate_gps_clock(JNIEnv* env, GpsClock* clock) { JavaObject object(env, "android/location/GnssClock"); GpsClockFlags flags = clock->flags; - SET_IF(GNSS_CLOCK_HAS_LEAP_SECOND, + SET_IF(GPS_CLOCK_HAS_LEAP_SECOND, LeapSecond, static_cast(clock->leap_second)); @@ -1121,8 +1121,9 @@ static jobject translate_gps_clock(JNIEnv* env, GpsClock* clock) { // old GPS_CLOCK types (active only in a limited number of older devices), // the GPS time information is handled as an always discontinuous HW clock, // with the GPS time information put into the full_bias_ns instead - so that - // time_ns + full_bias_ns = local estimate of GPS time (as remains true, in - // the new GnssClock struct.) + // time_ns - full_bias_ns = local estimate of GPS time. Additionally, the + // sign of full_bias_ns and bias_ns has flipped between GpsClock & + // GnssClock, so that is also handled below. switch (clock->type) { case GPS_CLOCK_TYPE_UNKNOWN: // Clock type unsupported. @@ -1133,7 +1134,7 @@ static jobject translate_gps_clock(JNIEnv* env, GpsClock* clock) { break; case GPS_CLOCK_TYPE_GPS_TIME: // GPS time, need to convert. - flags |= GNSS_CLOCK_HAS_FULL_BIAS; + flags |= GPS_CLOCK_HAS_FULL_BIAS; clock->full_bias_ns = clock->time_ns; clock->time_ns = 0; SET(HardwareClockDiscontinuityCount, @@ -1142,16 +1143,20 @@ static jobject translate_gps_clock(JNIEnv* env, GpsClock* clock) { } SET(TimeNanos, clock->time_ns); - SET_IF(GNSS_CLOCK_HAS_TIME_UNCERTAINTY, + SET_IF(GPS_CLOCK_HAS_TIME_UNCERTAINTY, TimeUncertaintyNanos, clock->time_uncertainty_ns); - SET_IF(GNSS_CLOCK_HAS_FULL_BIAS, FullBiasNanos, clock->full_bias_ns); - SET_IF(GNSS_CLOCK_HAS_BIAS, BiasNanos, clock->bias_ns); - SET_IF(GNSS_CLOCK_HAS_BIAS_UNCERTAINTY, + + // Definition of sign for full_bias_ns & bias_ns has been changed since N, + // so flip signs here. + SET_IF(GPS_CLOCK_HAS_FULL_BIAS, FullBiasNanos, -(clock->full_bias_ns)); + SET_IF(GPS_CLOCK_HAS_BIAS, BiasNanos, -(clock->bias_ns)); + + SET_IF(GPS_CLOCK_HAS_BIAS_UNCERTAINTY, BiasUncertaintyNanos, clock->bias_uncertainty_ns); - SET_IF(GNSS_CLOCK_HAS_DRIFT, DriftNanosPerSecond, clock->drift_nsps); - SET_IF(GNSS_CLOCK_HAS_DRIFT_UNCERTAINTY, + SET_IF(GPS_CLOCK_HAS_DRIFT, DriftNanosPerSecond, clock->drift_nsps); + SET_IF(GPS_CLOCK_HAS_DRIFT_UNCERTAINTY, DriftUncertaintyNanosPerSecond, clock->drift_uncertainty_nsps);