Add support in sensor tests to assume sensor under load.
b/17570759

- Add a test environment that carries information regarding the test execution
- The test environment inside CTS always assumes sensor under load

Change-Id: Idab31a71cfd9de76fab15334dbf19a5eb04bec7b
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerMeasurementTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerMeasurementTestActivity.java
index 265f086..945e9ab0 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerMeasurementTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerMeasurementTestActivity.java
@@ -21,6 +21,7 @@
 
 import android.hardware.Sensor;
 import android.hardware.SensorManager;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.sensoroperations.TestSensorOperation;
 import android.hardware.cts.helpers.sensorverification.MeanVerification;
 
@@ -91,12 +92,12 @@
      */
     private String verifyMeasurements(float ... expectations) throws Throwable {
         Thread.sleep(500 /*ms*/);
-        TestSensorOperation verifyMeasurements = new TestSensorOperation(
+        TestSensorEnvironment environment = new TestSensorEnvironment(
                 getApplicationContext(),
                 Sensor.TYPE_ACCELEROMETER,
-                SensorManager.SENSOR_DELAY_FASTEST,
-                0 /*reportLatencyInUs*/,
-                100 /* event count */);
+                SensorManager.SENSOR_DELAY_FASTEST);
+        TestSensorOperation verifyMeasurements =
+                new TestSensorOperation(environment, 100 /* event count */);
         verifyMeasurements.addVerification(new MeanVerification(
                 expectations,
                 new float[]{1.95f, 1.95f, 1.95f} /* m / s^2 */));
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/BatchingTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/BatchingTestActivity.java
index d6a6e36..4ba38a9 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/BatchingTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/BatchingTestActivity.java
@@ -22,6 +22,7 @@
 import android.content.Context;
 import android.hardware.Sensor;
 import android.hardware.SensorManager;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.sensoroperations.TestSensorFlushOperation;
 import android.hardware.cts.helpers.sensoroperations.TestSensorOperation;
 import android.hardware.cts.helpers.sensoroperations.VerifiableSensorOperation;
@@ -132,17 +133,16 @@
         getTestLogger().logInstructions(instructionsResId);
         waitForUserToBegin();
 
-        Context context = getApplicationContext();
         int maxBatchReportLatencyUs = (int) TimeUnit.SECONDS.toMicros(maxBatchReportLatencySec);
-        int testDurationSec = maxBatchReportLatencySec + BATCHING_PADDING_TIME_S;
-        TestSensorOperation operation = new TestSensorOperation(
-                context,
+        TestSensorEnvironment environment = new TestSensorEnvironment(
+                getApplicationContext(),
                 sensorType,
                 SENSOR_BATCHING_RATE_US,
-                maxBatchReportLatencyUs,
-                testDurationSec,
-                TimeUnit.SECONDS);
+                maxBatchReportLatencyUs);
 
+        int testDurationSec = maxBatchReportLatencySec + BATCHING_PADDING_TIME_S;
+        TestSensorOperation operation =
+                new TestSensorOperation(environment, testDurationSec,TimeUnit.SECONDS);
         return executeTest(operation);
     }
 
@@ -151,17 +151,16 @@
         getTestLogger().logInstructions(instructionsResId);
         waitForUserToBegin();
 
-        Context context = getApplicationContext();
         int maxBatchReportLatencyUs = (int) TimeUnit.SECONDS.toMicros(maxBatchReportLatencySec);
-        int flushDurationSec = maxBatchReportLatencySec / 2;
-        TestSensorFlushOperation operation = new TestSensorFlushOperation(
-                context,
+        TestSensorEnvironment environment = new TestSensorEnvironment(
+                getApplicationContext(),
                 sensorType,
                 SENSOR_BATCHING_RATE_US,
-                maxBatchReportLatencyUs,
-                flushDurationSec,
-                TimeUnit.SECONDS);
+                maxBatchReportLatencyUs);
 
+        int flushDurationSec = maxBatchReportLatencySec / 2;
+        TestSensorFlushOperation operation =
+                new TestSensorFlushOperation(environment, flushDurationSec, TimeUnit.SECONDS);
         return executeTest(operation);
     }
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/GyroscopeMeasurementTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/GyroscopeMeasurementTestActivity.java
index c4927e9..11a741b 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/GyroscopeMeasurementTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/GyroscopeMeasurementTestActivity.java
@@ -21,6 +21,7 @@
 
 import android.hardware.Sensor;
 import android.hardware.SensorManager;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.sensoroperations.TestSensorOperation;
 import android.hardware.cts.helpers.sensorverification.SigNumVerification;
 
@@ -119,12 +120,13 @@
         waitForUser();
 
         Thread.sleep(500 /*ms*/);
-        TestSensorOperation verifySignum = new TestSensorOperation(
+
+        TestSensorEnvironment environment = new TestSensorEnvironment(
                 getApplicationContext(),
                 Sensor.TYPE_GYROSCOPE,
-                SensorManager.SENSOR_DELAY_FASTEST,
-                0 /*reportLatencyInUs*/,
-                100 /* event count */);
+                SensorManager.SENSOR_DELAY_FASTEST);
+        TestSensorOperation verifySignum =
+                new TestSensorOperation(environment, 100 /* event count */);
         verifySignum.addVerification(new SigNumVerification(
                 expectations,
                 new float[]{0.2f, 0.2f, 0.2f} /*noiseThreshold*/));
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/MagneticFieldMeasurementTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/MagneticFieldMeasurementTestActivity.java
index 0e83a3e..c2a9207 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/MagneticFieldMeasurementTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/MagneticFieldMeasurementTestActivity.java
@@ -24,6 +24,7 @@
 import android.hardware.SensorEvent;
 import android.hardware.SensorEventListener2;
 import android.hardware.SensorManager;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEventListener;
 import android.hardware.cts.helpers.TestSensorManager;
 import android.hardware.cts.helpers.sensoroperations.TestSensorOperation;
@@ -77,9 +78,11 @@
             public void onFlushCompleted(Sensor sensor) {}
         };
 
