Fix bug in CarPropertyUtils.toCarPropertyValue which returns an Integer when an Integer[] is expected.

Bug: 110245496
Change-Id: Ib09593c4b03e65e60208e326e070220223e96550
Fixes: 110245496
Test: runtest -x packages/services/Car/tests/android_car_api_test
diff --git a/car-lib/src/android/car/CarInfoManager.java b/car-lib/src/android/car/CarInfoManager.java
index ffeaa93..d90883b 100644
--- a/car-lib/src/android/car/CarInfoManager.java
+++ b/car-lib/src/android/car/CarInfoManager.java
@@ -169,9 +169,7 @@
      *         types available.
      */
     public @FuelType.Enum int[] getFuelTypes() throws CarNotConnectedException {
-        CarPropertyValue<int[]> carProp = mCarPropertyMgr.getProperty(
-                int[].class, BASIC_INFO_FUEL_TYPES, 0);
-        return carProp != null ? carProp.getValue() : new int[0];
+        return mCarPropertyMgr.getIntArrayProperty(BASIC_INFO_FUEL_TYPES, 0);
     }
 
     /**
@@ -189,9 +187,7 @@
      *         no connector types available.
      */
     public @EvConnectorType.Enum int[] getEvConnectorTypes() throws CarNotConnectedException {
-        CarPropertyValue<int[]> carProp = mCarPropertyMgr.getProperty(int[].class,
-                BASIC_INFO_EV_CONNECTOR_TYPES, 0);
-        return carProp != null ? carProp.getValue() : new int[0];
+        return mCarPropertyMgr.getIntArrayProperty(BASIC_INFO_EV_CONNECTOR_TYPES, 0);
     }
 
     /** @hide */
diff --git a/car-lib/src/android/car/hardware/property/CarPropertyManager.java b/car-lib/src/android/car/hardware/property/CarPropertyManager.java
index dc23adf..ff8c4db 100644
--- a/car-lib/src/android/car/hardware/property/CarPropertyManager.java
+++ b/car-lib/src/android/car/hardware/property/CarPropertyManager.java
@@ -291,6 +291,26 @@
         return carProp != null ? carProp.getValue() : 0;
     }
 
+    /**
+     * Returns value of a integer array property
+     *
+     * @param prop Property ID to get
+     * @param area Zone of the property to get
+     */
+    public int[] getIntArrayProperty(int prop, int area) throws CarNotConnectedException {
+        CarPropertyValue<Integer[]> carProp = getProperty(Integer[].class, prop, area);
+        return carProp != null ? toIntArray(carProp.getValue()) : new int[0];
+    }
+
+    private static int[] toIntArray(Integer[] input) {
+        int len = input.length;
+        int[] arr = new int[len];
+        for (int i = 0; i < len; i++) {
+            arr[i] = input[i];
+        }
+        return arr;
+    }
+
     /** Return CarPropertyValue */
     @SuppressWarnings("unchecked")
     public <E> CarPropertyValue<E> getProperty(Class<E> clazz, int propId, int area)
diff --git a/service/src/com/android/car/hal/CarPropertyUtils.java b/service/src/com/android/car/hal/CarPropertyUtils.java
index 4b201f5..2d0e6ad 100644
--- a/service/src/com/android/car/hal/CarPropertyUtils.java
+++ b/service/src/com/android/car/hal/CarPropertyUtils.java
@@ -48,13 +48,35 @@
         long timestamp = halValue.timestamp;
         VehiclePropValue.RawValue v = halValue.value;
 
+        // Handles each return value from {@link getJavaClass}.
         if (Boolean.class == clazz) {
             return new CarPropertyValue<>(propertyId, areaId, status, timestamp,
                                           v.int32Values.get(0) == 1);
-        } else if (Boolean[].class == clazz) {
-            Boolean[] values = new Boolean[v.int32Values.size()];
+        } else if (Float.class == clazz) {
+            return new CarPropertyValue<>(propertyId, areaId, status, timestamp,
+                                          v.floatValues.get(0));
+        } else if (Integer.class == clazz) {
+            return new CarPropertyValue<>(propertyId, areaId, status, timestamp,
+                                          v.int32Values.get(0));
+        } else if (Long.class == clazz) {
+            return new CarPropertyValue<>(propertyId, areaId, status, timestamp,
+                                          v.int64Values.get(0));
+        } else if (Float[].class == clazz) {
+            Float[] values = new Float[v.floatValues.size()];
             for (int i = 0; i < values.length; i++) {
-                values[i] = v.int32Values.get(i) == 1;
+                values[i] = v.floatValues.get(i);
+            }
+            return new CarPropertyValue<>(propertyId, areaId, status, timestamp, values);
+        } else if (Integer[].class == clazz) {
+            Integer[] values = new Integer[v.int32Values.size()];
+            for (int i = 0; i < values.length; i++) {
+                values[i] = v.int32Values.get(i);
+            }
+            return new CarPropertyValue<>(propertyId, areaId, status, timestamp, values);
+        } else if (Long[].class == clazz) {
+            Long[] values = new Long[v.int64Values.size()];
+            for (int i = 0; i < values.length; i++) {
+                values[i] = v.int64Values.get(i);
             }
             return new CarPropertyValue<>(propertyId, areaId, status, timestamp, values);
         } else if (String.class == clazz) {
@@ -62,13 +84,7 @@
         } else if (byte[].class == clazz) {
             byte[] halData = toByteArray(v.bytes);
             return new CarPropertyValue<>(propertyId, areaId, status, timestamp, halData);
-        } else if (Long[].class == clazz) {
-            Long[] values = new Long[v.int64Values.size()];
-            for (int i = 0; i < values.length; i++) {
-                values[i] = v.int64Values.get(i);
-            }
-            return new CarPropertyValue<>(propertyId, areaId, status, timestamp, values);
-        } else /* All list properties */ {
+        } else /* Object.class */ {
             Object[] values = getRawValueList(clazz, v).toArray();
             return new CarPropertyValue<>(propertyId, areaId, status, timestamp,
                     values.length == 1 ? values[0] : values);