Add pressure sensor resolution test

Verifies that for a device with Hifi sensors, the pressure sensor's
resolution meets the CDD requirement.

Bug: 77811402
Test: SensorTest#testSensorOperations passes on reference device
Change-Id: I10d2012765a480f8ef006eb72df64fb4bb07210d
diff --git a/tests/sensor/src/android/hardware/cts/SensorTest.java b/tests/sensor/src/android/hardware/cts/SensorTest.java
index 4c70cd9..debf8ce 100644
--- a/tests/sensor/src/android/hardware/cts/SensorTest.java
+++ b/tests/sensor/src/android/hardware/cts/SensorTest.java
@@ -181,6 +181,17 @@
             assertNull(sensor);
         }
 
+        sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
+        boolean hasPressure = getContext().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_SENSOR_BAROMETER);
+        // pressure sensor is optional
+        if (hasPressure) {
+            assertEquals(Sensor.TYPE_PRESSURE, sensor.getType());
+            assertSensorValues(sensor);
+        } else {
+            assertNull(sensor);
+        }
+
         sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
         // Note: orientation sensor is deprecated.
         if (sensor != null) {
@@ -527,7 +538,9 @@
                 sensor.getName(), sensor.getPower() >= 0);
         assertTrue("Max resolution must be positive. Resolution=" + sensor.getResolution() +
                 " " + sensor.getName(), sensor.getResolution() >= 0);
-        if (SensorCtsHelper.hasResolutionRequirement(sensor)) {
+        boolean hasHifiSensors = getContext().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_HIFI_SENSORS);
+        if (SensorCtsHelper.hasResolutionRequirement(sensor, hasHifiSensors)) {
             float requiredResolution = SensorCtsHelper.getRequiredResolutionForSensor(sensor);
             assertTrue("Resolution must be <= " + requiredResolution + ". Resolution=" +
                     sensor.getResolution() + " " + sensor.getName(),
diff --git a/tests/sensor/src/android/hardware/cts/helpers/SensorCtsHelper.java b/tests/sensor/src/android/hardware/cts/helpers/SensorCtsHelper.java
index 5ad0c43..a4909c5 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/SensorCtsHelper.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/SensorCtsHelper.java
@@ -328,7 +328,7 @@
         return "";
     }
 
-    public static boolean hasResolutionRequirement(Sensor sensor) {
+    public static boolean hasResolutionRequirement(Sensor sensor, boolean hasHifiSensors) {
         switch (sensor.getType()) {
             case Sensor.TYPE_ACCELEROMETER:
             case Sensor.TYPE_ACCELEROMETER_UNCALIBRATED:
@@ -337,6 +337,10 @@
             case Sensor.TYPE_MAGNETIC_FIELD:
             case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
                 return true;
+
+            case Sensor.TYPE_PRESSURE:
+                // Pressure sensor only has a resolution requirement when there are HiFi sensors
+                return hasHifiSensors;
         }
         return false;
     }
@@ -359,6 +363,11 @@
                 // Magnetometer must have a resolution equal to or denser
                 // than 0.6 uT
                 return 0.6f;
+            case Sensor.TYPE_PRESSURE:
+                // Pressure sensor must have at least 80 LSB / hPa which is
+                // equivalent to 0.0125 hPa / LSB. Allow for a small margin of
+                // error due to rounding errors.
+                return 1.01f * (1.0f / 80.0f);
         }
         return 0.0f;
     }