-        TestSensorManager magnetometer = new TestSensorManager(
-                this.getApplicationContext(), Sensor.TYPE_MAGNETIC_FIELD,
-                SensorManager.SENSOR_DELAY_NORMAL, 0);
+        TestSensorEnvironment environment = new TestSensorEnvironment(
+                getApplicationContext(),
+                Sensor.TYPE_MAGNETIC_FIELD,
+                SensorManager.SENSOR_DELAY_NORMAL);
+        TestSensorManager magnetometer = new TestSensorManager(environment);
         try {
             magnetometer.registerListener(new TestSensorEventListener(listener));
             waitForUser();
@@ -109,16 +112,17 @@
      * - the values sampled from the sensor
      */
     private String verifyNorm() throws Throwable {
+        TestSensorEnvironment environment = new TestSensorEnvironment(
+                getApplicationContext(),
+                Sensor.TYPE_MAGNETIC_FIELD,
+                SensorManager.SENSOR_DELAY_FASTEST);
+        TestSensorOperation verifyNorm =
+                new TestSensorOperation(environment, 100 /* event count */);
+
         float expectedMagneticFieldEarth =
                 (SensorManager.MAGNETIC_FIELD_EARTH_MAX + SensorManager.MAGNETIC_FIELD_EARTH_MIN) / 2;
         float magneticFieldEarthThreshold =
                 expectedMagneticFieldEarth - SensorManager.MAGNETIC_FIELD_EARTH_MIN;
-        TestSensorOperation verifyNorm = new TestSensorOperation(
-                this.getApplicationContext(),
-                Sensor.TYPE_MAGNETIC_FIELD,
-                SensorManager.SENSOR_DELAY_FASTEST,
-                0 /*reportLatencyInUs*/,
-                100 /* event count */);
         verifyNorm.addVerification(new MagnitudeVerification(
                 expectedMagneticFieldEarth,
                 magneticFieldEarthThreshold));
@@ -150,12 +154,12 @@
      * the failure to help track down the issue.
      */
     private String verifyStandardDeviation() throws Throwable {
-        TestSensorOperation verifyStdDev = new TestSensorOperation(
-                this.getApplicationContext(),
+        TestSensorEnvironment environment = new TestSensorEnvironment(
+                getApplicationContext(),
                 Sensor.TYPE_MAGNETIC_FIELD,
-                SensorManager.SENSOR_DELAY_FASTEST,
-                0 /*reportLatencyInUs*/,
-                100 /* event count */);
+                SensorManager.SENSOR_DELAY_FASTEST);
+        TestSensorOperation verifyStdDev =
+                new TestSensorOperation(environment, 100 /* event count */);
         verifyStdDev.addVerification(new StandardDeviationVerification(
                 new float[]{2f, 2f, 2f} /* uT */));
         verifyStdDev.execute();
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/SensorValueAccuracyActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/SensorValueAccuracyActivity.java
index 39d02ac..4b74280 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/SensorValueAccuracyActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/SensorValueAccuracyActivity.java
@@ -27,6 +27,7 @@
 import android.hardware.SensorEventListener;
 import android.hardware.SensorManager;
 import android.hardware.cts.helpers.SensorNotSupportedException;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEvent;
 import android.hardware.cts.helpers.sensoroperations.TestSensorOperation;
 import android.hardware.cts.helpers.sensorverification.ISensorVerification;
@@ -172,12 +173,10 @@
         appendText(instructionsResId);
         waitForUser();
 
-        TestSensorOperation verifyNormOperation = new TestSensorOperation(
-                getApplicationContext(),
-                sensorType,
-                SENSOR_RATE,
-                0 /* reportLatencyInUs */,
-                EVENTS_TO_COLLECT);
+        TestSensorEnvironment environment =
+                new TestSensorEnvironment(getApplicationContext(), sensorType, SENSOR_RATE);
+        TestSensorOperation verifyNormOperation =
+                new TestSensorOperation(environment, EVENTS_TO_COLLECT);
 
         // TODO: add event ordering and timestamp > 0 verifications
         ISensorVerification magnitudeVerification =
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/base/SensorCtsTestResult.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/base/SensorCtsTestResult.java
index d07b4c4..851d405b 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/base/SensorCtsTestResult.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/base/SensorCtsTestResult.java
@@ -124,6 +124,7 @@
         if (testCase instanceof SensorTestCase) {
             SensorTestCase sensorTestCase = (SensorTestCase) testCase;
             sensorTestCase.setContext(mContext);
+            sensorTestCase.setEmulateSensorUnderLoad(false);
             // TODO: set delayed assertion provider
         } else {
             throw new IllegalStateException("TestCase must be an instance of SensorTestCase.");
diff --git a/tests/tests/hardware/src/android/hardware/cts/SensorBatchingTests.java b/tests/tests/hardware/src/android/hardware/cts/SensorBatchingTests.java
index 3d66b50..d00194f 100644
--- a/tests/tests/hardware/src/android/hardware/cts/SensorBatchingTests.java
+++ b/tests/tests/hardware/src/android/hardware/cts/SensorBatchingTests.java
@@ -16,12 +16,12 @@
 
 package android.hardware.cts;
 
-import android.content.Context;
 import android.hardware.Sensor;
 import android.hardware.SensorManager;
 import android.hardware.cts.helpers.SensorCtsHelper;
 import android.hardware.cts.helpers.SensorStats;
 import android.hardware.cts.helpers.SensorTestInformation;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.sensoroperations.TestSensorFlushOperation;
 import android.hardware.cts.helpers.sensoroperations.TestSensorOperation;
 import android.hardware.cts.helpers.sensoroperations.VerifiableSensorOperation;
@@ -255,36 +255,46 @@
 
     private void runBatchingSensorTest(int sensorType, int rateUs, int maxBatchReportLatencySec)
             throws Throwable {
-        Context context = getContext();
         int maxBatchReportLatencyUs = (int) TimeUnit.SECONDS.toMicros(maxBatchReportLatencySec);
         int testDurationSec = maxBatchReportLatencySec + BATCHING_PADDING_TIME_S;
-        TestSensorOperation operation = new TestSensorOperation(
-                context,
+
+        TestSensorEnvironment environment = new TestSensorEnvironment(
+                getContext(),
+                sensorType,
+                shouldEmulateSensorUnderLoad(),
+                rateUs,
+                maxBatchReportLatencyUs);
+        TestSensorOperation operation =
+                new TestSensorOperation(environment, testDurationSec, TimeUnit.SECONDS);
+
+        executeTest(
+                operation,
                 sensorType,
                 rateUs,
                 maxBatchReportLatencyUs,
-                testDurationSec,
-                TimeUnit.SECONDS);
-
-        boolean flushExpected = false;
-        executeTest(operation, sensorType, rateUs, maxBatchReportLatencyUs, flushExpected);
+                false /* flushExpected */);
     }
 
     private void runFlushSensorTest(int sensorType, int rateUs, int maxBatchReportLatencySec)
             throws Throwable {
-        Context context = getContext();
         int maxBatchReportLatencyUs = (int) TimeUnit.SECONDS.toMicros(maxBatchReportLatencySec);
         int flushDurationSec = maxBatchReportLatencySec / 2;
-        TestSensorFlushOperation operation = new TestSensorFlushOperation(
-                context,
+
+        TestSensorEnvironment environment = new TestSensorEnvironment(
+                getContext(),
+                sensorType,
+                shouldEmulateSensorUnderLoad(),
+                rateUs,
+                maxBatchReportLatencyUs);
+        TestSensorFlushOperation operation =
+                new TestSensorFlushOperation(environment, flushDurationSec, TimeUnit.SECONDS);
+
+        executeTest(
+                operation,
                 sensorType,
                 rateUs,
                 maxBatchReportLatencyUs,
-                flushDurationSec,
-                TimeUnit.SECONDS);
-
-        boolean flushExpected = true;
-        executeTest(operation, sensorType, rateUs, maxBatchReportLatencyUs, flushExpected);
+                true /* flushExpected */);
     }
 
     private void executeTest(
diff --git a/tests/tests/hardware/src/android/hardware/cts/SensorIntegrationTests.java b/tests/tests/hardware/src/android/hardware/cts/SensorIntegrationTests.java
index c471b7a..3c9eef9 100644
--- a/tests/tests/hardware/src/android/hardware/cts/SensorIntegrationTests.java
+++ b/tests/tests/hardware/src/android/hardware/cts/SensorIntegrationTests.java
@@ -23,6 +23,7 @@
 import android.hardware.SensorManager;
 import android.hardware.cts.helpers.SensorCtsHelper;
 import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.sensoroperations.ParallelSensorOperation;
 import android.hardware.cts.helpers.sensoroperations.RepeatingSensorOperation;
 import android.hardware.cts.helpers.sensoroperations.SequentialSensorOperation;
@@ -87,7 +88,7 @@
     public void testSensorsWithSeveralClients() throws Throwable {
         final int ITERATIONS = 50;
         final int MAX_REPORTING_LATENCY_IN_SECONDS = 5;
-        final Context context = this.getContext();
+        final Context context = getContext();
 
         int sensorTypes[] = {
                 Sensor.TYPE_ACCELEROMETER,
@@ -96,21 +97,25 @@
 
         ParallelSensorOperation operation = new ParallelSensorOperation();
         for(int sensorType : sensorTypes) {
-            TestSensorOperation continuousOperation = new TestSensorOperation(
+            TestSensorEnvironment environment = new TestSensorEnvironment(
                     context,
                     sensorType,
-                    SensorManager.SENSOR_DELAY_FASTEST,
-                    0 /* reportLatencyInUs */,
-                    100 /* event count */);
+                    shouldEmulateSensorUnderLoad(),
+                    SensorManager.SENSOR_DELAY_FASTEST);
+            TestSensorOperation continuousOperation =
+                    new TestSensorOperation(environment, 100 /* eventCount */);
             continuousOperation.addVerification(new EventOrderingVerification());
             operation.add(new RepeatingSensorOperation(continuousOperation, ITERATIONS));
 
-            TestSensorOperation batchingOperation = new TestSensorOperation(
+            Sensor sensor = TestSensorEnvironment.getSensor(context, sensorType);
+            TestSensorEnvironment batchingEnvironment = new TestSensorEnvironment(
                     context,
                     sensorType,
-                    SensorCtsHelper.getSensor(getContext(), sensorType).getMinDelay(),
-                    SensorCtsHelper.getSecondsAsMicroSeconds(MAX_REPORTING_LATENCY_IN_SECONDS),
-                    100);
+                    shouldEmulateSensorUnderLoad(),
+                    sensor.getMinDelay(),
+                    SensorCtsHelper.getSecondsAsMicroSeconds(MAX_REPORTING_LATENCY_IN_SECONDS));
+            TestSensorOperation batchingOperation =
+                    new TestSensorOperation(batchingEnvironment, 100 /* eventCount */);
             batchingOperation.addVerification(new EventOrderingVerification());
             operation.add(new RepeatingSensorOperation(batchingOperation, ITERATIONS));
         }
@@ -150,16 +155,19 @@
                 Sensor.TYPE_MAGNETIC_FIELD,
                 Sensor.TYPE_GYROSCOPE };
 
+        Context context = getContext();
         for(int sensorType : sensorTypes) {
             for(int instance = 0; instance < INSTANCES_TO_USE; ++instance) {
                 SequentialSensorOperation sequentialOperation = new SequentialSensorOperation();
                 for(int iteration = 0; iteration < ITERATIONS_TO_EXECUTE; ++iteration) {
-                    TestSensorOperation sensorOperation = new TestSensorOperation(
-                            this.getContext(),
+                    TestSensorEnvironment environment = new TestSensorEnvironment(
+                            context,
                             sensorType,
-                            this.generateSamplingRateInUs(sensorType),
-                            this.generateReportLatencyInUs(),
-                            100);
+                            shouldEmulateSensorUnderLoad(),
+                            generateSamplingRateInUs(sensorType),
+                            generateReportLatencyInUs());
+                    TestSensorOperation sensorOperation =
+                            new TestSensorOperation(environment, 100 /* eventCount */);
                     sensorOperation.addVerification(new EventOrderingVerification());
                     sequentialOperation.add(sensorOperation);
                 }
@@ -216,22 +224,24 @@
      * of several clients can lead to the failing state.
      */
     public void testSensorStoppingInteraction() throws Throwable {
-        Context context = this.getContext();
+        Context context = getContext();
 
-        TestSensorOperation tester = new TestSensorOperation(
+        TestSensorEnvironment testerEnvironment = new TestSensorEnvironment(
                 context,
                 mSensorTypeTester,
-                SensorManager.SENSOR_DELAY_FASTEST,
-                0 /*reportLatencyInUs*/,
-                100 /* event count */);
+                shouldEmulateSensorUnderLoad(),
+                SensorManager.SENSOR_DELAY_FASTEST);
+        TestSensorOperation tester =
+                new TestSensorOperation(testerEnvironment, 100 /* event count */);
         tester.addVerification(new EventOrderingVerification());
 
-        VerifiableSensorOperation testee = new TestSensorOperation(
+        TestSensorEnvironment testeeEnvironment = new TestSensorEnvironment(
                 context,
                 mSensorTypeTestee,
-                SensorManager.SENSOR_DELAY_FASTEST,
-                0 /*reportLatencyInUs*/,
-                100 /* event count */);
+                shouldEmulateSensorUnderLoad(),
+                SensorManager.SENSOR_DELAY_FASTEST);
+        VerifiableSensorOperation testee =
+                new TestSensorOperation(testeeEnvironment, 100 /* event count */);
         testee.addVerification(new EventOrderingVerification());
 
         ParallelSensorOperation operation = new ParallelSensorOperation();
@@ -256,8 +266,8 @@
                 rate = SensorManager.SENSOR_DELAY_FASTEST;
                 break;
             default:
-                int maxSamplingRate = SensorCtsHelper.getSensor(getContext(), sensorType)
-                        .getMinDelay();
+                Sensor sensor = TestSensorEnvironment.getSensor(getContext(), sensorType);
+                int maxSamplingRate = sensor.getMinDelay();
                 rate = maxSamplingRate * mGenerator.nextInt(10);
         }
         return rate;
diff --git a/tests/tests/hardware/src/android/hardware/cts/SensorTestCase.java b/tests/tests/hardware/src/android/hardware/cts/SensorTestCase.java
index 54c7ffe..6454678 100644
--- a/tests/tests/hardware/src/android/hardware/cts/SensorTestCase.java
+++ b/tests/tests/hardware/src/android/hardware/cts/SensorTestCase.java
@@ -22,8 +22,11 @@
 
 import android.app.Instrumentation;
 import android.cts.util.DeviceReportLog;
+import android.hardware.Sensor;
 import android.hardware.cts.helpers.SensorStats;
 import android.hardware.cts.helpers.SensorTestStateNotSupportedException;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.sensoroperations.ISensorOperation;
 import android.test.AndroidTestCase;
 import android.util.Log;
 
@@ -34,6 +37,17 @@
     // TODO: consolidate all log tags
     protected final String LOG_TAG = "TestRunner";
 
+    /**
+     * By default tests need to run in a {@link TestSensorEnvironment} that assumes each sensor is
+     * running with a load of several listeners, requesting data at different rates.
+     *
+     * In a better world the component acting as builder of {@link ISensorOperation} would compute
+     * this value based on the tests composed.
+     *
+     * Ideally, each {@link Sensor} object would expose this information to clients.
+     */
+    private volatile boolean mEmulateSensorUnderLoad = true;
+
     protected SensorTestCase() {}
 
     @Override
@@ -46,6 +60,14 @@
         }
     }
 
+    public void setEmulateSensorUnderLoad(boolean value) {
+        mEmulateSensorUnderLoad = value;
+    }
+
+    protected boolean shouldEmulateSensorUnderLoad() {
+        return mEmulateSensorUnderLoad;
+    }
+
     /**
      * Utility method to log selected stats to a {@link ReportLog} object.  The stats must be
      * a number or an array of numbers.
diff --git a/tests/tests/hardware/src/android/hardware/cts/SingleSensorTests.java b/tests/tests/hardware/src/android/hardware/cts/SingleSensorTests.java
index 866e556..a323ffa 100644
--- a/tests/tests/hardware/src/android/hardware/cts/SingleSensorTests.java
+++ b/tests/tests/hardware/src/android/hardware/cts/SingleSensorTests.java
@@ -16,11 +16,13 @@
 
 package android.hardware.cts;
 
+import android.content.Context;
 import android.hardware.Sensor;
 import android.hardware.SensorManager;
 import android.hardware.cts.helpers.SensorCtsHelper;
 import android.hardware.cts.helpers.SensorStats;
 import android.hardware.cts.helpers.SensorTestInformation;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.sensoroperations.TestSensorOperation;
 
 import java.util.HashMap;
@@ -110,15 +112,20 @@
         expectedProperties.put(Sensor.TYPE_GYROSCOPE, new Object[]{10000});
         expectedProperties.put(Sensor.TYPE_MAGNETIC_FIELD, new Object[]{100000});
 
+        SensorManager sensorManager =
+                (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
+        assertNotNull("SensorManager not present in the system.", sensorManager);
         for (Entry<Integer, Object[]> entry : expectedProperties.entrySet()) {
-            Sensor sensor = SensorCtsHelper.getSensor(getContext(), entry.getKey());
-            String sensorName = SensorTestInformation.getSensorName(entry.getKey());
-            if (entry.getValue()[0] != null) {
-                int expected = (Integer) entry.getValue()[0];
-                String msg = String.format(
-                        "%s: min delay %dus expected to be less than or equal to %dus",
-                        sensorName, sensor.getMinDelay(), expected);
-                assertTrue(msg, sensor.getMinDelay() <= expected);
+            Sensor sensor = sensorManager.getDefaultSensor(entry.getKey());
+            if (sensor != null) {
+                String sensorName = SensorTestInformation.getSensorName(entry.getKey());
+                if (entry.getValue()[0] != null) {
+                    int expected = (Integer) entry.getValue()[0];
+                    String msg = String.format(
+                            "%s: min delay %dus expected to be less than or equal to %dus",
+                            sensorName, sensor.getMinDelay(), expected);
+                    assertTrue(msg, sensor.getMinDelay() <= expected);
+                }
             }
         }
     }
@@ -529,10 +536,13 @@
         runSensorTest(Sensor.TYPE_LINEAR_ACCELERATION, RATE_1HZ);
     }
 
-    private void runSensorTest(int sensorType, int rateUs)
-            throws Throwable {
-        TestSensorOperation op = new TestSensorOperation(this.getContext(), sensorType,
-                rateUs, 0 /* maxBatchReportLatencyUs */, 5, TimeUnit.SECONDS);
+    private void runSensorTest(int sensorType, int rateUs) throws Throwable {
+        TestSensorEnvironment environment = new TestSensorEnvironment(
+                getContext(),
+                sensorType,
+                shouldEmulateSensorUnderLoad(),
+                rateUs);
+        TestSensorOperation op = new TestSensorOperation(environment, 5, TimeUnit.SECONDS);
         op.addDefaultVerifications();
         op.setLogEvents(true);
         try {
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/SensorCtsHelper.java b/tests/tests/hardware/src/android/hardware/cts/helpers/SensorCtsHelper.java
index b3f9fec..52f37e8 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/SensorCtsHelper.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/SensorCtsHelper.java
@@ -15,10 +15,6 @@
  */
 package android.hardware.cts.helpers;
 
-import android.content.Context;
-import android.hardware.Sensor;
-import android.hardware.SensorManager;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -104,30 +100,6 @@
     }
 
     /**
-     * Get the default sensor for a given type.
-     */
-    public static Sensor getSensor(Context context, int sensorType) {
-        SensorManager sensorManager = getSensorManager(context);
-        Sensor sensor = sensorManager.getDefaultSensor(sensorType);
-        if(sensor == null) {
-            throw new SensorNotSupportedException(sensorType);
-        }
-        return sensor;
-    }
-
-    /**
-     * Get all the sensors for a given type.
-     */
-    public static List<Sensor> getSensors(Context context, int sensorType) {
-        SensorManager sensorManager = getSensorManager(context);
-        List<Sensor> sensors = sensorManager.getSensorList(sensorType);
-        if (sensors.size() == 0) {
-            throw new SensorNotSupportedException(sensorType);
-        }
-        return sensors;
-    }
-
-    /**
      * Convert a period to frequency in Hz.
      */
     public static <TValue extends Number> double getFrequency(TValue period, TimeUnit unit) {
@@ -149,37 +121,6 @@
     }
 
     /**
-     * Convert the sensor delay or rate in microseconds into delay in microseconds.
-     * <p>
-     * The flags SensorManager.SENSOR_DELAY_[GAME|UI|NORMAL] are not supported since the CDD does
-     * not specify values for these flags. The rate is set to the max of
-     * {@link Sensor#getMinDelay()} and the rate given.
-     * </p>
-     */
-    public static int getDelay(Sensor sensor, int rateUs) {
-        if (!isDelayRateTestable(rateUs)) {
-            throw new IllegalArgumentException("rateUs cannot be SENSOR_DELAY_[GAME|UI|NORMAL]");
-        }
-        int delay;
-        if (rateUs == SensorManager.SENSOR_DELAY_FASTEST) {
-            delay = 0;
-        } else {
-            delay = rateUs;
-        }
-        return Math.max(delay, sensor.getMinDelay());
-    }
-
-    /**
-     * Return true if the operation rate is not one of {@link SensorManager#SENSOR_DELAY_GAME},
-     * {@link SensorManager#SENSOR_DELAY_UI}, or {@link SensorManager#SENSOR_DELAY_NORMAL}.
-     */
-    public static boolean isDelayRateTestable(int rateUs) {
-        return (rateUs != SensorManager.SENSOR_DELAY_GAME
-                && rateUs != SensorManager.SENSOR_DELAY_UI
-                && rateUs != SensorManager.SENSOR_DELAY_NORMAL);
-    }
-
-    /**
      * Helper method to sleep for a given duration.
      */
     public static void sleep(long duration, TimeUnit timeUnit) {
@@ -194,34 +135,53 @@
     /**
      * Format an assertion message.
      *
-     * @param sensor the {@link Sensor}
      * @param label the verification name
-     * @param rateUs the rate of the sensor
-     * @param maxBatchReportLatencyUs the max batch report latency of the sensor
+     * @param environment the environment of the test
+     *
      * @return The formatted string
      */
-    public static String formatAssertionMessage(Sensor sensor, String label, int rateUs,
-            int maxBatchReportLatencyUs) {
-        return String.format("%s | %s", label,
-                SensorTestInformation.getSensorName(sensor.getType()));
+    public static String formatAssertionMessage(String label, TestSensorEnvironment environment) {
+        return formatAssertionMessage(label, environment, "");
     }
 
     /**
      * Format an assertion message with a custom message.
      *
-     * @param sensor the {@link Sensor}
      * @param label the verification name
-     * @param rateUs the rate of the sensor
-     * @param maxBatchReportLatencyUs the max batch report latency of the sensor
+     * @param environment the environment of the test
      * @param format the additional format string
      * @param params the additional format params
+     *
      * @return The formatted string
      */
-    public static String formatAssertionMessage(Sensor sensor, String label, int rateUs,
-            int maxBatchReportLatencyUs, String format, Object ... params) {
-        return String.format("%s | %s, rateUs: %d, maxBatchReportLatencyUs: %d | %s",
-                label, SensorTestInformation.getSensorName(sensor.getType()),
-                rateUs, maxBatchReportLatencyUs, String.format(format, params));
+    public static String formatAssertionMessage(
+            String label,
+            TestSensorEnvironment environment,
+            String format,
+            Object ... params) {
+        return formatAssertionMessage(label, environment, String.format(format, params));
+    }
+
+    /**
+     * Format an assertion message.
+     *
+     * @param label the verification name
+     * @param environment the environment of the test
+     * @param extras the additional information for the assertion
+     *
+     * @return The formatted string
+     */
+    public static String formatAssertionMessage(
+            String label,
+            TestSensorEnvironment environment,
+            String extras) {
+        return String.format(
+                "%s | sensor=%s, rateUs=%d, maxBatchReportLatenchUs=%d | %s",
+                label,
+                SensorTestInformation.getSensorName(environment.getSensor().getType()),
+                environment.getRequestedSamplingPeriodUs(),
+                environment.getMaxReportLatencyUs(),
+                extras);
     }
 
     /**
@@ -234,18 +194,4 @@
             throw new IllegalStateException("Collection cannot be null or empty");
         }
     }
-
-    /**
-     * Get the SensorManager.
-     *
-     * @throws IllegalStateException if the SensorManager is not present in the system.
-     */
-    private static SensorManager getSensorManager(Context context) {
-        SensorManager sensorManager = (SensorManager) context.getSystemService(
-                Context.SENSOR_SERVICE);
-        if(sensorManager == null) {
-            throw new IllegalStateException("SensorService is not present in the system.");
-        }
-        return sensorManager;
-    }
 }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/SensorTestInformation.java b/tests/tests/hardware/src/android/hardware/cts/helpers/SensorTestInformation.java
index b220b00..86c164d 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/SensorTestInformation.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/SensorTestInformation.java
@@ -25,41 +25,8 @@
 public class SensorTestInformation {
     private SensorTestInformation() {}
 
-    public enum SensorReportingMode {
-        CONTINUOUS,
-        ON_CHANGE,
-        ONE_SHOT,
-    }
-
-    @SuppressWarnings("deprecation")
-    public static SensorReportingMode getReportingMode(int sensorType) {
-        switch(sensorType) {
-            case Sensor.TYPE_ACCELEROMETER:
-            case Sensor.TYPE_MAGNETIC_FIELD:
-            case Sensor.TYPE_ORIENTATION:
-            case Sensor.TYPE_GYROSCOPE:
-            case Sensor.TYPE_PRESSURE:
-            case Sensor.TYPE_GRAVITY:
-            case Sensor.TYPE_LINEAR_ACCELERATION:
-            case Sensor.TYPE_ROTATION_VECTOR:
-            case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
-            case Sensor.TYPE_GAME_ROTATION_VECTOR:
-            case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
-            case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR:
-                return SensorReportingMode.CONTINUOUS;
-            case Sensor.TYPE_LIGHT:
-            case Sensor.TYPE_TEMPERATURE:
-            case Sensor.TYPE_PROXIMITY:
-            case Sensor.TYPE_RELATIVE_HUMIDITY:
-            case Sensor.TYPE_AMBIENT_TEMPERATURE:
-            case Sensor.TYPE_STEP_DETECTOR:
-            case Sensor.TYPE_STEP_COUNTER:
-                return SensorReportingMode.ON_CHANGE;
-            case Sensor.TYPE_SIGNIFICANT_MOTION:
-                return SensorReportingMode.ONE_SHOT;
-            default:
-                return null;
-        }
+    public static String getSensorName(Sensor sensor) {
+        return getSensorName(sensor.getType());
     }
 
     public static String getSensorName(int sensorType) {
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorEnvironment.java b/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorEnvironment.java
new file mode 100644
index 0000000..b1ffd85
--- /dev/null
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorEnvironment.java
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2014 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.hardware.cts.helpers;
+
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.hardware.cts.helpers.sensoroperations.ISensorOperation;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A class that encapsulates base environment information for the {@link ISensorOperation}.
+ * The environment is self contained and carries its state around all the sensor test framework.
+ */
+public class TestSensorEnvironment {
+    private final Context mContext;
+    private final Sensor mSensor;
+    private final boolean mSensorMightHaveMoreListeners;
+    private final int mSamplingPeriodUs;
+    private final int mMaxReportLatencyUs;
+
+    /**
+     * Constructs an environment for sensor testing.
+     *
+     * @param context The context for the test
+     * @param sensorType The type of the sensor under test
+     * @param samplingPeriodUs The requested collection period for the sensor under test
+     */
+    public TestSensorEnvironment(Context context, int sensorType, int samplingPeriodUs) {
+        this(context, sensorType, false /* sensorMightHaveMoreListeners */, samplingPeriodUs);
+    }
+
+    /**
+     * Constructs an environment for sensor testing.
+     *
+     * @param context The context for the test
+     * @param sensorType The type of the sensor under test
+     * @param samplingPeriodUs The requested collection period for the sensor under test
+     * @param maxReportLatencyUs The requested collection report latency for the sensor under test
+     */
+    public TestSensorEnvironment(
+            Context context,
+            int sensorType,
+            int samplingPeriodUs,
+            int maxReportLatencyUs) {
+        this(context,
+                sensorType,
+                false /* sensorMightHaveMoreListeners */,
+                samplingPeriodUs,
+                maxReportLatencyUs);
+    }
+
+    /**
+     * Constructs an environment for sensor testing.
+     *
+     * @param context The context for the test
+     * @param sensorType The type of the sensor under test
+     * @param sensorMightHaveMoreListeners Whether the sensor under test is acting under load
+     * @param samplingPeriodUs The requested collection period for the sensor under test
+     */
+    public TestSensorEnvironment(
+            Context context,
+            int sensorType,
+            boolean sensorMightHaveMoreListeners,
+            int samplingPeriodUs) {
+        this(context,
+                sensorType,
+                sensorMightHaveMoreListeners,
+                samplingPeriodUs,
+                0 /* maxReportLatencyUs */);
+    }
+
+    /**
+     * Constructs an environment for sensor testing.
+     *
+     * @param context The context for the test
+     * @param sensorType The type of the sensor under test
+     * @param sensorMightHaveMoreListeners Whether the sensor under test is acting under load
+     * @param samplingPeriodUs The requested collection period for the sensor under test
+     * @param maxReportLatencyUs The requested collection report latency for the sensor under test
+     */
+    public TestSensorEnvironment(
+            Context context,
+            int sensorType,
+            boolean sensorMightHaveMoreListeners,
+            int samplingPeriodUs,
+            int maxReportLatencyUs) {
+        this(context,
+                getSensor(context, sensorType),
+                sensorMightHaveMoreListeners,
+                samplingPeriodUs,
+                maxReportLatencyUs);
+    }
+
+    /**
+     * Constructs an environment for sensor testing.
+     *
+     * @param context The context for the test
+     * @param sensor The sensor under test
+     * @param sensorMightHaveMoreListeners Whether the sensor under test is acting under load (this
+     *                                     usually implies that there are several listeners
+     *                                     requesting different sampling periods)
+     * @param samplingPeriodUs The requested collection period for the sensor under test
+     * @param maxReportLatencyUs The requested collection report latency for the sensor under test
+     */
+    public TestSensorEnvironment(
+            Context context,
+            Sensor sensor,
+            boolean sensorMightHaveMoreListeners,
+            int samplingPeriodUs,
+            int maxReportLatencyUs) {
+        mContext = context;
+        mSensor = sensor;
+        mSensorMightHaveMoreListeners = sensorMightHaveMoreListeners;
+        mSamplingPeriodUs = samplingPeriodUs;
+        mMaxReportLatencyUs = maxReportLatencyUs;
+    }
+
+    /**
+     * @return The context instance associated with the test.
+     */
+    public Context getContext() {
+        return mContext;
+    }
+
+    /**
+     * @return The sensor under test.
+     */
+    public Sensor getSensor() {
+        return mSensor;
+    }
+
+    /**
+     * @return The requested collection rate in microseconds.
+     */
+    public int getRequestedSamplingPeriodUs() {
+        return mSamplingPeriodUs;
+    }
+
+    /**
+     * @return The frequency equivalent to {@link #getRequestedSamplingPeriodUs()}.
+     */
+    public double getFrequencyHz() {
+        return SensorCtsHelper.getFrequency(mSamplingPeriodUs, TimeUnit.MICROSECONDS);
+    }
+
+    /**
+     * @return The requested collection max batch report latency in microseconds.
+     */
+    public int getMaxReportLatencyUs() {
+        return mMaxReportLatencyUs;
+    }
+
+    /**
+     * Returns {@code true} if there might be other listeners of {@link #getSensor()} requesting
+     * data at different sampling rates (the rates are unknown); false otherwise.
+     */
+    public boolean isSensorSamplingRateOverloaded() {
+        return mSensorMightHaveMoreListeners && mSamplingPeriodUs != SensorManager.SENSOR_DELAY_FASTEST;
+    }
+
+    /**
+     * Convert the {@link #getRequestedSamplingPeriodUs()} into delay in microseconds.
+     * <p>
+     * The flags SensorManager.SENSOR_DELAY_[GAME|UI|NORMAL] are not supported since the CDD does
+     * not specify values for these flags. The rate is set to the max of
+     * {@link Sensor#getMinDelay()} and the rate given.
+     * </p>
+     */
+    public int getExpectedSamplingPeriodUs() {
+        if (!isDelayRateTestable()) {
+            throw new IllegalArgumentException("rateUs cannot be SENSOR_DELAY_[GAME|UI|NORMAL]");
+        }
+
+        int expectedSamplingPeriodUs = mSamplingPeriodUs;
+        int sensorMaxDelay = mSensor.getMaxDelay();
+        if (sensorMaxDelay > 0) {
+            expectedSamplingPeriodUs = Math.min(expectedSamplingPeriodUs, sensorMaxDelay);
+        }
+
+        return Math.max(expectedSamplingPeriodUs, mSensor.getMinDelay());
+    }
+
+    /**
+     * Get the default sensor for a given type.
+     *
+     * @deprecated Used for historical reasons, sensor tests must be written around Sensor objects,
+     * so all sensors of a given type are exercised.
+     */
+    @Deprecated
+    public static Sensor getSensor(Context context, int sensorType) {
+        SensorManager sensorManager =
+                (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+        if (sensorManager == null) {
+            throw new IllegalStateException("SensorService is not present in the system.");
+        }
+
+        Sensor sensor = sensorManager.getDefaultSensor(sensorType);
+        if(sensor == null) {
+            throw new SensorNotSupportedException(sensorType);
+        }
+        return sensor;
+    }
+
+    /**
+     * Return true if {@link #getRequestedSamplingPeriodUs()} is not one of
+     * {@link SensorManager#SENSOR_DELAY_GAME}, {@link SensorManager#SENSOR_DELAY_UI}, or
+     * {@link SensorManager#SENSOR_DELAY_NORMAL}.
+     */
+    private boolean isDelayRateTestable() {
+        return (mSamplingPeriodUs >= 0
+                && mSamplingPeriodUs != SensorManager.SENSOR_DELAY_GAME
+                && mSamplingPeriodUs != SensorManager.SENSOR_DELAY_UI
+                && mSamplingPeriodUs != SensorManager.SENSOR_DELAY_NORMAL);
+    }
+}
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorEventListener.java b/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorEventListener.java
index f06b9d7..5197184 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorEventListener.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorEventListener.java
@@ -40,13 +40,10 @@
 
     private final SensorEventListener2 mListener;
 
-    private volatile CountDownLatch mEventLatch = null;
+    private volatile CountDownLatch mEventLatch;
     private volatile CountDownLatch mFlushLatch = new CountDownLatch(1);
-
-    private Sensor mSensor = null;
-    private int mRateUs = 0;
-    private int mMaxBatchReportLatencyUs = 0;
-    private boolean mLogEvents = false;
+    private volatile TestSensorEnvironment mEnvironment;
+    private volatile boolean mLogEvents;
 
     /**
      * Construct a {@link TestSensorEventListener}.
@@ -74,10 +71,8 @@
     /**
      * Set the sensor, rate, and batch report latency used for the assertions.
      */
-    public void setSensorInfo(Sensor sensor, int rateUs, int maxBatchReportLatencyUs) {
-        mSensor = sensor;
-        mRateUs = rateUs;
-        mMaxBatchReportLatencyUs = maxBatchReportLatencyUs;
+    public void setEnvironment(TestSensorEnvironment environment) {
+        mEnvironment = environment;
     }
 
     /**
@@ -111,7 +106,9 @@
 
             Log.v(LOG_TAG, String.format(
                     "Sensor %d: sensor_timestamp=%d, received_timestamp=%d, values=%s",
-                    mSensor.getType(), event.timestamp, System.nanoTime(),
+                    mEnvironment.getSensor().getType(),
+                    event.timestamp,
+                    System.nanoTime(),
                     Arrays.toString(event.values)));
         }
     }
@@ -146,9 +143,9 @@
         CountDownLatch latch = mFlushLatch;
         try {
             if(latch != null) {
-                String message = SensorCtsHelper.formatAssertionMessage(mSensor, "WaitForFlush",
-                        mRateUs, mMaxBatchReportLatencyUs);
-                Assert.assertTrue(message, latch.await(FLUSH_TIMEOUT_US, TimeUnit.MICROSECONDS));
+                Assert.assertTrue(
+                        SensorCtsHelper.formatAssertionMessage("WaitForFlush", mEnvironment),
+                        latch.await(FLUSH_TIMEOUT_US, TimeUnit.MICROSECONDS));
             }
         } catch(InterruptedException e) {
             // Ignore
@@ -163,14 +160,17 @@
     public void waitForEvents(int eventCount) {
         mEventLatch = new CountDownLatch(eventCount);
         try {
-            int rateUs = SensorCtsHelper.getDelay(mSensor, mRateUs);
+            int rateUs = mEnvironment.getExpectedSamplingPeriodUs();
             // Timeout is 2 * event count * expected period + batch timeout + default wait
             long timeoutUs = ((2 * eventCount * rateUs)
-                    + mMaxBatchReportLatencyUs + EVENT_TIMEOUT_US);
+                    + mEnvironment.getMaxReportLatencyUs()
+                    + EVENT_TIMEOUT_US);
 
-            String message = SensorCtsHelper.formatAssertionMessage(mSensor, "WaitForEvents",
-                    mRateUs, mMaxBatchReportLatencyUs, "count:%d, available:%d", eventCount,
-                    mEventLatch.getCount());
+            String message = SensorCtsHelper.formatAssertionMessage(
+                    "WaitForEvents",
+                    mEnvironment,
+                    "count:%d, available:%d",
+                    eventCount, mEventLatch.getCount());
             Assert.assertTrue(message, mEventLatch.await(timeoutUs, TimeUnit.MICROSECONDS));
         } catch(InterruptedException e) {
             // Ignore
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorManager.java b/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorManager.java
index 1c1ea1c..a62107b 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorManager.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorManager.java
@@ -53,21 +53,29 @@
     private static final String LOG_TAG = "TestSensorManager";
 
     private final SensorManager mSensorManager;
-    private final Sensor mSensor;
-    private final int mRateUs;
-    private final int mMaxBatchReportLatencyUs;
+    private final TestSensorEnvironment mEnvironment;
 
-    private TestSensorEventListener mTestSensorEventListener = null;
+    private TestSensorEventListener mTestSensorEventListener;
+
+    /**
+     * @Deprecated Use {@link #TestSensorManager(TestSensorEnvironment)} instead.
+     */
+    @Deprecated
+    public TestSensorManager(
+            Context context,
+            int sensorType,
+            int rateUs,
+            int maxBatchReportLatencyUs) {
+        this(new TestSensorEnvironment(context, sensorType, rateUs, maxBatchReportLatencyUs));
+    }
 
     /**
      * Construct a {@link TestSensorManager}.
      */
-    public TestSensorManager(Context context, int sensorType, int rateUs,
-            int maxBatchReportLatencyUs) {
-        mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
-        mSensor = SensorCtsHelper.getSensor(context, sensorType);
-        mRateUs = rateUs;
-        mMaxBatchReportLatencyUs = maxBatchReportLatencyUs;
+    public TestSensorManager(TestSensorEnvironment environment) {
+        mSensorManager =
+                (SensorManager) environment.getContext().getSystemService(Context.SENSOR_SERVICE);
+        mEnvironment = environment;
     }
 
     /**
@@ -83,12 +91,14 @@
         }
 
         mTestSensorEventListener = listener != null ? listener : new TestSensorEventListener();
-        mTestSensorEventListener.setSensorInfo(mSensor, mRateUs, mMaxBatchReportLatencyUs);
+        mTestSensorEventListener.setEnvironment(mEnvironment);
 
-        String message = SensorCtsHelper.formatAssertionMessage(mSensor, "registerListener",
-                mRateUs, mMaxBatchReportLatencyUs);
-        boolean result = mSensorManager.registerListener(mTestSensorEventListener, mSensor, mRateUs,
-                mMaxBatchReportLatencyUs);
+        String message = SensorCtsHelper.formatAssertionMessage("registerListener", mEnvironment);
+        boolean result = mSensorManager.registerListener(
+                mTestSensorEventListener,
+                mEnvironment.getSensor(),
+                mEnvironment.getRequestedSamplingPeriodUs(),
+                mEnvironment.getMaxReportLatencyUs());
         Assert.assertTrue(message, result);
     }
 
@@ -101,7 +111,9 @@
             return;
         }
 
-        mSensorManager.unregisterListener(mTestSensorEventListener, mSensor);
+        mSensorManager.unregisterListener(
+                mTestSensorEventListener,
+                mEnvironment.getSensor());
         mTestSensorEventListener = null;
     }
 
@@ -140,9 +152,9 @@
             return;
         }
 
-        String message = SensorCtsHelper.formatAssertionMessage(mSensor, "Flush", mRateUs,
-                mMaxBatchReportLatencyUs);
-        Assert.assertTrue(message, mSensorManager.flush(mTestSensorEventListener));
+        Assert.assertTrue(
+                SensorCtsHelper.formatAssertionMessage("Flush", mEnvironment),
+                mSensorManager.flush(mTestSensorEventListener));
     }
 
     /**
@@ -234,11 +246,4 @@
             unregisterListener();
         }
     }
-
-    /**
-     * Get the sensor under test.
-     */
-    public Sensor getSensor() {
-        return mSensor;
-    }
 }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorFlushOperation.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorFlushOperation.java
index 135d674..1fb6bef 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorFlushOperation.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorFlushOperation.java
@@ -16,7 +16,7 @@
 
 package android.hardware.cts.helpers.sensoroperations;
 
-import android.content.Context;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEventListener;
 
 import java.util.concurrent.TimeUnit;
@@ -36,21 +36,15 @@
     /**
      * Create a {@link TestSensorOperation}.
      *
-     * @param context the {@link Context}.
-     * @param sensorType the sensor type
-     * @param rateUs the rate that
-     * @param maxBatchReportLatencyUs the max batch report latency
+     * @param environment the test environment
      * @param duration the duration to gather events before calling {@code SensorManager.flush()}
      * @param timeUnit the time unit of the duration
      */
     public TestSensorFlushOperation(
-            Context context,
-            int sensorType,
-            int rateUs,
-            int maxBatchReportLatencyUs,
+            TestSensorEnvironment environment,
             long duration,
             TimeUnit timeUnit) {
-        super(context, sensorType, rateUs, maxBatchReportLatencyUs);
+        super(environment);
         mDuration = duration;
         mTimeUnit = timeUnit;
     }
@@ -68,12 +62,6 @@
      */
     @Override
     protected VerifiableSensorOperation doClone() {
-        return new TestSensorFlushOperation(
-                mContext,
-                mSensorType,
-                mRateUs,
-                mMaxBatchReportLatencyUs,
-                mDuration,
-                mTimeUnit);
+        return new TestSensorFlushOperation(mEnvironment, mDuration,mTimeUnit);
     }
 }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java
index 5982d24..6c3851e 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java
@@ -16,7 +16,7 @@
 
 package android.hardware.cts.helpers.sensoroperations;
 
-import android.content.Context;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEventListener;
 
 import java.util.concurrent.TimeUnit;
@@ -37,38 +37,36 @@
     /**
      * Create a {@link TestSensorOperation}.
      *
-     * @param context the {@link Context}.
-     * @param sensorType the sensor type
-     * @param rateUs the rate that
-     * @param maxBatchReportLatencyUs the max batch report latency
+     * @param environment the test environment
      * @param eventCount the number of events to gather
      */
-    public TestSensorOperation(Context context, int sensorType, int rateUs,
-            int maxBatchReportLatencyUs, int eventCount) {
-        this(context, sensorType, rateUs, maxBatchReportLatencyUs, eventCount, null, null);
+    public TestSensorOperation(TestSensorEnvironment environment, int eventCount) {
+        this(environment, eventCount, null /* duration */, null /* timeUnit */);
     }
 
     /**
      * Create a {@link TestSensorOperation}.
      *
-     * @param context the {@link Context}.
-     * @param sensorType the sensor type
-     * @param rateUs the rate that
-     * @param maxBatchReportLatencyUs the max batch report latency
+     * @param environment the test environment
      * @param duration the duration to gather events for
      * @param timeUnit the time unit of the duration
      */
-    public TestSensorOperation(Context context, int sensorType, int rateUs,
-            int maxBatchReportLatencyUs, long duration, TimeUnit timeUnit) {
-        this(context, sensorType, rateUs, maxBatchReportLatencyUs, null, duration, timeUnit);
+    public TestSensorOperation(
+            TestSensorEnvironment environment,
+            long duration,
+            TimeUnit timeUnit) {
+        this(environment, null /* eventCount */, duration, timeUnit);
     }
 
     /**
      * Private helper constructor.
      */
-    private TestSensorOperation(Context context, int sensorType, int rateUs,
-            int maxBatchReportLatencyUs, Integer eventCount, Long duration, TimeUnit timeUnit) {
-        super(context, sensorType, rateUs, maxBatchReportLatencyUs);
+    private TestSensorOperation(
+            TestSensorEnvironment environment,
+            Integer eventCount,
+            Long duration,
+            TimeUnit timeUnit) {
+        super(environment);
         mEventCount = eventCount;
         mDuration = duration;
         mTimeUnit = timeUnit;
@@ -92,11 +90,9 @@
     @Override
     protected VerifiableSensorOperation doClone() {
         if (mEventCount != null) {
-            return new TestSensorOperation(mContext, mSensorType, mRateUs,
-                    mMaxBatchReportLatencyUs, mEventCount);
+            return new TestSensorOperation(mEnvironment, mEventCount);
         } else {
-            return new TestSensorOperation(mContext, mSensorType, mRateUs,
-                    mMaxBatchReportLatencyUs, mDuration, mTimeUnit);
+            return new TestSensorOperation(mEnvironment, mDuration, mTimeUnit);
         }
     }
 }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/VerifiableSensorOperation.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/VerifiableSensorOperation.java
index d0a5673..55a880ae 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/VerifiableSensorOperation.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensoroperations/VerifiableSensorOperation.java
@@ -18,11 +18,10 @@
 
 import junit.framework.Assert;
 
-import android.content.Context;
-import android.hardware.Sensor;
 import android.hardware.cts.helpers.SensorCtsHelper;
 import android.hardware.cts.helpers.SensorStats;
 import android.hardware.cts.helpers.SensorTestInformation;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEventListener;
 import android.hardware.cts.helpers.TestSensorManager;
 import android.hardware.cts.helpers.ValidatingSensorEventListener;
@@ -48,10 +47,7 @@
  */
 public abstract class VerifiableSensorOperation extends AbstractSensorOperation {
     protected final TestSensorManager mSensorManager;
-    protected final Context mContext;
-    protected final int mSensorType;
-    protected final int mRateUs;
-    protected final int mMaxBatchReportLatencyUs;
+    protected final TestSensorEnvironment mEnvironment;
 
     private final Collection<ISensorVerification> mVerifications =
             new HashSet<ISensorVerification>();
@@ -61,22 +57,11 @@
     /**
      * Create a {@link TestSensorOperation}.
      *
-     * @param context the {@link Context}.
-     * @param sensorType the sensor type
-     * @param rateUs the rate that
-     * @param maxBatchReportLatencyUs the max batch report latency
+     * @param environment the test environment
      */
-    public VerifiableSensorOperation(
-            Context context,
-            int sensorType,
-            int rateUs,
-            int maxBatchReportLatencyUs) {
-        mContext = context;
-        mSensorType = sensorType;
-        mRateUs = rateUs;
-        mMaxBatchReportLatencyUs = maxBatchReportLatencyUs;
-        mSensorManager = new TestSensorManager(mContext, mSensorType, mRateUs,
-                mMaxBatchReportLatencyUs);
+    public VerifiableSensorOperation(TestSensorEnvironment environment) {
+        mEnvironment = environment;
+        mSensorManager = new TestSensorManager(mEnvironment);
     }
 
     /**
@@ -90,15 +75,14 @@
      * Set all of the default test expectations.
      */
     public void addDefaultVerifications() {
-        Sensor sensor = mSensorManager.getSensor();
-        addVerification(EventGapVerification.getDefault(sensor, mRateUs));
-        addVerification(EventOrderingVerification.getDefault(sensor));
-        addVerification(FrequencyVerification.getDefault(sensor, mRateUs));
-        addVerification(JitterVerification.getDefault(sensor, mRateUs));
-        addVerification(MagnitudeVerification.getDefault(sensor));
-        addVerification(MeanVerification.getDefault(sensor));
+        addVerification(EventGapVerification.getDefault(mEnvironment));
+        addVerification(EventOrderingVerification.getDefault(mEnvironment));
+        addVerification(FrequencyVerification.getDefault(mEnvironment));
+        addVerification(JitterVerification.getDefault(mEnvironment));
+        addVerification(MagnitudeVerification.getDefault(mEnvironment));
+        addVerification(MeanVerification.getDefault(mEnvironment));
         // Skip SigNumVerification since it has no default
-        addVerification(StandardDeviationVerification.getDefault(sensor));
+        addVerification(StandardDeviationVerification.getDefault(mEnvironment));
     }
 
     public void addVerification(ISensorVerification verification) {
@@ -112,7 +96,9 @@
      */
     @Override
     public void execute() {
-        getStats().addValue("sensor_name", SensorTestInformation.getSensorName(mSensorType));
+        getStats().addValue(
+                "sensor_name",
+                SensorTestInformation.getSensorName(mEnvironment.getSensor()));
 
         ValidatingSensorEventListener listener = new ValidatingSensorEventListener(mVerifications);
         listener.setLogEvents(mLogEvents);
@@ -126,8 +112,8 @@
         }
 
         if (failed) {
-            String msg = SensorCtsHelper.formatAssertionMessage(mSensorManager.getSensor(),
-                    "VerifySensorOperation", mRateUs, mMaxBatchReportLatencyUs, sb.toString());
+            String msg = SensorCtsHelper
+                    .formatAssertionMessage("VerifySensorOperation", mEnvironment, sb.toString());
             getStats().addValue(SensorStats.ERROR, msg);
             Assert.fail(msg);
         }
@@ -160,7 +146,7 @@
      */
     private boolean evaluateResults(ISensorVerification verification, StringBuilder sb) {
         try {
-            verification.verify(getStats());
+            verification.verify(mEnvironment, getStats());
         } catch (AssertionError e) {
             if (sb.length() > 0) {
                 sb.append(", ");
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/AbstractMeanVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/AbstractMeanVerification.java
index 8d132a3..b755304 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/AbstractMeanVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/AbstractMeanVerification.java
@@ -16,10 +16,10 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
-import android.hardware.cts.helpers.TestSensorEvent;
-
 import junit.framework.Assert;
 
+import android.hardware.cts.helpers.TestSensorEvent;
+
 /**
  * Abstract class that calculates of the mean event values.
  */
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventGapVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventGapVerification.java
index 251ef3c..962e5ad 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventGapVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventGapVerification.java
@@ -1,14 +1,12 @@
 package android.hardware.cts.helpers.sensorverification;
 
-import android.hardware.Sensor;
-import android.hardware.cts.helpers.SensorCtsHelper;
-import android.hardware.cts.helpers.SensorStats;
-import android.hardware.cts.helpers.SensorTestInformation;
-import android.hardware.cts.helpers.SensorTestInformation.SensorReportingMode;
-import android.hardware.cts.helpers.TestSensorEvent;
-
 import junit.framework.Assert;
 
+import android.hardware.Sensor;
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+
 import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
@@ -45,23 +43,27 @@
     /**
      * Get the default {@link EventGapVerification}.
      *
-     * @param sensor the {@link Sensor}
-     * @param rateUs the requested rate in us
+     * @param environment the test environment
      * @return the verification or null if the verification is not a continuous mode sensor.
      */
-    public static EventGapVerification getDefault(Sensor sensor, int rateUs) {
-        if (!SensorReportingMode.CONTINUOUS.equals(SensorTestInformation.getReportingMode(
-                sensor.getType()))) {
+    public static EventGapVerification getDefault(TestSensorEnvironment environment) {
+        if (environment.getSensor().getReportingMode() != Sensor.REPORTING_MODE_CONTINUOUS) {
             return null;
         }
-        return new EventGapVerification(SensorCtsHelper.getDelay(sensor, rateUs));
+        return new EventGapVerification(environment.getExpectedSamplingPeriodUs());
     }
 
     /**
      * {@inheritDoc}
      */
     @Override
-    public void verify(SensorStats stats) {
+    public void verify(TestSensorEnvironment environment, SensorStats stats) {
+        if (environment.isSensorSamplingRateOverloaded()) {
+            // the verification is not reliable on environments under load
+            stats.addValue(PASSED_KEY, true);
+            return;
+        }
+
         final int count = mEventGaps.size();
         stats.addValue(PASSED_KEY, count == 0);
         stats.addValue(SensorStats.EVENT_GAP_COUNT_KEY, count);
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventGapVerificationTest.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventGapVerificationTest.java
index b7861b2..d01e108 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventGapVerificationTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventGapVerificationTest.java
@@ -16,11 +16,12 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
-import android.hardware.cts.helpers.SensorStats;
-import android.hardware.cts.helpers.TestSensorEvent;
-
 import junit.framework.TestCase;
 
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+
 /**
  * Tests for {@link EventGapVerification}.
  */
@@ -65,12 +66,13 @@
             int[] indices) {
         SensorStats stats = new SensorStats();
         ISensorVerification verification = getVerification(expected, timestamps);
+        TestSensorEnvironment environment = new TestSensorEnvironment(null, null, false, 0, 0);
         if (pass) {
-            verification.verify(stats);
+            verification.verify(environment, stats);
         } else {
             boolean failed = false;
             try {
-                verification.verify(stats);
+                verification.verify(environment, stats);
             } catch (AssertionError e) {
                 // Expected;
                 failed = true;
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerification.java
index c74c826..6598725 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerification.java
@@ -16,14 +16,13 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
+import junit.framework.Assert;
+
 import android.hardware.Sensor;
 import android.hardware.cts.helpers.SensorStats;
-import android.hardware.cts.helpers.SensorTestInformation;
-import android.hardware.cts.helpers.SensorTestInformation.SensorReportingMode;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEvent;
 
-import junit.framework.Assert;
-
 import java.util.LinkedList;
 import java.util.List;
 
@@ -44,14 +43,14 @@
     /**
      * Get the default {@link EventOrderingVerification} for a sensor.
      *
-     * @param sensor a {@link Sensor}
+     * @param environment the test environment
      * @return the verification or null if the verification does not apply to the sensor.
      */
     @SuppressWarnings("deprecation")
-    public static EventOrderingVerification getDefault(Sensor sensor) {
-        SensorReportingMode mode = SensorTestInformation.getReportingMode(sensor.getType());
-        if (!SensorReportingMode.CONTINUOUS.equals(mode)
-                && !SensorReportingMode.ON_CHANGE.equals(mode)) {
+    public static EventOrderingVerification getDefault(TestSensorEnvironment environment) {
+        int reportingMode = environment.getSensor().getReportingMode();
+        if (reportingMode != Sensor.REPORTING_MODE_CONTINUOUS
+                && reportingMode != Sensor.REPORTING_MODE_ON_CHANGE) {
             return null;
         }
         return new EventOrderingVerification();
@@ -65,7 +64,14 @@
      * @throws AssertionError if the verification failed.
      */
     @Override
-    public void verify(SensorStats stats) {
+    public void verify(TestSensorEnvironment environment, SensorStats stats) {
+        verify(stats);
+    }
+
+    /**
+     * Visible for unit tests only.
+     */
+    void verify(SensorStats stats) {
         final int count = mOutOfOrderEvents.size();
         stats.addValue(PASSED_KEY, count == 0);
         stats.addValue(SensorStats.EVENT_OUT_OF_ORDER_COUNT_KEY, count);
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerificationTest.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerificationTest.java
index 28cbd01..88d5c19 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerificationTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerificationTest.java
@@ -16,11 +16,11 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
+import junit.framework.TestCase;
+
 import android.hardware.cts.helpers.SensorStats;
 import android.hardware.cts.helpers.TestSensorEvent;
 
-import junit.framework.TestCase;
-
 import java.util.ArrayList;
 import java.util.List;
 
@@ -34,7 +34,7 @@
      */
     public void testNoEvents() {
         SensorStats stats = new SensorStats();
-        ISensorVerification verification = getVerification();
+        EventOrderingVerification verification = getVerification();
         verification.verify(stats);
         verifyStats(stats, true, 0);
     }
@@ -44,7 +44,7 @@
      */
     public void testSameTimestamp() {
         SensorStats stats = new SensorStats();
-        ISensorVerification verification = getVerification(0, 0, 0, 0, 0);
+        EventOrderingVerification verification = getVerification(0, 0, 0, 0, 0);
         verification.verify(stats);
         verifyStats(stats, true, 0);
     }
@@ -54,7 +54,7 @@
      */
     public void testSequentialTimestamp() {
         SensorStats stats = new SensorStats();
-        ISensorVerification verification = getVerification(0, 1, 2, 3, 4);
+        EventOrderingVerification verification = getVerification(0, 1, 2, 3, 4);
         verification.verify(stats);
         verifyStats(stats, true, 0);
     }
@@ -64,7 +64,7 @@
      */
     public void testSingleOutofOrder() {
         SensorStats stats = new SensorStats();
-        ISensorVerification verification = getVerification(0, 2, 1, 3, 4);
+        EventOrderingVerification verification = getVerification(0, 2, 1, 3, 4);
         try {
             verification.verify(stats);
             fail("Expected an AssertionError");
@@ -81,7 +81,7 @@
      */
     public void testMultipleOutOfOrder() {
         SensorStats stats = new SensorStats();
-        ISensorVerification verification = getVerification(4, 0, 1, 2, 3);
+        EventOrderingVerification verification = getVerification(4, 0, 1, 2, 3);
         try {
             verification.verify(stats);
             fail("Expected an AssertionError");
@@ -96,8 +96,8 @@
         assertTrue(indices.contains(4));
     }
 
-    private ISensorVerification getVerification(long ... timestamps) {
-        ISensorVerification verification = new EventOrderingVerification();
+    private EventOrderingVerification getVerification(long ... timestamps) {
+        EventOrderingVerification verification = new EventOrderingVerification();
         for (long timestamp : timestamps) {
             verification.addSensorEvent(new TestSensorEvent(null, timestamp, 0, null));
         }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/FrequencyVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/FrequencyVerification.java
index b6704b6..cf34f28 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/FrequencyVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/FrequencyVerification.java
@@ -16,16 +16,15 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
+import junit.framework.Assert;
+
 import android.hardware.Sensor;
 import android.hardware.cts.helpers.SensorCtsHelper;
 import android.hardware.cts.helpers.SensorStats;
-import android.hardware.cts.helpers.SensorTestInformation;
-import android.hardware.cts.helpers.SensorTestInformation.SensorReportingMode;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEvent;
 import android.util.Log;
 
-import junit.framework.Assert;
-
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -41,10 +40,8 @@
     // Highest acceptable frequency, as percentage of the requested one.
     private static final int DEFAULT_UPPER_THRESHOLD = 220;
 
-    private final double mRequestedFrequencyHz;
     private final double mLowerThresholdHz;
     private final double mUpperThresholdHz;
-    private final String mSensorName;
 
     private long mMinTimestamp = 0;
     private long mMaxTimestamp = 0;
@@ -53,34 +50,31 @@
     /**
      * Construct a {@link FrequencyVerification}.
      *
-     * @param expected the expected frequency in Hz.
      * @param lowerTheshold Lowest acceptable frequency Hz.
      * @param upperThreshold Highest acceptable frequency Hz.
      */
-    public FrequencyVerification(double expected, double lowerTheshold, double upperThreshold,
-        String sensorName) {
-        mRequestedFrequencyHz = expected;
+    public FrequencyVerification(double lowerTheshold, double upperThreshold) {
         mLowerThresholdHz = lowerTheshold;
         mUpperThresholdHz = upperThreshold;
-        mSensorName = sensorName;
     }
 
     /**
      * Get the default {@link FrequencyVerification} for a sensor.
      *
-     * @param sensor a {@link Sensor}
-     * @param rateUs the desired rate of the sensor
+     * @param environment the test environment
      * @return the verification or null if the verification does not apply to the sensor.
      */
-    public static FrequencyVerification getDefault(Sensor sensor, int rateUs) {
-        if (!SensorReportingMode.CONTINUOUS.equals(
-                SensorTestInformation.getReportingMode(sensor.getType()))) {
+    public static FrequencyVerification getDefault(TestSensorEnvironment environment) {
+        Sensor sensor = environment.getSensor();
+        if (sensor.getReportingMode() != Sensor.REPORTING_MODE_CONTINUOUS) {
             return null;
         }
 
-        Log.i(LOG_TAG, String.format("Preparing frequency test for \"%s\" for which "
-                + "minDelay=%dus and maxDelay=%dus",
-                sensor.getName(), sensor.getMinDelay(), sensor.getMaxDelay()));
+        Log.i(LOG_TAG, String.format(
+                "Preparing frequency test for \"%s\" for which minDelay=%dus and maxDelay=%dus",
+                sensor.getName(),
+                sensor.getMinDelay(),
+                sensor.getMaxDelay()));
         double maxDelayUs = sensor.getMaxDelay();
         if (maxDelayUs <= 0) {
             // This sensor didn't report its maxDelay.
@@ -92,10 +86,12 @@
             maxDelayUs = sensor.getMinDelay();
         }
 
+        if (environment.isSensorSamplingRateOverloaded()) {
+            maxDelayUs = sensor.getMinDelay();
+        }
+
         // Convert the rateUs parameter into a delay in microseconds and rate in Hz.
-        double delayUs = SensorCtsHelper.getDelay(sensor, rateUs);
-        double requestedFrequencyHz = SensorCtsHelper.getFrequency(
-            delayUs, TimeUnit.MICROSECONDS);
+        double delayUs = environment.getRequestedSamplingPeriodUs();
 
         // When rateUs > maxDelay, the sensor can do as if we requested maxDelay.
         double upperExpectedHz = SensorCtsHelper.getFrequency(
@@ -108,8 +104,7 @@
         double lowerThresholdHz = lowerExpectedHz * DEFAULT_LOWER_THRESHOLD / 100;
         double upperThresholdHz = upperExpectedHz * DEFAULT_UPPER_THRESHOLD / 100;
 
-        return new FrequencyVerification(requestedFrequencyHz, lowerThresholdHz, upperThresholdHz,
-            sensor.getName());
+        return new FrequencyVerification(lowerThresholdHz, upperThresholdHz);
     }
 
     /**
@@ -119,7 +114,7 @@
      * @throws AssertionError if the verification failed.
      */
     @Override
-    public void verify(SensorStats stats) {
+    public void verify(TestSensorEnvironment environment, SensorStats stats) {
         if (mCount < 2) {
             stats.addValue(PASSED_KEY, true);
             return;
@@ -132,9 +127,13 @@
 
         stats.addValue(SensorStats.FREQUENCY_KEY, measuredFrequencyHz);
         stats.addValue(PASSED_KEY, !failed);
-        String resultString = String.format("Requested \"" + mSensorName + "\" at %.2fHz "
-                + "(expecting between %.2fHz and %.2fHz, measured %.2fHz)",
-                mRequestedFrequencyHz, mLowerThresholdHz, mUpperThresholdHz, measuredFrequencyHz);
+        String resultString = String.format(
+                "Requested \"%s\" at %.2fHz (expecting between %.2fHz and %.2fHz, measured %.2fHz)",
+                environment.getSensor().getName(),
+                environment.getFrequencyHz(),
+                mLowerThresholdHz,
+                mUpperThresholdHz,
+                measuredFrequencyHz);
 
         if (failed) {
             Log.e(LOG_TAG, "Frequency test FAIL: " + resultString);
@@ -149,8 +148,7 @@
      */
     @Override
     public FrequencyVerification clone() {
-        return new FrequencyVerification(mRequestedFrequencyHz, mLowerThresholdHz,
-            mUpperThresholdHz, mSensorName);
+        return new FrequencyVerification(mLowerThresholdHz, mUpperThresholdHz);
     }
 
     /**
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/FrequencyVerificationTest.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/FrequencyVerificationTest.java
index 82d93e5..24349ce 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/FrequencyVerificationTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/FrequencyVerificationTest.java
@@ -16,15 +16,16 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
+import android.hardware.Sensor;
+import android.hardware.cts.SensorTestCase;
 import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEvent;
 
-import junit.framework.TestCase;
-
 /**
  * Tests for {@link EventOrderingVerification}.
  */
-public class FrequencyVerificationTest extends TestCase {
+public class FrequencyVerificationTest extends SensorTestCase {
 
     /**
      * Test that the verifications passes/fails based on threshold given.
@@ -33,24 +34,24 @@
         long[] timestamps = {0, 1000000, 2000000, 3000000, 4000000};  // 1000Hz
 
         SensorStats stats = new SensorStats();
-        ISensorVerification verification = getVerification(1000.0, 999.0, 1001.0, timestamps);
-        verification.verify(stats);
+        ISensorVerification verification = getVerification(999.0, 1001.0, timestamps);
+        verification.verify(getEnvironment(1000), stats);
         verifyStats(stats, true, 1000.0);
 
         stats = new SensorStats();
-        verification = getVerification(950.0, 850.0, 1050.0, timestamps);
-        verification.verify(stats);
+        verification = getVerification(850.0, 1050.0, timestamps);
+        verification.verify(getEnvironment(950), stats);
         verifyStats(stats, true, 1000.0);
 
         stats = new SensorStats();
-        verification = getVerification(1050.0, 950.0, 1150.0, timestamps);
-        verification.verify(stats);
+        verification = getVerification(950.0, 1150.0, timestamps);
+        verification.verify(getEnvironment(1050), stats);
         verifyStats(stats, true, 1000.0);
 
         stats = new SensorStats();
-        verification = getVerification(950.0, 850.0, 975.0, timestamps);
+        verification = getVerification(850.0, 975.0, timestamps);
         try {
-            verification.verify(stats);
+            verification.verify(getEnvironment(950), stats);
             fail("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
@@ -58,9 +59,9 @@
         verifyStats(stats, false, 1000.0);
 
         stats = new SensorStats();
-        verification = getVerification(1050.0, 1025.0, 1150.0, timestamps);
+        verification = getVerification(1025.0, 1150.0, timestamps);
         try {
-            verification.verify(stats);
+            verification.verify(getEnvironment(1050), stats);
             fail("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
@@ -68,10 +69,16 @@
         verifyStats(stats, false, 1000.0);
     }
 
-    private ISensorVerification getVerification(double expected, double lowerThreshold,
-            double upperThreshold, long ... timestamps) {
-        ISensorVerification verification = new FrequencyVerification(expected, lowerThreshold,
-                upperThreshold, "Test sensor");
+    private TestSensorEnvironment getEnvironment(int rateUs) {
+        return new TestSensorEnvironment(getContext(), Sensor.TYPE_ALL, rateUs);
+    }
+
+    private ISensorVerification getVerification(
+            double lowerThreshold,
+            double upperThreshold,
+            long ... timestamps) {
+        ISensorVerification verification =
+                new FrequencyVerification(lowerThreshold, upperThreshold);
         for (long timestamp : timestamps) {
             verification.addSensorEvent(new TestSensorEvent(null, timestamp, 0, null));
         }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/ISensorVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/ISensorVerification.java
index 07af392..4f7b65a 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/ISensorVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/ISensorVerification.java
@@ -17,13 +17,15 @@
 package android.hardware.cts.helpers.sensorverification;
 
 import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEvent;
 
 /**
  * Interface describing the sensor verification. This class was designed for to handle streaming
  * events. The methods {@link #addSensorEvent(TestSensorEvent)} and
  * {@link #addSensorEvents(TestSensorEvent...)} should be called in the order that the events are
- * received. The method {@link #verify(SensorStats)} should be called after all events are added.
+ * received. The method {@link #verify(TestSensorEnvironment, SensorStats)} should be called after
+ * all events are added.
  */
 public interface ISensorVerification {
 
@@ -43,7 +45,7 @@
      * @param stats a {@link SensorStats} object used to keep track of the stats.
      * @throws AssertionError if the verification fails.
      */
-    public void verify(SensorStats stats);
+    public void verify(TestSensorEnvironment environment, SensorStats stats);
 
     /**
      * Clones the {@link ISensorVerification}
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerification.java
index 6feceb8..97d2f5b 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerification.java
@@ -16,13 +16,14 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
+import junit.framework.Assert;
+
 import android.hardware.Sensor;
 import android.hardware.cts.helpers.SensorCtsHelper;
 import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEvent;
 
-import junit.framework.Assert;
-
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -62,18 +63,18 @@
     /**
      * Get the default {@link JitterVerification} for a sensor.
      *
-     * @param sensor a {@link Sensor}
-     * @param rateUs the desired rate of the sensor
+     * @param environment the test environment
      * @return the verification or null if the verification does not apply to the sensor.
      */
-    public static JitterVerification getDefault(Sensor sensor, int rateUs) {
-        if (!DEFAULTS.containsKey(sensor.getType())) {
+    public static JitterVerification getDefault(TestSensorEnvironment environment) {
+        int sensorType = environment.getSensor().getType();
+        if (!DEFAULTS.containsKey(sensorType)) {
             return null;
         }
 
-        int expected = (int) TimeUnit.NANOSECONDS.convert(SensorCtsHelper.getDelay(sensor, rateUs),
-                TimeUnit.MICROSECONDS);
-        return new JitterVerification(expected, DEFAULTS.get(sensor.getType()));
+        int expected = (int) TimeUnit.NANOSECONDS
+                .convert(environment.getExpectedSamplingPeriodUs(), TimeUnit.MICROSECONDS);
+        return new JitterVerification(expected, DEFAULTS.get(sensorType));
     }
 
     /**
@@ -84,8 +85,9 @@
      * @throws AssertionError if the verification failed.
      */
     @Override
-    public void verify(SensorStats stats) {
-        if (mTimestamps.size() < 2) {
+    public void verify(TestSensorEnvironment environment, SensorStats stats) {
+        if (mTimestamps.size() < 2 || environment.isSensorSamplingRateOverloaded()) {
+            // the verification is not reliable in environments under load
             stats.addValue(PASSED_KEY, true);
             return;
         }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerificationTest.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerificationTest.java
index a9e872a..26e3fa3 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerificationTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerificationTest.java
@@ -16,11 +16,12 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
-import android.hardware.cts.helpers.SensorStats;
-import android.hardware.cts.helpers.TestSensorEvent;
-
 import junit.framework.TestCase;
 
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+
 import java.util.List;
 
 /**
@@ -31,6 +32,14 @@
 
     public void testVerify() {
         final int SAMPLE_SIZE = 100;
+        // for unit testing the verification, only the parameter 'sensorMightHaveMoreListeners' is
+        // required
+        TestSensorEnvironment environment = new TestSensorEnvironment(
+                null /* context */,
+                null /* sensor */,
+                false /* sensorMightHaveMoreListeners */,
+                0 /*samplingPeriodUs */,
+                0 /* maxReportLatencyUs */);
 
         // 100 samples at 1000Hz
         long[] timestamps = new long[SAMPLE_SIZE];
@@ -39,7 +48,7 @@
         }
         SensorStats stats = new SensorStats();
         ISensorVerification verification = getVerification(1000, 1, timestamps);
-        verification.verify(stats);
+        verification.verify(environment, stats);
         verifyStats(stats, true, 0.0);
 
         // 90 samples at 1000Hz, 10 samples at 2000Hz
@@ -51,7 +60,7 @@
         stats = new SensorStats();
         verification = getVerification(1000, 1, timestamps);
         try {
-            verification.verify(stats);
+            verification.verify(environment, stats);
             fail("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerification.java
index 5e44273..2c90127 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerification.java
@@ -16,13 +16,14 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
+import junit.framework.Assert;
+
 import android.hardware.Sensor;
 import android.hardware.SensorManager;
 import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEvent;
 
-import junit.framework.Assert;
-
 import java.util.HashMap;
 import java.util.Map;
 
@@ -60,15 +61,16 @@
     /**
      * Get the default {@link MagnitudeVerification} for a sensor.
      *
-     * @param sensor a {@link Sensor}
+     * @param environment the test environment
      * @return the verification or null if the verification does not apply to the sensor.
      */
-    public static MagnitudeVerification getDefault(Sensor sensor) {
-        if (!DEFAULTS.containsKey(sensor.getType())) {
+    public static MagnitudeVerification getDefault(TestSensorEnvironment environment) {
+        int sensorType = environment.getSensor().getType();
+        if (!DEFAULTS.containsKey(sensorType)) {
             return null;
         }
-        Float expected = DEFAULTS.get(sensor.getType())[0];
-        Float threshold = DEFAULTS.get(sensor.getType())[1];
+        Float expected = DEFAULTS.get(sensorType)[0];
+        Float threshold = DEFAULTS.get(sensorType)[1];
         return new MagnitudeVerification(expected, threshold);
     }
 
@@ -79,7 +81,14 @@
      * @throws AssertionError if the verification failed.
      */
     @Override
-    public void verify(SensorStats stats) {
+    public void verify(TestSensorEnvironment environment, SensorStats stats) {
+        verify(stats);
+    }
+
+    /**
+     * Visible for unit tests only.
+     */
+    void verify(SensorStats stats) {
         if (mCount < 1) {
             stats.addValue(PASSED_KEY, true);
             return;
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerificationTest.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerificationTest.java
index 9a50753..bb29330 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerificationTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerificationTest.java
@@ -16,18 +16,19 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
-import android.hardware.cts.helpers.SensorStats;
-import android.hardware.cts.helpers.TestSensorEvent;
-
 import junit.framework.TestCase;
 
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+
 /**
  * Tests for {@link MagnitudeVerification}.
  */
 public class MagnitudeVerificationTest extends TestCase {
 
     /**
-     * Test {@link MagnitudeVerification#verify(SensorStats)}.
+     * Test {@link MagnitudeVerification#verify(TestSensorEnvironment, SensorStats)}.
      */
     public void testVerify() {
         float[][] values = {
@@ -47,7 +48,7 @@
 
     private void runStats(float expected, float threshold, float[][] values, boolean pass, float magnitude) {
         SensorStats stats = new SensorStats();
-        ISensorVerification verification = getVerification(expected, threshold, values);
+        MagnitudeVerification verification = getVerification(expected, threshold, values);
         if (pass) {
             verification.verify(stats);
         } else {
@@ -62,9 +63,9 @@
         assertEquals(magnitude, (Float) stats.getValue(SensorStats.MAGNITUDE_KEY), 0.01);
     }
 
-    private ISensorVerification getVerification(float expected, float threshold,
+    private MagnitudeVerification getVerification(float expected, float threshold,
             float[] ... values) {
-        ISensorVerification verification = new MagnitudeVerification(expected, threshold);
+        MagnitudeVerification verification = new MagnitudeVerification(expected, threshold);
         for (float[] value : values) {
             verification.addSensorEvent(new TestSensorEvent(null, 0, 0, value));
         }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java
index d6769d0..6603895 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java
@@ -16,11 +16,12 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
+import junit.framework.Assert;
+
 import android.hardware.Sensor;
 import android.hardware.SensorManager;
 import android.hardware.cts.helpers.SensorStats;
-
-import junit.framework.Assert;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -55,15 +56,16 @@
     /**
      * Get the default {@link MeanVerification} for a sensor.
      *
-     * @param sensor a {@link Sensor}
+     * @param environment the test environment
      * @return the verification or null if the verification does not apply to the sensor.
      */
-    public static MeanVerification getDefault(Sensor sensor) {
-        if (!DEFAULTS.containsKey(sensor.getType())) {
+    public static MeanVerification getDefault(TestSensorEnvironment environment) {
+        int sensorType = environment.getSensor().getType();
+        if (!DEFAULTS.containsKey(sensorType)) {
             return null;
         }
-        float[] expected = (float[]) DEFAULTS.get(sensor.getType())[0];
-        float[] threshold = (float[]) DEFAULTS.get(sensor.getType())[1];
+        float[] expected = (float[]) DEFAULTS.get(sensorType)[0];
+        float[] threshold = (float[]) DEFAULTS.get(sensorType)[1];
         return new MeanVerification(expected, threshold);
     }
 
@@ -74,7 +76,14 @@
      * @throws AssertionError if the verification failed.
      */
     @Override
-    public void verify(SensorStats stats) {
+    public void verify(TestSensorEnvironment environment, SensorStats stats) {
+        verify(stats);
+    }
+
+    /**
+     * Visible for unit tests only.
+     */
+    void verify(SensorStats stats) {
         if (getCount() < 1) {
             stats.addValue(PASSED_KEY, true);
             return;
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MeanVerificationTest.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MeanVerificationTest.java
index 94b6362..b07ea50 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MeanVerificationTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/MeanVerificationTest.java
@@ -16,18 +16,19 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
-import android.hardware.cts.helpers.SensorStats;
-import android.hardware.cts.helpers.TestSensorEvent;
-
 import junit.framework.TestCase;
 
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+
 /**
  * Tests for {@link MeanVerification}.
  */
 public class MeanVerificationTest extends TestCase {
 
     /**
-     * Test {@link MeanVerification#verify(SensorStats)}.
+     * Test {@link MeanVerification#verify(TestSensorEnvironment, SensorStats)}.
      */
     public void testVerify() {
         float[][] values = {
@@ -41,7 +42,7 @@
         float[] expected = {2.0f, 3.0f, 6.0f};
         float[] threshold = {0.1f, 0.1f, 0.1f};
         SensorStats stats = new SensorStats();
-        ISensorVerification verification = getVerification(expected, threshold, values);
+        MeanVerification verification = getVerification(expected, threshold, values);
         verification.verify(stats);
         verifyStats(stats, true, new float[]{2.0f, 3.0f, 6.0f});
 
@@ -76,7 +77,6 @@
         }
         verifyStats(stats, false, new float[]{2.0f, 3.0f, 6.0f});
 
-        threshold = new float[]{2.5f, 2.5f, 5.5f};
         threshold = new float[]{0.6f, 0.6f, 0.1f};
         stats = new SensorStats();
         verification = getVerification(expected, threshold, values);
@@ -89,9 +89,9 @@
         verifyStats(stats, false, new float[]{2.0f, 3.0f, 6.0f});
     }
 
-    private ISensorVerification getVerification(float[] expected, float[] threshold,
+    private MeanVerification getVerification(float[] expected, float[] threshold,
             float[] ... values) {
-        ISensorVerification verification = new MeanVerification(expected, threshold);
+        MeanVerification verification = new MeanVerification(expected, threshold);
         for (float[] value : values) {
             verification.addSensorEvent(new TestSensorEvent(null, 0, 0, value));
         }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/SigNumVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/SigNumVerification.java
index 9428d1d..94a4c96 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/SigNumVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/SigNumVerification.java
@@ -16,10 +16,11 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
-import android.hardware.cts.helpers.SensorStats;
-
 import junit.framework.Assert;
 
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+
 /**
  * A {@link ISensorVerification} which verifies that the sign of each of the sensor values is
  * correct.
@@ -60,7 +61,14 @@
      * @throws AssertionError if the verification failed.
      */
     @Override
-    public void verify(SensorStats stats) {
+    public void verify(TestSensorEnvironment environment, SensorStats stats) {
+        verify(stats);
+    }
+
+    /**
+     * Visible for unit tests only.
+     */
+    void verify(SensorStats stats) {
         if (getCount() < 1) {
             stats.addValue(PASSED_KEY, true);
             return;
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/SigNumVerificationTest.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/SigNumVerificationTest.java
index 009ab65..c8ce87e 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/SigNumVerificationTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/SigNumVerificationTest.java
@@ -16,18 +16,19 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
-import android.hardware.cts.helpers.SensorStats;
-import android.hardware.cts.helpers.TestSensorEvent;
-
 import junit.framework.TestCase;
 
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+
 /**
  * Tests for {@link SigNumVerification}.
  */
 public class SigNumVerificationTest extends TestCase {
 
     /**
-     * Test {@link SigNumVerification#verify(SensorStats)}.
+     * Test {@link SigNumVerification#verify(TestSensorEnvironment, SensorStats)}.
      */
     public void testVerify() {
         float[][] values = {{1.0f, 0.2f, 0.0f, -0.2f, -1.0f}};
@@ -65,7 +66,7 @@
     private void runVerification(boolean passed, int[] expected, float[] threshold,
             float[][] values) {
         SensorStats stats = new SensorStats();
-        ISensorVerification verification = getVerification(expected, threshold, values);
+        SigNumVerification verification = getVerification(expected, threshold, values);
         if (passed) {
             verification.verify(stats);
         } else {
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerification.java
index 57b34b0..f7c2c53 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerification.java
@@ -16,12 +16,13 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
+import junit.framework.Assert;
+
 import android.hardware.Sensor;
 import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEvent;
 
-import junit.framework.Assert;
-
 import java.util.HashMap;
 import java.util.Map;
 
@@ -57,15 +58,16 @@
     /**
      * Get the default {@link StandardDeviationVerification} for a sensor.
      *
-     * @param sensor a {@link Sensor}
+     * @param environment the test environment
      * @return the verification or null if the verification does not apply to the sensor.
      */
-    public static StandardDeviationVerification getDefault(Sensor sensor) {
-        if (!DEFAULTS.containsKey(sensor.getType())) {
+    public static StandardDeviationVerification getDefault(TestSensorEnvironment environment) {
+        int sensorType = environment.getSensor().getType();
+        if (!DEFAULTS.containsKey(sensorType)) {
             return null;
         }
 
-        return new StandardDeviationVerification(DEFAULTS.get(sensor.getType()));
+        return new StandardDeviationVerification(DEFAULTS.get(sensorType));
     }
 
     /**
@@ -75,7 +77,14 @@
      * @throws AssertionError if the verification failed.
      */
     @Override
-    public void verify(SensorStats stats) {
+    public void verify(TestSensorEnvironment environment, SensorStats stats) {
+        verify(stats);
+    }
+
+    /**
+     * Visible for unit tests only.
+     */
+    void verify(SensorStats stats) {
         if (mCount < 2) {
             stats.addValue(PASSED_KEY, true);
             return;
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerificationTest.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerificationTest.java
index 308f114..5d958f5 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerificationTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerificationTest.java
@@ -16,18 +16,19 @@
 
 package android.hardware.cts.helpers.sensorverification;
 
-import android.hardware.cts.helpers.SensorStats;
-import android.hardware.cts.helpers.TestSensorEvent;
-
 import junit.framework.TestCase;
 
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+
 /**
  * Tests for {@link StandardDeviationVerification}.
  */
 public class StandardDeviationVerificationTest extends TestCase {
 
     /**
-     * Test {@link StandardDeviationVerification#verify(SensorStats)}.
+     * Test {@link StandardDeviationVerification#verify(TestSensorEnvironment, SensorStats)}.
      */
     public void testVerify() {
         // Stddev should be {sqrt(2.5), sqrt(2.5), sqrt(2.5)}
@@ -58,7 +59,7 @@
     private void runVerification(float[] threshold, float[][] values, boolean pass,
             float[] standardDeviations) {
         SensorStats stats = new SensorStats();
-        ISensorVerification verification = getVerification(threshold, values);
+        StandardDeviationVerification verification = getVerification(threshold, values);
         if (pass) {
             verification.verify(stats);
         } else {
@@ -78,8 +79,8 @@
         }
     }
 
-    private ISensorVerification getVerification(float[] threshold, float[] ... values) {
-        ISensorVerification verification = new StandardDeviationVerification(threshold);
+    private StandardDeviationVerification getVerification(float[] threshold, float[] ... values) {
+        StandardDeviationVerification verification = new StandardDeviationVerification(threshold);
         for (float[] value : values) {
             verification.addSensorEvent(new TestSensorEvent(null, 0, 0, value));
         }