Add CTS to verify Z axis of accelerometer in Car is pointing upward.

Adds check in mean verification to check the accelerometer reading is [0, 0, 9.8].
This verifies the Z axis points upward as per android automotive axis.
https://source.android.com/devices/sensors/sensor-types#auto_axes
X and Y axis directions are not verified.

Bug: 120840410

Change-Id: I10c30a46732ceb10fd3da1690f02ba8382bc41d9
Test: atest CtsSensorTests:SingleSensotTest
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java
index 17882d7..7a48ba8 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java
@@ -23,6 +23,7 @@
 import android.hardware.cts.helpers.SensorCtsHelper;
 import android.hardware.cts.helpers.SensorStats;
 import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.content.pm.PackageManager;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -65,13 +66,23 @@
      * @return the verification or null if the verification does not apply to the sensor.
      */
     public static MeanVerification getDefault(TestSensorEnvironment environment) {
+
+        Map<Integer, ExpectedValuesAndThresholds> currentDefaults =
+                new HashMap<Integer, ExpectedValuesAndThresholds>(DEFAULTS);
+
+        // For automotive flag, add car default tests.
+        if(environment.getContext().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_AUTOMOTIVE)) {
+            addCarDefaultTests(currentDefaults);
+        }
+
         int sensorType = environment.getSensor().getType();
-        if (!DEFAULTS.containsKey(sensorType)) {
+        if (!currentDefaults.containsKey(sensorType)) {
             return null;
         }
-        float[] expected = DEFAULTS.get(sensorType).mExpectedValues;
-        float[] upperThresholds = DEFAULTS.get(sensorType).mUpperThresholds;
-        float[] lowerThresholds = DEFAULTS.get(sensorType).mLowerThresholds;
+        float[] expected = currentDefaults.get(sensorType).mExpectedValues;
+        float[] upperThresholds = currentDefaults.get(sensorType).mUpperThresholds;
+        float[] lowerThresholds = currentDefaults.get(sensorType).mLowerThresholds;
         return new MeanVerification(expected, upperThresholds, lowerThresholds);
     }
 
@@ -186,6 +197,20 @@
                                                         Float.MAX_VALUE}));
     }
 
+    @SuppressWarnings("deprecation")
+    private static void addCarDefaultTests(Map<Integer, ExpectedValuesAndThresholds> defaults) {
+        // Sensors that are being tested for mean verification for the car.
+        // Accelerometer axes should be aligned to car axes: X right, Y forward, Z up.
+        // Refer for car axes: https://source.android.com/devices/sensors/sensor-types
+        // Verifying Z axis is Gravity, X and Y is zero as car is expected to be stationary.
+        // Tolerance set to 1.95 as used in CTS Verifier tests.
+        defaults.put(Sensor.TYPE_ACCELEROMETER,
+                new ExpectedValuesAndThresholds(
+                        new float[]{0.0f, 0.0f, SensorManager.STANDARD_GRAVITY},
+                        new float[]{1.95f, 1.95f, 1.95f} /* m / s^2 */,
+                        new float[]{1.95f, 1.95f, 1.95f} /* m / s^2 */));
+    }
+
     private static final class ExpectedValuesAndThresholds {
         private float[] mExpectedValues;
         private float[] mUpperThresholds;