diff --git a/gnss/aidl/android/hardware/gnss/IGnssMeasurementInterface.aidl b/gnss/aidl/android/hardware/gnss/IGnssMeasurementInterface.aidl index 8733754e96..43164074da 100644 --- a/gnss/aidl/android/hardware/gnss/IGnssMeasurementInterface.aidl +++ b/gnss/aidl/android/hardware/gnss/IGnssMeasurementInterface.aidl @@ -78,6 +78,9 @@ interface IGnssMeasurementInterface { * output rate of 1Hz (occasional intra-measurement time offsets in the range from 0-2000msec * can be tolerated.) * + * If setCallback() is invoked without a previous close(), the HAL must use the new callback + * and parameters to provide updates. + * * @param callback Handle to GnssMeasurement callback interface. * @param enableFullTracking If true, GNSS chipset must switch off duty cycling. In such mode * no clock discontinuities are expected and, when supported, carrier phase should be @@ -104,6 +107,9 @@ interface IGnssMeasurementInterface { /** * Initializes the interface and registers the callback routines with the HAL. * + * If setCallbackWithOptions() is invoked without a previous close(), the HAL must use the new + * callback and options to provide updates. + * * @param options See Options definition. */ void setCallbackWithOptions(in IGnssMeasurementCallback callback, in Options options); diff --git a/gnss/aidl/vts/gnss_hal_test_cases.cpp b/gnss/aidl/vts/gnss_hal_test_cases.cpp index 3696233d3b..f1a9894c3e 100644 --- a/gnss/aidl/vts/gnss_hal_test_cases.cpp +++ b/gnss/aidl/vts/gnss_hal_test_cases.cpp @@ -1494,3 +1494,32 @@ TEST_P(GnssHalTest, TestGnssMeasurementIntervals_LocationOnAfterMeasurement) { assertMeanAndStdev(locationIntervalMs, deltas); } } + +TEST_P(GnssHalTest, TestGnssMeasurementSetCallback) { + if (aidl_gnss_hal_->getInterfaceVersion() <= 2) { + return; + } + + sp iGnssMeasurement; + auto status = aidl_gnss_hal_->getExtensionGnssMeasurement(&iGnssMeasurement); + ASSERT_TRUE(status.isOk()); + ASSERT_TRUE(iGnssMeasurement != nullptr); + + ALOGD("TestGnssMeasurementSetCallback"); + auto callback = sp::make(); + std::vector deltas; + + // setCallback at 20s interval and wait for 1 measurement + startMeasurementWithInterval(20000, iGnssMeasurement, callback); + collectMeasurementIntervals(callback, /* numEvents= */ 1, /* timeoutSeconds= */ 10, deltas); + + // setCallback at 1s interval and wait for 5 measurements + startMeasurementWithInterval(1000, iGnssMeasurement, callback); + collectMeasurementIntervals(callback, /* numEvents= */ 5, /* timeoutSeconds= */ 10, deltas); + + // verify the measurements were received at 1Hz + assertMeanAndStdev(1000, deltas); + + status = iGnssMeasurement->close(); + ASSERT_TRUE(status.isOk()); +}