Fix CTS GPS test false failure
Fixes exception & false failure on CTS testing run indoors
Improving some text error messages too.
Bug: 30898485
Change-Id: Id119a83a32c25f33850825910ca84084a3e1116c
diff --git a/tests/tests/location/src/android/location/cts/GnssMeasurementWhenNoLocationTest.java b/tests/tests/location/src/android/location/cts/GnssMeasurementWhenNoLocationTest.java
index 0f4775e..32c54c9 100644
--- a/tests/tests/location/src/android/location/cts/GnssMeasurementWhenNoLocationTest.java
+++ b/tests/tests/location/src/android/location/cts/GnssMeasurementWhenNoLocationTest.java
@@ -135,7 +135,13 @@
List<GnssMeasurementsEvent> events = mMeasurementListener.getEvents();
Log.i(TAG, "Number of GPS measurement events received = " + events.size());
- // Ensure that after getting a few (at least 2) measurements, that we still don't have
+ if (events.isEmpty()) {
+ SoftAssert.failOrWarning(isMeasurementTestStrict(), "No measurement events received",
+ false);
+ return; // All of the following checks rely on there being measurements
+ }
+
+ // Ensure that after getting a few (at least 2) measurement events, that we still don't have
// location (i.e. that we got measurements before location.) Fail, if strict, warn, if not.
SoftAssert.failOrWarning(isMeasurementTestStrict(),
"Location was received before " + events.size() +
@@ -149,9 +155,8 @@
return; // allow a (passing) return, if not strict, otherwise continue
}
- // If device is not indoors, verify
- // 1) that we receive GPS measurements before being able to calculate the position solution
- // 2) that mandatory fields of GnssMeasurement are in expected ranges.
+ // If device has received measurements also verify
+ // that mandatory fields of GnssMeasurement are in expected ranges.
GnssMeasurementsEvent firstEvent = events.get(0);
Collection<GnssMeasurement> gpsMeasurements = firstEvent.getMeasurements();
int satelliteCount = gpsMeasurements.size();
diff --git a/tests/tests/location/src/android/location/cts/SoftAssert.java b/tests/tests/location/src/android/location/cts/SoftAssert.java
index 3913149..4349f07 100644
--- a/tests/tests/location/src/android/location/cts/SoftAssert.java
+++ b/tests/tests/location/src/android/location/cts/SoftAssert.java
@@ -156,7 +156,9 @@
if (testIsStrict) {
Assert.assertTrue(message, condition);
} else {
- failAsWarning("", message);
+ if (!condition) {
+ failAsWarning("", message);
+ }
}
}
diff --git a/tests/tests/location/src/android/location/cts/TestMeasurementUtil.java b/tests/tests/location/src/android/location/cts/TestMeasurementUtil.java
index 0b2d875..5810209 100644
--- a/tests/tests/location/src/android/location/cts/TestMeasurementUtil.java
+++ b/tests/tests/location/src/android/location/cts/TestMeasurementUtil.java
@@ -63,15 +63,12 @@
String testTag,
int minHardwareYear,
boolean isCtsVerifier) {
- // TODO(sumitk): Enable this check once api 24 for N is avaiable.
- /*
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
Log.i(TAG, "This test is designed to work on N or newer. " +
"Test is being skipped because the platform version is being run in " +
Build.VERSION.SDK_INT);
return false;
}
- */
// If device does not have a GPS, skip the test.
PackageManager pm = testLocationManager.getContext().getPackageManager();