diff options
author | Yu Liu <yudiliu@google.com> | 2016-10-24 17:53:09 -0700 |
---|---|---|
committer | Yu Liu <yudiliu@google.com> | 2016-10-24 18:40:10 -0700 |
commit | 2d25bb5e6456032f9838b4ff6b3621632591a5b5 (patch) | |
tree | 2a2c3edcdc03d6046691139d9e1d434c63820db4 | |
parent | 995490cad52cb0aa0bce45724da9a1a366d798b2 (diff) | |
download | cts-2d25bb5e6456032f9838b4ff6b3621632591a5b5.tar.gz |
Add Gnss Status test
BUG: 31535558
Change-Id: Iff1fa29bf2539c6c3b1c94212050905379566018
6 files changed, 134 insertions, 6 deletions
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml index eaa308dd406..f40937f9614 100644 --- a/apps/CtsVerifier/AndroidManifest.xml +++ b/apps/CtsVerifier/AndroidManifest.xml @@ -494,6 +494,17 @@ <meta-data android:name="test_required_features" android:value="android.hardware.location.gps" /> </activity> + <activity android:name=".location.GnssStatusTestsActivity" + android:label="@string/location_gnss_status_test" + android:screenOrientation="locked"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.cts.intent.category.MANUAL_TEST"/> + </intent-filter> + <meta-data android:name="test_category" android:value="@string/test_category_hardware"/> + <meta-data android:name="test_required_features" android:value="android.hardware.location.gps" /> + </activity> + <activity android:name=".location.LocationListenerActivity" android:label="@string/location_listener_activity" android:configChanges="keyboardHidden|orientation|screenSize"> diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml index 1275c9e25b0..01b1139a348 100644 --- a/apps/CtsVerifier/res/values/strings.xml +++ b/apps/CtsVerifier/res/values/strings.xml @@ -423,6 +423,7 @@ <string name="location_gnss_reg_test">GNSS Measurement Registration Test</string> <string name="location_gnss_value_test">GNSS Measurement Values Test</string> <string name="location_gnss_nav_msg_test">GNSS Navigation Message Test</string> + <string name="location_gnss_status_test">GNSS Status Test</string> <string name="location_gnss_test_info">This test verifies basic GNSS behavior. Make sure the device has line of sight to GNSS satellites (for example, stationary on a windowsill. If needed, try again, outside, also with the diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/location/GnssStatusTestsActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/location/GnssStatusTestsActivity.java new file mode 100644 index 00000000000..a64c5d3de3a --- /dev/null +++ b/apps/CtsVerifier/src/com/android/cts/verifier/location/GnssStatusTestsActivity.java @@ -0,0 +1,15 @@ +package com.android.cts.verifier.location; + +import com.android.cts.verifier.location.base.GnssCtsTestActivity; +import android.location.cts.GnssStatusTest; + +/** + * Activity to execute CTS GnssStatusTest. + * It is a wrapper for {@link GnssStatusTest} running with AndroidJUnitRunner. + */ + +public class GnssStatusTestsActivity extends GnssCtsTestActivity { + public GnssStatusTestsActivity() { + super(GnssStatusTest.class); + } +} diff --git a/tests/tests/location/src/android/location/cts/GnssStatusTest.java b/tests/tests/location/src/android/location/cts/GnssStatusTest.java new file mode 100644 index 00000000000..e8f3cb132d0 --- /dev/null +++ b/tests/tests/location/src/android/location/cts/GnssStatusTest.java @@ -0,0 +1,49 @@ +package android.location.cts; + +import android.location.GnssStatus; + +public class GnssStatusTest extends GnssTestCase { + + private static final String TAG = "GnssStatusTest"; + private static final int LOCATION_TO_COLLECT_COUNT = 1; + private static final int STATUS_TO_COLLECT_COUNT = 3; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mTestLocationManager = new TestLocationManager(getContext()); + } + + /** + * 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, + TAG, MIN_HARDWARE_YEAR_MEASUREMENTS_REQUIRED, isCtsVerifierTest())) { + return; + } + + // Register Gps Status Listener. + TestGnssStatusCallback testGnssStatusCallback = + new TestGnssStatusCallback(TAG, STATUS_TO_COLLECT_COUNT); + mTestLocationManager.registerGnssStatusCallback(testGnssStatusCallback); + + TestLocationListener locationListener = new TestLocationListener(LOCATION_TO_COLLECT_COUNT); + mTestLocationManager.requestLocationUpdates(locationListener); + + boolean success = testGnssStatusCallback.awaitStart(); + success = success ? testGnssStatusCallback.awaitStatus() : false; + success = success ? testGnssStatusCallback.awaitTtff() : false; + mTestLocationManager.removeLocationUpdates(locationListener); + success = success ? testGnssStatusCallback.awaitStop() : false; + mTestLocationManager.unregisterGnssStatusCallback(testGnssStatusCallback); + + SoftAssert.failOrWarning(isMeasurementTestStrict(), + "Time elapsed without getting the right status changes." + + " Possibly, the test has been run deep indoors." + + " Consider retrying test outdoors.", + success); + } +} diff --git a/tests/tests/location/src/android/location/cts/TestGnssStatusCallback.java b/tests/tests/location/src/android/location/cts/TestGnssStatusCallback.java index cc4c930e823..c63fb01b04d 100644 --- a/tests/tests/location/src/android/location/cts/TestGnssStatusCallback.java +++ b/tests/tests/location/src/android/location/cts/TestGnssStatusCallback.java @@ -18,6 +18,7 @@ package android.location.cts; import android.location.GnssStatus; +import android.util.Log; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -28,34 +29,50 @@ import java.util.concurrent.TimeUnit; */ class TestGnssStatusCallback extends GnssStatus.Callback { + private final String mTag; private volatile boolean mGpsStatusReceived; private GnssStatus mGnssStatus = null; // Timeout in sec for count down latch wait private static final int TIMEOUT_IN_SEC = 90; - private final CountDownLatch mCountDownLatch; + private final CountDownLatch mLatchStart; + private final CountDownLatch mLatchStatus; + private final CountDownLatch mLatchTtff; + private final CountDownLatch mLatchStop; + // Store list of Prn for Satellites. private List<List<Integer>> mGpsSatellitePrns; - TestGnssStatusCallback(int gpsStatusCountToCollect) { - mCountDownLatch = new CountDownLatch(gpsStatusCountToCollect); + TestGnssStatusCallback(String tag, int gpsStatusCountToCollect) { + this.mTag = tag; + mLatchStart = new CountDownLatch(1); + mLatchStatus = new CountDownLatch(gpsStatusCountToCollect); + mLatchTtff = new CountDownLatch(1); + mLatchStop = new CountDownLatch(1); mGpsSatellitePrns = new ArrayList<List<Integer>>(); } @Override public void onStarted() { + Log.i(mTag, "Gnss Status Listener Started"); + mLatchStart.countDown(); } @Override public void onStopped() { + Log.i(mTag, "Gnss Status Listener Stopped"); + mLatchStop.countDown(); } @Override public void onFirstFix(int ttffMillis) { + Log.i(mTag, "Gnss Status Listener Received TTFF"); + mLatchTtff.countDown(); } @Override public void onSatelliteStatusChanged(GnssStatus status) { - mCountDownLatch.countDown(); + Log.i(mTag, "Gnss Status Listener Received Status Update"); + mLatchStatus.countDown(); } /** @@ -86,7 +103,19 @@ class TestGnssStatusCallback extends GnssStatus.Callback { return mGnssStatus; } - public boolean await() throws InterruptedException { - return TestUtils.waitFor(mCountDownLatch, TIMEOUT_IN_SEC); + public boolean awaitStart() throws InterruptedException { + return TestUtils.waitFor(mLatchStart, TIMEOUT_IN_SEC); + } + + public boolean awaitStatus() throws InterruptedException { + return TestUtils.waitFor(mLatchStatus, TIMEOUT_IN_SEC); + } + + public boolean awaitTtff() throws InterruptedException { + return TestUtils.waitFor(mLatchTtff, TIMEOUT_IN_SEC); + } + + public boolean awaitStop() throws InterruptedException { + return TestUtils.waitFor(mLatchStop, TIMEOUT_IN_SEC); } } diff --git a/tests/tests/location/src/android/location/cts/TestLocationManager.java b/tests/tests/location/src/android/location/cts/TestLocationManager.java index 26cc0576b87..cca2b78a496 100644 --- a/tests/tests/location/src/android/location/cts/TestLocationManager.java +++ b/tests/tests/location/src/android/location/cts/TestLocationManager.java @@ -19,6 +19,7 @@ package android.location.cts; import android.content.Context; import android.location.GnssMeasurementsEvent; import android.location.GnssNavigationMessage; +import android.location.GnssStatus; import android.location.GpsStatus; import android.location.LocationListener; import android.location.LocationManager; @@ -193,6 +194,28 @@ public class TestLocationManager { } /** + * Add a GNSS Status callback. + * + * @param callback a {@link GnssStatus.Callback} object to register. + * @return {@code true} if the listener was added successfully, {@code false} otherwise. + */ + public boolean registerGnssStatusCallback(GnssStatus.Callback callback) { + Log.i(TAG, "Add Gnss Status Callback."); + return mLocationManager.registerGnssStatusCallback( + callback, new Handler(Looper.getMainLooper())); + } + + /** + * Removes a GNSS Status callback. + * + * @param callback a {@link GnssStatus.Callback} object to remove. + */ + public void unregisterGnssStatusCallback(GnssStatus.Callback callback) { + Log.i(TAG, "Remove Gnss Status Callback."); + mLocationManager.unregisterGnssStatusCallback(callback); + } + + /** * Get LocationManager * * @return locationManager |