Merge "Fixed the sign error in GnssClock" into nyc-dev
diff --git a/location/java/android/location/GnssClock.java b/location/java/android/location/GnssClock.java
index d1b1be9..25d247d 100644
--- a/location/java/android/location/GnssClock.java
+++ b/location/java/android/location/GnssClock.java
@@ -97,7 +97,7 @@
*
* <p>The sign of the value is defined by the following equation:
* <pre>
- * UtcTimeNanos = TimeNanos + (FullBiasNanos + BiasNanos) - LeapSecond * 1,000,000,000</pre>
+ * UtcTimeNanos = TimeNanos - (FullBiasNanos + BiasNanos) - LeapSecond * 1,000,000,000</pre>
*
* <p>The value is only available if {@link #hasLeapSecond()} is {@code true}.
*/
@@ -130,9 +130,9 @@
*
* <p>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()}.
*
* <p>The error estimate for this value (if applicable) is {@link #getTimeUncertaintyNanos()}.
*/
@@ -213,7 +213,7 @@
* <p>The sign of the value is defined by the following equation:
*
* <pre>
- * local estimate of GPS time = TimeNanos + (FullBiasNanos + BiasNanos)</pre>
+ * local estimate of GPS time = TimeNanos - (FullBiasNanos + BiasNanos)</pre>
*/
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 ae05042..78b0844 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 @@
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<int32_t>(clock->leap_second));
@@ -1121,8 +1121,9 @@
// 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 @@
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 @@
}
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);