Add testLowPowerModeGnssLocation and GnssMeasurementRegistrationTest to
location_privileged CTS
Bug: 156061898
Bug: 154503105
Test: atest GnssMeasurementRegistrationTest
atest GnssLocationValuesTest
Change-Id: I4d4d8273092fdd4446dc1226fae8ea67954f0692
diff --git a/tests/location/common/Android.bp b/tests/location/common/Android.bp
index 2b24322..4ca35fe 100644
--- a/tests/location/common/Android.bp
+++ b/tests/location/common/Android.bp
@@ -21,5 +21,4 @@
"compatibility-device-util-axt",
"android.test.base.stubs",
],
- sdk_version: "test_current",
}
diff --git a/tests/location/location_gnss/src/android/location/cts/common/GnssTestCase.java b/tests/location/common/src/android/location/cts/common/GnssTestCase.java
similarity index 88%
rename from tests/location/location_gnss/src/android/location/cts/common/GnssTestCase.java
rename to tests/location/common/src/android/location/cts/common/GnssTestCase.java
index 03f824e..6fe711a 100644
--- a/tests/location/location_gnss/src/android/location/cts/common/GnssTestCase.java
+++ b/tests/location/common/src/android/location/cts/common/GnssTestCase.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,8 +31,4 @@
protected GnssTestCase() {
}
-
- public boolean isCtsVerifierTest() {
- return false;
- }
}
diff --git a/tests/location/location_gnss/src/android/location/cts/common/SoftAssert.java b/tests/location/common/src/android/location/cts/common/SoftAssert.java
similarity index 98%
rename from tests/location/location_gnss/src/android/location/cts/common/SoftAssert.java
rename to tests/location/common/src/android/location/cts/common/SoftAssert.java
index 76d68f0..bbb4f8b 100644
--- a/tests/location/location_gnss/src/android/location/cts/common/SoftAssert.java
+++ b/tests/location/common/src/android/location/cts/common/SoftAssert.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Google Inc.
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,10 @@
package android.location.cts.common;
-import junit.framework.Assert;
-
import android.util.Log;
+import junit.framework.Assert;
+
import java.util.ArrayList;
import java.util.List;
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/TestGnssMeasurementListener.java b/tests/location/common/src/android/location/cts/common/TestGnssMeasurementListener.java
similarity index 98%
rename from tests/location/location_gnss/src/android/location/cts/gnss/TestGnssMeasurementListener.java
rename to tests/location/common/src/android/location/cts/common/TestGnssMeasurementListener.java
index 34fe9eb..3f309f9 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/TestGnssMeasurementListener.java
+++ b/tests/location/common/src/android/location/cts/common/TestGnssMeasurementListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Google Inc.
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package android.location.cts.gnss;
+package android.location.cts.common;
import android.location.GnssClock;
import android.location.GnssMeasurement;
import android.location.GnssMeasurementsEvent;
-import android.location.cts.common.TestUtils;
import android.util.Log;
import junit.framework.Assert;
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/TestLocationListener.java b/tests/location/common/src/android/location/cts/common/TestLocationListener.java
similarity index 96%
rename from tests/location/location_gnss/src/android/location/cts/gnss/TestLocationListener.java
rename to tests/location/common/src/android/location/cts/common/TestLocationListener.java
index 6252b18..7075e45 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/TestLocationListener.java
+++ b/tests/location/common/src/android/location/cts/common/TestLocationListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Google Inc.
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package android.location.cts.gnss;
+package android.location.cts.common;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
-import android.location.cts.common.TestUtils;
import android.os.Bundle;
import java.util.ArrayList;
diff --git a/tests/location/location_gnss/src/android/location/cts/common/TestLocationManager.java b/tests/location/common/src/android/location/cts/common/TestLocationManager.java
similarity index 82%
rename from tests/location/location_gnss/src/android/location/cts/common/TestLocationManager.java
rename to tests/location/common/src/android/location/cts/common/TestLocationManager.java
index de13864..bed3793 100644
--- a/tests/location/location_gnss/src/android/location/cts/common/TestLocationManager.java
+++ b/tests/location/common/src/android/location/cts/common/TestLocationManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Google Inc.
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,9 +19,11 @@
import android.content.Context;
import android.location.GnssMeasurementsEvent;
import android.location.GnssNavigationMessage;
+import android.location.GnssRequest;
import android.location.GnssStatus;
import android.location.LocationListener;
import android.location.LocationManager;
+import android.location.LocationRequest;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
@@ -89,6 +91,45 @@
}
/**
+ * See {@link android.location.LocationManager#registerGnssMeasurementsCallback
+ * (GnssMeasurementsEvent.Callback callback)}
+ *
+ * @param callback the listener to add
+ */
+ public void registerGnssMeasurementCallback(GnssMeasurementsEvent.Callback callback,
+ GnssRequest request) {
+ Log.i(TAG, "Add Gnss Measurement Callback. enableFullTracking=" + request);
+ boolean measurementListenerAdded =
+ mLocationManager.registerGnssMeasurementsCallback(request, Runnable::run, callback);
+ if (!measurementListenerAdded) {
+ // Registration of GnssMeasurements listener has failed, this indicates a platform bug.
+ Log.i(TAG, TestMeasurementUtil.REGISTRATION_ERROR_MESSAGE);
+ Assert.fail(TestMeasurementUtil.REGISTRATION_ERROR_MESSAGE);
+ }
+ }
+
+ /**
+ * Request GNSS location updates with {@code LocationRequest#setLowPowerMode()} enabled.
+ *
+ * See {@code LocationManager#requestLocationUpdates}.
+ *
+ * @param locationListener location listener for request
+ */
+ public void requestLowPowerModeGnssLocationUpdates(int minTimeMillis,
+ LocationListener locationListener) {
+ LocationRequest request = LocationRequest.createFromDeprecatedProvider(
+ LocationManager.GPS_PROVIDER, /* minTime= */ minTimeMillis, /* minDistance= */0,
+ false);
+ request.setLowPowerMode(true);
+ if (mLocationManager.getProvider(LocationManager.GPS_PROVIDER) != null) {
+ Log.i(TAG, "Request Location updates.");
+ mLocationManager.requestLocationUpdates(request,
+ locationListener,
+ Looper.getMainLooper());
+ }
+ }
+
+ /**
* See {@link android.location.LocationManager#unregisterGnssMeasurementsCallback
* (GnssMeasurementsEvent.Callback)}.
*
diff --git a/tests/location/location_gnss/src/android/location/cts/common/TestMeasurementUtil.java b/tests/location/common/src/android/location/cts/common/TestMeasurementUtil.java
similarity index 97%
rename from tests/location/location_gnss/src/android/location/cts/common/TestMeasurementUtil.java
rename to tests/location/common/src/android/location/cts/common/TestMeasurementUtil.java
index 282264d..d159828 100644
--- a/tests/location/location_gnss/src/android/location/cts/common/TestMeasurementUtil.java
+++ b/tests/location/common/src/android/location/cts/common/TestMeasurementUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Google Inc.
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,8 +22,6 @@
import android.location.GnssNavigationMessage;
import android.location.GnssStatus;
import android.location.LocationManager;
-import android.os.Build;
-import android.os.SystemProperties;
import android.util.Log;
import com.android.compatibility.common.util.ApiLevelUtil;
@@ -89,14 +87,17 @@
/**
* Check if test can be run on the current device.
*
+ * @param androidSdkVersionCode must be from {@link android.os.Build.VERSION_CODES}
* @param testLocationManager TestLocationManager
- * @return true if Build.VERSION >= Build.VERSION_CODES.N and Location GPS present on
+ * @return true if Build.VERSION >= {@code androidSdkVersionCode} and Location GPS present on
* device.
*/
- public static boolean canTestRunOnCurrentDevice(TestLocationManager testLocationManager,
- boolean isCtsVerifier) {
- if (ApiLevelUtil.isBefore(Build.VERSION_CODES.N)) {
- Log.i(TAG, "This test is designed to work on N or newer. " +
+ public static boolean canTestRunOnCurrentDevice(int androidSdkVersionCode,
+ TestLocationManager testLocationManager,
+ String testTag) {
+ if (ApiLevelUtil.isBefore(androidSdkVersionCode)) {
+ Log.i(testTag, "This test is designed to work on API level " +
+ androidSdkVersionCode + " or newer. " +
"Test is being skipped because the platform version is being run in " +
ApiLevelUtil.getApiLevel());
return false;
@@ -104,7 +105,7 @@
// If device does not have a GPS, skip the test.
if (!TestUtils.deviceHasGpsFeature(testLocationManager.getContext())) {
- return false;
+ return false;
}
// If device has a GPS, but it's turned off in settings, and this is CTS verifier,
@@ -113,14 +114,9 @@
// (Cts non-verifier deep-indoors-forgiveness happens later, *if* needed)
boolean gpsProviderEnabled = testLocationManager.getLocationManager()
.isProviderEnabled(LocationManager.GPS_PROVIDER);
- SoftAssert.failOrWarning(isCtsVerifier, " GPS location disabled on the device. " +
- "Enable location in settings to continue test.", gpsProviderEnabled);
- // If CTS only, allow an early exit pass
- if (!isCtsVerifier && !gpsProviderEnabled) {
- return false;
- }
-
- return true;
+ SoftAssert.failOrWarning(true, " GPS location disabled on the device. "
+ + "Enable location in settings to continue test.", gpsProviderEnabled);
+ return gpsProviderEnabled;
}
/**
diff --git a/tests/location/location_gnss/src/android/location/cts/common/TestUtils.java b/tests/location/common/src/android/location/cts/common/TestUtils.java
similarity index 98%
rename from tests/location/location_gnss/src/android/location/cts/common/TestUtils.java
rename to tests/location/common/src/android/location/cts/common/TestUtils.java
index bcf3f34..75c2b27 100644
--- a/tests/location/location_gnss/src/android/location/cts/common/TestUtils.java
+++ b/tests/location/common/src/android/location/cts/common/TestUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Google Inc.
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationRateChangeTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationRateChangeTest.java
index e7e740e..b0175a6 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationRateChangeTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationRateChangeTest.java
@@ -18,6 +18,7 @@
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestUtils;
import android.platform.test.annotations.AppModeFull;
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationUpdateIntervalTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationUpdateIntervalTest.java
index f031947..0733c0d 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationUpdateIntervalTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationUpdateIntervalTest.java
@@ -20,8 +20,10 @@
import android.location.LocationManager;
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestMeasurementUtil;
+import android.os.Build;
import android.util.Log;
import java.util.ArrayList;
@@ -79,7 +81,9 @@
}
public void testLocationUpdatesAtVariousIntervals() throws Exception {
- if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager, true)) {
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N,
+ mTestLocationManager,
+ TAG)) {
return;
}
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationValuesTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationValuesTest.java
index 9ac46df..a872c49 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationValuesTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssLocationValuesTest.java
@@ -19,8 +19,10 @@
import android.location.Location;
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestMeasurementUtil;
+import android.os.Build;
import android.util.Log;
/**
@@ -64,10 +66,10 @@
* only test them if the hardware is later than 2017
*/
public void testAccuracyFields() throws Exception {
- // Checks if GPS hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
- if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager, isCtsVerifierTest())) {
- return;
+ // Checks if GPS hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N, mTestLocationManager,
+ TAG)) {
+ return;
}
SoftAssert softAssert = new SoftAssert(TAG);
@@ -136,10 +138,10 @@
* check whether all fields' value make sense
*/
public void testLocationRegularFields() throws Exception {
- // Checks if GPS hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
- if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager, isCtsVerifierTest())) {
- return;
+ // Checks if GPS hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N, mTestLocationManager,
+ TAG)) {
+ return;
}
SoftAssert softAssert = new SoftAssert(TAG);
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementRegistrationTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementRegistrationTest.java
index 30b3c59..25d57f4 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementRegistrationTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementRegistrationTest.java
@@ -21,8 +21,11 @@
import android.location.GnssStatus;
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestGnssMeasurementListener;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestMeasurementUtil;
+import android.os.Build;
import android.util.Log;
import java.util.List;
@@ -82,10 +85,10 @@
* Test GPS measurements registration.
*/
public void testGnssMeasurementRegistration() throws Exception {
- // Checks if GPS hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
- if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager,
- isCtsVerifierTest())) {
+ // Checks if GPS hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N,
+ mTestLocationManager,
+ TAG)) {
return;
}
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementValuesTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementValuesTest.java
index 12a26f8..eb04679 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementValuesTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementValuesTest.java
@@ -20,8 +20,11 @@
import android.location.GnssMeasurementsEvent;
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestGnssMeasurementListener;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestMeasurementUtil;
+import android.os.Build;
import android.util.Log;
import java.util.HashSet;
@@ -80,10 +83,10 @@
* This tests uses actual data retrieved from GPS HAL.
*/
public void testListenForGnssMeasurements() throws Exception {
- // Checks if GPS hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
- if (!TestMeasurementUtil
- .canTestRunOnCurrentDevice(mTestLocationManager, isCtsVerifierTest())) {
+ // Checks if GPS hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N,
+ mTestLocationManager,
+ TAG)) {
return;
}
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementWhenNoLocationTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementWhenNoLocationTest.java
index 5586739..1e4e2c3 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementWhenNoLocationTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementWhenNoLocationTest.java
@@ -20,6 +20,9 @@
import android.location.GnssMeasurementsEvent;
import android.location.GnssStatus;
import android.location.cts.common.GnssTestCase;
+import android.location.cts.common.TestGnssMeasurementListener;
+import android.location.cts.common.TestLocationListener;
+import android.os.Build;
import android.platform.test.annotations.AppModeFull;
import android.util.Log;
import android.location.cts.common.TestUtils;
@@ -98,10 +101,10 @@
*/
@AppModeFull(reason = "Requires use of extra LocationManager commands")
public void testGnssMeasurementWhenNoLocation() throws Exception {
- // Checks if GPS hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
- if (!TestMeasurementUtil
- .canTestRunOnCurrentDevice(mTestLocationManager, isCtsVerifierTest())) {
+ // Checks if GPS hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N,
+ mTestLocationManager,
+ TAG)) {
return;
}
@@ -111,13 +114,11 @@
// Hence, airplane mode is turned on only when this test is run as a regular CTS test
// and not when it is invoked through CtsVerifier.
boolean isAirplaneModeOffBeforeTest = true;
- if (!isCtsVerifierTest()) {
- // Record the state of the airplane mode before the test so that we can restore it
- // after the test.
- isAirplaneModeOffBeforeTest = !TestUtils.isAirplaneModeOn();
- if (isAirplaneModeOffBeforeTest) {
- TestUtils.setAirplaneModeOn(getContext(), true);
- }
+ // Record the state of the airplane mode before the test so that we can restore it
+ // after the test.
+ isAirplaneModeOffBeforeTest = !TestUtils.isAirplaneModeOn();
+ if (isAirplaneModeOffBeforeTest) {
+ TestUtils.setAirplaneModeOn(getContext(), true);
}
try {
@@ -208,7 +209,7 @@
softAssert.assertAll();
} finally {
// Set the airplane mode back to off if it was off before this test.
- if (!isCtsVerifierTest() && isAirplaneModeOffBeforeTest) {
+ if (isAirplaneModeOffBeforeTest) {
TestUtils.setAirplaneModeOn(getContext(), false);
}
}
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementsConstellationTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementsConstellationTest.java
index e4ea91d..b34465e 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementsConstellationTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssMeasurementsConstellationTest.java
@@ -21,8 +21,11 @@
import android.location.GnssStatus;
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestGnssMeasurementListener;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestMeasurementUtil;
+import android.os.Build;
import android.util.Log;
import java.util.List;
@@ -75,10 +78,10 @@
* Test Gnss multi constellation supported.
*/
public void testGnssMultiConstellationSupported() throws Exception {
- // Checks if GPS hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
- if (!TestMeasurementUtil
- .canTestRunOnCurrentDevice(mTestLocationManager, isCtsVerifierTest())) {
+ // Checks if GPS hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N,
+ mTestLocationManager,
+ TAG)) {
return;
}
@@ -127,15 +130,6 @@
}
}
- // If test is running in CtsVerifier and multi constellation is not supported, then
- // throw MultiConstellationNotSupportedException which is used to indicate warning.
- if (isCtsVerifierTest() && !isExpectedConstellationType) {
- throw new MultiConstellationNotSupportedException(
- "\n\n WARNING: Device does not support Multi-constellation. " +
- "Device only supports GPS. " +
- "This will be mandatory starting from Android-O.\n");
- }
-
// In cts test just log it as warning if multi constellation is not supported
softAssert.assertTrueAsWarning(
"Constellation type is other than CONSTELLATION_GPS",
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssNavigationMessageRegistrationTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssNavigationMessageRegistrationTest.java
index 4bfd31c..24a1726 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssNavigationMessageRegistrationTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssNavigationMessageRegistrationTest.java
@@ -19,8 +19,10 @@
import android.location.GnssNavigationMessage;
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestMeasurementUtil;
+import android.os.Build;
import android.util.Log;
import java.util.List;
@@ -86,10 +88,10 @@
* It only performs sanity checks for the Navigation messages received.
*/
public void testGnssNavigationMessageRegistration() throws Exception {
- // Checks if GPS hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
- if (!TestMeasurementUtil
- .canTestRunOnCurrentDevice(mTestLocationManager, isCtsVerifierTest())) {
+ // Checks if GPS hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N,
+ mTestLocationManager,
+ TAG)) {
return;
}
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssNavigationMessageTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssNavigationMessageTest.java
index fa3d63c..69c5c9e 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssNavigationMessageTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssNavigationMessageTest.java
@@ -19,8 +19,10 @@
import android.location.GnssNavigationMessage;
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestMeasurementUtil;
+import android.os.Build;
import android.os.Parcel;
import java.util.List;
@@ -74,10 +76,10 @@
* This tests uses actual data retrieved from GPS HAL.
*/
public void testGnssNavigationMessageMandatoryFieldRanges() throws Exception {
- // Checks if GPS hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
- if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager,
- isCtsVerifierTest())) {
+ // Checks if GPS hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N,
+ mTestLocationManager,
+ TAG)) {
return;
}
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssPseudorangeVerificationTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssPseudorangeVerificationTest.java
index a539724..d1cca19 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssPseudorangeVerificationTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssPseudorangeVerificationTest.java
@@ -22,9 +22,12 @@
import android.location.Location;
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestGnssMeasurementListener;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestMeasurementUtil;
import android.location.cts.gnss.pseudorange.PseudorangePositionVelocityFromRealTimeEvents;
+import android.os.Build;
import android.platform.test.annotations.AppModeFull;
import android.util.Log;
@@ -104,10 +107,10 @@
*/
@CddTest(requirement="7.3.3")
public void testPseudorangeValue() throws Exception {
- // Checks if Gnss hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/Gnss (Provider) is turned on if is Cts Verifier.
- // From android O, CTS tests should run in the lab with GPS signal.
- if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager, true)) {
+ // Checks if Gnss hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N,
+ mTestLocationManager,
+ TAG)) {
return;
}
@@ -249,10 +252,10 @@
@CddTest(requirement = "7.3.3")
@AppModeFull(reason = "Flaky in instant mode")
public void testPseudoPosition() throws Exception {
- // Checks if Gnss hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/Gnss (Provider) is turned on if is Cts Verifier.
- // From android O, CTS tests should run in the lab with GPS signal.
- if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager, true)) {
+ // Checks if Gnss hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N,
+ mTestLocationManager,
+ TAG)) {
return;
}
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssStatusTest.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssStatusTest.java
index facd956..27467db 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssStatusTest.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssStatusTest.java
@@ -3,8 +3,10 @@
import android.location.GnssStatus;
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestMeasurementUtil;
+import android.os.Build;
import android.util.Log;
public class GnssStatusTest extends GnssTestCase {
@@ -23,9 +25,9 @@
* Tests that one can listen for {@link GnssStatus}.
*/
public void testGnssStatusChanges() throws Exception {
- // Checks if GPS hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
- if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager, isCtsVerifierTest())) {
+ // Checks if GPS hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N, mTestLocationManager,
+ TAG)) {
return;
}
@@ -62,9 +64,9 @@
* Tests values of {@link GnssStatus}.
*/
public void testGnssStatusValues() throws InterruptedException {
- // Checks if GPS hardware feature is present, skips test (pass) if not,
- // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
- if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager, isCtsVerifierTest())) {
+ // Checks if GPS hardware feature is present, skips test (pass) if not
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.N, mTestLocationManager,
+ TAG)) {
return;
}
SoftAssert softAssert = new SoftAssert(TAG);
diff --git a/tests/location/location_gnss/src/android/location/cts/gnss/GnssTtffTests.java b/tests/location/location_gnss/src/android/location/cts/gnss/GnssTtffTests.java
index 48edbc3..81c0292 100644
--- a/tests/location/location_gnss/src/android/location/cts/gnss/GnssTtffTests.java
+++ b/tests/location/location_gnss/src/android/location/cts/gnss/GnssTtffTests.java
@@ -2,6 +2,7 @@
import android.location.cts.common.GnssTestCase;
import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestLocationListener;
import android.location.cts.common.TestLocationManager;
import android.location.cts.common.TestUtils;
import android.net.ConnectivityManager;
diff --git a/tests/location/location_privileged/Android.bp b/tests/location/location_privileged/Android.bp
index 19ab211b..a32212d 100644
--- a/tests/location/location_privileged/Android.bp
+++ b/tests/location/location_privileged/Android.bp
@@ -16,6 +16,7 @@
name: "CtsLocationPrivilegedTestCases",
defaults: ["cts_defaults"],
static_libs: [
+ "LocationCtsCommon",
"androidx.test.ext.junit",
"androidx.test.ext.truth",
"androidx.test.rules",
diff --git a/tests/location/location_privileged/AndroidManifest.xml b/tests/location/location_privileged/AndroidManifest.xml
index 29df273..a0200fa 100644
--- a/tests/location/location_privileged/AndroidManifest.xml
+++ b/tests/location/location_privileged/AndroidManifest.xml
@@ -18,6 +18,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android.location.cts.privileged">
<uses-permission android:name="android.permission.LOCATION_HARDWARE" />
+ <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application>
<uses-library android:name="android.test.runner" />
diff --git a/tests/location/location_privileged/src/android/location/cts/privileged/GnssLocationValuesTest.java b/tests/location/location_privileged/src/android/location/cts/privileged/GnssLocationValuesTest.java
new file mode 100644
index 0000000..fc5481e
--- /dev/null
+++ b/tests/location/location_privileged/src/android/location/cts/privileged/GnssLocationValuesTest.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.location.cts.privileged;
+
+import android.Manifest;
+import android.location.Location;
+import android.location.cts.common.GnssTestCase;
+import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestLocationListener;
+import android.location.cts.common.TestLocationManager;
+import android.location.cts.common.TestMeasurementUtil;
+import android.os.Build;
+
+import androidx.test.InstrumentationRegistry;
+
+/**
+ * Test the {@link Location} values.
+ *
+ * Test steps:
+ * 1. Register for location updates.
+ * 2. Wait for {@link #LOCATION_TO_COLLECT_COUNT} locations.
+ * 3.1 Confirm locations have been found.
+ * 3. Get LastKnownLocation, verified all fields are in the correct range.
+ */
+public class GnssLocationValuesTest extends GnssTestCase {
+
+ private static final String TAG = "GnssLocationValuesTest";
+ private static final int LOCATION_TO_COLLECT_COUNT = 5;
+ private TestLocationListener mLocationListener;
+ // TODO(b/65458848): Re-tighten the limit to 0.001 when sufficient devices in the market comply
+ private static final double MINIMUM_SPEED_FOR_BEARING = 1.000;
+ private static final int MIN_ANDROID_SDK_VERSION_REQUIRED = Build.VERSION_CODES.O;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .adoptShellPermissionIdentity(Manifest.permission.LOCATION_HARDWARE);
+ mTestLocationManager = new TestLocationManager(getContext());
+ mLocationListener = new TestLocationListener(LOCATION_TO_COLLECT_COUNT);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ // Unregister listeners
+ if (mLocationListener != null) {
+ mTestLocationManager.removeLocationUpdates(mLocationListener);
+ }
+
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .dropShellPermissionIdentity();
+ super.tearDown();
+ }
+
+ /**
+ * 1. Get GNSS locations in low power mode.
+ * 2. Check whether all fields' value make sense.
+ */
+ public void testLowPowerModeGnssLocation() throws Exception {
+ // Checks if GPS hardware feature is present, skips test (pass) if not,
+ // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(MIN_ANDROID_SDK_VERSION_REQUIRED,
+ mTestLocationManager, TAG)) {
+ return;
+ }
+ mTestLocationManager.requestLowPowerModeGnssLocationUpdates(5000, mLocationListener);
+
+ waitAndValidateLocation();
+ }
+
+ private void waitAndValidateLocation() throws InterruptedException {
+ boolean success = mLocationListener.await();
+ SoftAssert softAssert = new SoftAssert(TAG);
+ softAssert.assertTrue(
+ "Time elapsed without getting the GNSS locations."
+ + " Possibly, the test has been run deep indoors."
+ + " Consider retrying test outdoors.",
+ success);
+
+ // don't check speed of first GNSS location - it may not be ready in some cases
+ boolean checkSpeed = false;
+ for (Location location : mLocationListener.getReceivedLocationList()) {
+ checkLocationRegularFields(softAssert, location, checkSpeed);
+ checkSpeed = true;
+ }
+
+ softAssert.assertAll();
+ }
+
+ private static void checkLocationRegularFields(SoftAssert softAssert, Location location,
+ boolean checkSpeed) {
+ // For the altitude: the unit is meter
+ // The lowest exposed land on Earth is at the Dead Sea shore, at -413 meters.
+ // Whilst University of Tokyo Atacama Obsevatory is on 5,640m above sea level.
+
+ softAssert.assertTrue("All GNSS locations generated by the LocationManager "
+ + "must have altitudes.", location.hasAltitude());
+ if (location.hasAltitude()) {
+ softAssert.assertTrue("Altitude should be greater than -500 (meters).",
+ location.getAltitude() >= -500);
+ softAssert.assertTrue("Altitude should be less than 6000 (meters).",
+ location.getAltitude() < 6000);
+ }
+
+ // It is guaranteed to be in the range [0.0, 360.0] if the device has a bearing.
+ // The API will return 0.0 if there is no bearing
+ if (location.hasSpeed() && location.getSpeed() > MINIMUM_SPEED_FOR_BEARING) {
+ softAssert.assertTrue("When speed is greater than 0, all GNSS locations generated by "
+ + "the LocationManager must have bearings.", location.hasBearing());
+ if (location.hasBearing()) {
+ softAssert.assertTrue("Bearing should be in the range of [0.0, 360.0]",
+ location.getBearing() >= 0 && location.getBearing() <= 360);
+ }
+ }
+
+ softAssert.assertTrue("ElapsedRaltimeNanos should be great than 0.",
+ location.getElapsedRealtimeNanos() > 0);
+
+ assertEquals("gps", location.getProvider());
+ assertTrue(location.getTime() > 0);
+
+ softAssert.assertTrue("Longitude should be in the range of [-180.0, 180.0] degrees",
+ location.getLongitude() >= -180 && location.getLongitude() <= 180);
+
+ softAssert.assertTrue("Latitude should be in the range of [-90.0, 90.0] degrees",
+ location.getLatitude() >= -90 && location.getLatitude() <= 90);
+
+ if (checkSpeed) {
+ softAssert.assertTrue("All but the first GNSS location from LocationManager "
+ + "must have speeds.", location.hasSpeed());
+ }
+
+ // For the speed, during the cts test device shouldn't move faster than 1m/s, but
+ // allowing up to 5m/s for possible early fix noise in moderate signal test environments.
+ if (location.hasSpeed()) {
+ softAssert.assertTrue(
+ "In the test environment, speed should be in the range of [0, 5] m/s",
+ location.getSpeed() >= 0 && location.getSpeed() <= 5);
+ }
+ }
+}
+
diff --git a/tests/location/location_privileged/src/android/location/cts/privileged/GnssMeasurementRegistrationTest.java b/tests/location/location_privileged/src/android/location/cts/privileged/GnssMeasurementRegistrationTest.java
new file mode 100644
index 0000000..a6e2021
--- /dev/null
+++ b/tests/location/location_privileged/src/android/location/cts/privileged/GnssMeasurementRegistrationTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.location.cts.privileged;
+
+import android.Manifest;
+import android.location.GnssMeasurementsEvent;
+import android.location.GnssRequest;
+import android.location.Location;
+import android.location.cts.common.GnssTestCase;
+import android.location.cts.common.SoftAssert;
+import android.location.cts.common.TestGnssMeasurementListener;
+import android.location.cts.common.TestLocationListener;
+import android.location.cts.common.TestLocationManager;
+import android.location.cts.common.TestMeasurementUtil;
+import android.os.Build;
+import android.util.Log;
+
+import androidx.test.InstrumentationRegistry;
+
+import java.util.List;
+
+/**
+ * Test for {@link GnssMeasurementsEvent.Callback} registration.
+ *
+ * Test steps:
+ * 1. Register a listener for {@link GnssMeasurementsEvent}s.
+ * 2. Check {@link GnssMeasurementsEvent} status: if the status is not
+ * {@link GnssMeasurementsEvent.Callback#STATUS_READY}, the test will fail and because one of
+ * the following reasons:
+ * 2.1 the device does not support the feature,
+ * 2.2 Location or GPS is disabled in the device.
+ * 3. If at least one {@link GnssMeasurementsEvent} is received, the test will pass.
+ * 4. If no {@link GnssMeasurementsEvent} are received, then check if the device can receive
+ * measurements only when {@link Location} is requested. This is done by performing the following
+ * steps:
+ * 4.1 Register for location updates.
+ * 4.2 Wait for {@link TestLocationListener#onLocationChanged(Location)}}.
+ * 4.3 If at least one {@link GnssMeasurementsEvent} is received, the test will pass.
+ * 4.4 If no {@link Location} is received this will mean that the device is located
+ * indoor. If we receive a {@link Location}, it mean that
+ * {@link GnssMeasurementsEvent}s are provided only if the application registers for
+ * location updates as well.
+ */
+public class GnssMeasurementRegistrationTest extends GnssTestCase {
+
+ private static final String TAG = "GnssMeasRegTest";
+ private static final int EVENTS_COUNT = 5;
+ private static final int GPS_EVENTS_COUNT = 1;
+ private TestLocationListener mLocationListener;
+ private TestGnssMeasurementListener mMeasurementListener;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .adoptShellPermissionIdentity(Manifest.permission.LOCATION_HARDWARE);
+ mTestLocationManager = new TestLocationManager(getContext());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ // Unregister listeners
+ if (mLocationListener != null) {
+ mTestLocationManager.removeLocationUpdates(mLocationListener);
+ }
+ if (mMeasurementListener != null) {
+ mTestLocationManager.unregisterGnssMeasurementCallback(mMeasurementListener);
+ }
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .dropShellPermissionIdentity();
+ super.tearDown();
+ }
+
+ /**
+ * Test GPS measurements registration with full tracking enabled.
+ */
+ public void testGnssMeasurementRegistration_enableFullTracking() throws Exception {
+ // Checks if GPS hardware feature is present, skips test (pass) if not,
+ // and hard asserts that Location/GPS (Provider) is turned on if is Cts Verifier.
+ if (!TestMeasurementUtil.canTestRunOnCurrentDevice(Build.VERSION_CODES.R,
+ mTestLocationManager,
+ TAG)) {
+ return;
+ }
+
+ // Register for GPS measurements.
+ mMeasurementListener = new TestGnssMeasurementListener(TAG, GPS_EVENTS_COUNT);
+ mTestLocationManager.registerGnssMeasurementCallback(mMeasurementListener,
+ new GnssRequest.Builder().setFullTracking(true).build());
+
+ mMeasurementListener.await();
+ if (!mMeasurementListener.verifyStatus()) {
+ // If test is strict verifyStatus will assert conditions are good for further testing.
+ // Else this returns false and, we arrive here, and then return from here (pass.)
+ return;
+ }
+
+ List<GnssMeasurementsEvent> events = mMeasurementListener.getEvents();
+ Log.i(TAG, "Number of GnssMeasurement events received = " + events.size());
+
+ if (!events.isEmpty()) {
+ // Test passes if we get at least 1 pseudorange.
+ Log.i(TAG, "Received GPS measurements. Test Pass.");
+ return;
+ }
+
+ SoftAssert.failAsWarning(
+ TAG,
+ "GPS measurements were not received without registering for location updates. "
+ + "Trying again with Location request.");
+
+ // Register for location updates.
+ mLocationListener = new TestLocationListener(EVENTS_COUNT);
+ mTestLocationManager.requestLocationUpdates(mLocationListener);
+
+ // Wait for location updates
+ mLocationListener.await();
+ Log.i(TAG, "Location received = " + mLocationListener.isLocationReceived());
+
+ events = mMeasurementListener.getEvents();
+ Log.i(TAG, "Number of GnssMeasurement events received = " + events.size());
+
+ SoftAssert softAssert = new SoftAssert(TAG);
+ softAssert.assertTrue(
+ "Did not receive any GnssMeasurement events. Retry outdoors?",
+ !events.isEmpty());
+ softAssert.assertAll();
+ }
+}