diff options
author | Chao Yan <aceyansf@google.com> | 2018-06-11 16:15:20 -0700 |
---|---|---|
committer | Chao Yan <aceyansf@google.com> | 2018-06-11 16:25:26 -0700 |
commit | 66c39555e4132ab5e5c568c088645e95f955c9b7 (patch) | |
tree | 1cf534ef415a365124aa1b856a7ab0bddbfd57a3 /tests/vehiclehal_test | |
parent | 8f44868d536aac474d83e0af8e930e169301550c (diff) | |
download | Car-66c39555e4132ab5e5c568c088645e95f955c9b7.tar.gz |
Added End-to-End tests for car property API
Test: atest VehicleHALTest
Bug: 76017041
Change-Id: I61292bfa276fa131a08357136180855e9126fb0b
Diffstat (limited to 'tests/vehiclehal_test')
8 files changed, 267 insertions, 291 deletions
diff --git a/tests/vehiclehal_test/assets/car_info_test.json b/tests/vehiclehal_test/assets/car_info_test.json new file mode 100644 index 0000000000..90c9bdc557 --- /dev/null +++ b/tests/vehiclehal_test/assets/car_info_test.json @@ -0,0 +1,20 @@ +[ + { + "timestamp": 1526063903356950016, + "areaId": 0, + "value": 15000, + "prop": 291504388 + }, + { + "timestamp": 1526063903358950016, + "areaId": 0, + "value": 150000, + "prop": 291504390 + }, + { + "timestamp": 1526063903360950016, + "areaId": 0, + "value": "Test Car", + "prop": 286261505 + } +] diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/CarHvacTest.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/CarHvacTest.java deleted file mode 100644 index 08544bdb60..0000000000 --- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/CarHvacTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2018 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 com.android.car.vehiclehal.test; - -import static org.junit.Assert.assertTrue; - -import static java.lang.Integer.toHexString; - -import android.car.Car; -import android.car.hardware.CarPropertyConfig; -import android.car.hardware.CarPropertyValue; -import android.car.hardware.hvac.CarHvacManager; -import android.car.hardware.hvac.CarHvacManager.CarHvacEventCallback; -import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; -import android.hardware.automotive.vehicle.V2_0.VehicleProperty; -import android.support.test.filters.LargeTest; -import android.support.test.runner.AndroidJUnit4; -import android.util.ArraySet; -import android.util.Log; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.io.File; -import java.time.Duration; -import java.util.Set; - - -/** - * The test suite will execute end-to-end Car HVAC API test by generating HVAC property data from - * default VHAL and verify those data on the fly. The test data is coming from assets/ folder in the - * test APK and will be shared with VHAL to execute the test. - */ -@RunWith(AndroidJUnit4.class) -@LargeTest -public class CarHvacTest extends E2eCarTestBase { - private static final String TAG = Utils.concatTag(CarHvacTest.class); - - // Test should be completed within 1 hour as it only covers a finite set of HVAC properties - private static final Duration TEST_TIME_OUT = Duration.ofHours(1); - - private static final String CAR_HVAC_TEST_JSON = "car_hvac_test.json"; - - // Referred to hardware/interfaces/automotive/vehicle/2.0/types.hal, some of the HVAC properties - // are in CONTINUOUS mode. They should be omitted when testing ON_CHANGE properties. - private static final Set<Integer> CONTINUOUS_HVAC_PROPS; - - private Integer mNumPropEventsToSkip; - - static { - CONTINUOUS_HVAC_PROPS = new ArraySet<>(); - CONTINUOUS_HVAC_PROPS.add(VehicleProperty.ENV_OUTSIDE_TEMPERATURE); - } - - - private class CarHvacOnChangeEventListener implements CarHvacEventCallback { - private VhalEventVerifier mVerifier; - - CarHvacOnChangeEventListener(VhalEventVerifier verifier) { - mVerifier = verifier; - } - - @Override - public void onChangeEvent(CarPropertyValue carPropertyValue) { - VehiclePropValue event = Utils.fromHvacPropertyValue(carPropertyValue); - if (!CONTINUOUS_HVAC_PROPS.contains(event.prop)) { - synchronized (mNumPropEventsToSkip) { - if (mNumPropEventsToSkip == 0) { - mVerifier.verify(Utils.fromHvacPropertyValue(carPropertyValue)); - } else { - mNumPropEventsToSkip--; - } - } - } - } - - @Override - public void onErrorEvent(final int propertyId, final int zone) { - Assert.fail("Error: propertyId=" + toHexString(propertyId) + " zone=" + zone); - } - } - - private Integer calculateNumPropEventsToSkip(CarHvacManager hvacMgr) { - int numToSkip = 0; - try { - for (CarPropertyConfig c: hvacMgr.getPropertyList()) { - if (!CONTINUOUS_HVAC_PROPS.contains(c.getPropertyId())) { - numToSkip += c.getAreaCount(); - } - } - } catch (Exception e) { - Log.d(TAG, "Unhandled exception thrown: ", e); - } - return Integer.valueOf(numToSkip); - } - @Test - public void testHvacOperations() throws Exception { - Log.d(TAG, "Prepare HVAC test data"); - VhalEventVerifier verifier = new VhalEventVerifier(getExpectedEvents(CAR_HVAC_TEST_JSON)); - File sharedJson = makeShareable(CAR_HVAC_TEST_JSON); - - Log.d(TAG, "Start listening to the HAL"); - CarHvacManager hvacMgr = (CarHvacManager) mCar.getCarManager(Car.HVAC_SERVICE); - // Calculate number of properties to skip due to registration event - mNumPropEventsToSkip = calculateNumPropEventsToSkip(hvacMgr); - CarHvacEventCallback callback = new CarHvacOnChangeEventListener(verifier); - hvacMgr.registerCallback(callback); - - Log.d(TAG, "Send command to VHAL to start generation"); - VhalEventGenerator hvacGenerator = - new JsonVhalEventGenerator(mVehicle).setJsonFile(sharedJson); - hvacGenerator.start(); - - Log.d(TAG, "Receiving and verifying VHAL events"); - verifier.waitForEnd(TEST_TIME_OUT.toMillis()); - - Log.d(TAG, "Send command to VHAL to stop generation"); - hvacGenerator.stop(); - hvacMgr.unregisterCallback(callback); - - assertTrue("Detected mismatched events: " + verifier.getResultString(), - verifier.getMismatchedEvents().isEmpty()); - } -} diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/CarPropertyTest.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/CarPropertyTest.java new file mode 100644 index 0000000000..26f3c11310 --- /dev/null +++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/CarPropertyTest.java @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2018 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 com.android.car.vehiclehal.test; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import static java.lang.Integer.toHexString; + +import android.car.Car; +import android.car.CarNotConnectedException; +import android.car.hardware.CarPropertyConfig; +import android.car.hardware.CarPropertyValue; +import android.car.hardware.property.CarPropertyManager; +import android.support.test.filters.LargeTest; +import android.support.test.runner.AndroidJUnit4; +import android.util.ArraySet; +import android.util.Log; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.File; +import java.time.Duration; +import java.util.List; + +/** + * The test suite will execute end-to-end Car Property API test by generating VHAL property data + * from default VHAL and verify those data on the fly. The test data is coming from assets/ folder + * in the test APK and will be shared with VHAL to execute the test. + */ +@RunWith(AndroidJUnit4.class) +@LargeTest +public class CarPropertyTest extends E2eCarTestBase { + + private static final String TAG = Utils.concatTag(CarPropertyTest.class); + + // Test should be completed within 10 minutes as it only covers a finite set of properties + private static final Duration TEST_TIME_OUT = Duration.ofMinutes(10); + + private static final String CAR_HVAC_TEST_JSON = "car_hvac_test.json"; + private static final String CAR_INFO_TEST_JSON = "car_info_test.json"; + + private class CarPropertyEventReceiver implements + CarPropertyManager.CarPropertyEventListener { + + private VhalEventVerifier mVerifier; + private Integer mNumOfEventToSkip; + + CarPropertyEventReceiver(VhalEventVerifier verifier, int numOfEventToSkip) { + mVerifier = verifier; + mNumOfEventToSkip = numOfEventToSkip; + } + + @Override + public void onChangeEvent(CarPropertyValue carPropertyValue) { + Log.d(TAG, "Received event: " + carPropertyValue); + synchronized (mNumOfEventToSkip) { + if (mNumOfEventToSkip > 0) { + mNumOfEventToSkip--; + return; + } + } + mVerifier.verify(carPropertyValue); + } + + @Override + public void onErrorEvent(final int propertyId, final int zone) { + Assert.fail("Error: propertyId=" + toHexString(propertyId) + " zone=" + zone); + } + } + + private int countNumPropEventsToSkip(CarPropertyManager propMgr, ArraySet<Integer> props) { + int numToSkip = 0; + try { + for (CarPropertyConfig c : propMgr.getPropertyList(props)) { + numToSkip += c.getAreaCount(); + } + } catch (CarNotConnectedException e) { + fail("Car connection failure: " + e); + } + return numToSkip; + } + + /** + * This test will let Default VHAL to generate HVAC data and verify on-the-fly in the test. It + * is simulating the HVAC actions coming from hard buttons in a car. + * @throws Exception + */ + @Test + public void testHvacHardButtonOperations() throws Exception { + Log.d(TAG, "Prepare HVAC test data"); + List<CarPropertyValue> expectedEvents = getExpectedEvents(CAR_HVAC_TEST_JSON); + VhalEventVerifier verifier = new VhalEventVerifier(expectedEvents); + + CarPropertyManager propMgr = (CarPropertyManager) mCar.getCarManager(Car.PROPERTY_SERVICE); + assertNotNull("CarPropertyManager is null", propMgr); + + ArraySet<Integer> props = new ArraySet<>(); + for (CarPropertyValue event : expectedEvents) { + if (!props.contains(event.getPropertyId())) { + props.add(event.getPropertyId()); + } + } + + int numToSkip = countNumPropEventsToSkip(propMgr, props); + Log.d(TAG, String.format("Start listening to the HAL." + + " Skipping %d events for listener registration", numToSkip)); + CarPropertyManager.CarPropertyEventListener receiver = + new CarPropertyEventReceiver(verifier, numToSkip); + for (Integer prop : props) { + propMgr.registerListener(receiver, prop, 0); + } + + File sharedJson = makeShareable(CAR_HVAC_TEST_JSON); + Log.d(TAG, "Send command to VHAL to start generation"); + VhalEventGenerator hvacGenerator = + new JsonVhalEventGenerator(mVehicle).setJsonFile(sharedJson); + hvacGenerator.start(); + + Log.d(TAG, "Receiving and verifying VHAL events"); + verifier.waitForEnd(TEST_TIME_OUT.toMillis()); + + Log.d(TAG, "Send command to VHAL to stop generation"); + hvacGenerator.stop(); + propMgr.unregisterListener(receiver); + + assertTrue("Detected mismatched events: " + verifier.getResultString(), + verifier.getMismatchedEvents().isEmpty()); + } + + /** + * This test will exercise on "set" calls to inject HVAC data in order to test the Car Property + * API end-to-end functionality. + * @throws Exception + */ + @Test + @SuppressWarnings("unchecked") + public void testHvacSetGetOperations() throws Exception { + Log.d(TAG, "Prepare HVAC test data"); + List<CarPropertyValue> expectedEvents = getExpectedEvents(CAR_HVAC_TEST_JSON); + + CarPropertyManager propMgr = (CarPropertyManager) mCar.getCarManager(Car.PROPERTY_SERVICE); + assertNotNull("CarPropertyManager is null", propMgr); + + final long waitForSetMillisecond = 2; + for (CarPropertyValue expectedEvent : expectedEvents) { + Class valueClass = expectedEvent.getValue().getClass(); + propMgr.setProperty(valueClass, + expectedEvent.getPropertyId(), + expectedEvent.getAreaId(), + expectedEvent.getValue()); + + Thread.sleep(waitForSetMillisecond); + CarPropertyValue receivedEvent = propMgr.getProperty(valueClass, + expectedEvent.getPropertyId(), expectedEvent.getAreaId()); + assertTrue("Mismatched events, expected: " + expectedEvent + ", received: " + + receivedEvent, Utils.areCarPropertyValuesEqual(expectedEvent, receivedEvent)); + } + } + + /** + * This test will load static vehicle information from test data file and verify them through + * get calls. + * @throws Exception + */ + @Test + public void testStaticInfoOperations() throws Exception { + Log.d(TAG, "Prepare static car information"); + + List<CarPropertyValue> expectedEvents = getExpectedEvents(CAR_INFO_TEST_JSON); + CarPropertyManager propMgr = (CarPropertyManager) mCar.getCarManager(Car.PROPERTY_SERVICE); + assertNotNull("CarPropertyManager is null", propMgr); + + File sharedJson = makeShareable(CAR_INFO_TEST_JSON); + Log.d(TAG, "Send command to VHAL to start generation"); + VhalEventGenerator infoGenerator = + new JsonVhalEventGenerator(mVehicle).setJsonFile(sharedJson); + infoGenerator.start(); + + // Wait for some time to ensure information is all loaded + // It is assuming the test data is not very large + Thread.sleep(2000); + + Log.d(TAG, "Send command to VHAL to stop generation"); + infoGenerator.stop(); + + for (CarPropertyValue expectedEvent : expectedEvents) { + CarPropertyValue actualEvent = propMgr.getProperty( + expectedEvent.getPropertyId(), expectedEvent.getAreaId()); + assertTrue(String.format( + "Mismatched car information data, actual: %s, expected: %s", + actualEvent, expectedEvent), + Utils.areCarPropertyValuesEqual(actualEvent, expectedEvent)); + } + } +} diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2eCarTestBase.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2eCarTestBase.java index 5960422bb2..9485d805e6 100644 --- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2eCarTestBase.java +++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2eCarTestBase.java @@ -19,12 +19,12 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assume.assumeTrue; import android.car.Car; +import android.car.hardware.CarPropertyValue; import android.content.ComponentName; import android.content.Context; import android.content.ServiceConnection; import android.hardware.automotive.vehicle.V2_0.IVehicle; import android.hardware.automotive.vehicle.V2_0.StatusCode; -import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; import android.os.ConditionVariable; import android.os.FileUtils; import android.os.IBinder; @@ -82,7 +82,7 @@ public class E2eCarTestBase { } } - protected List<VehiclePropValue> getExpectedEvents(String fileName) + protected List<CarPropertyValue> getExpectedEvents(String fileName) throws IOException, JSONException { try (InputStream in = mContext.getAssets().open(fileName)) { Log.d(TAG, "Reading golden test data" + fileName); diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Utils.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Utils.java index 6a4b49689f..496b504897 100644 --- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Utils.java +++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Utils.java @@ -16,13 +16,10 @@ package com.android.car.vehiclehal.test; -import static java.lang.Integer.toHexString; - import android.car.hardware.CarPropertyValue; import android.hardware.automotive.vehicle.V2_0.IVehicle; import android.hardware.automotive.vehicle.V2_0.VehiclePropConfig; import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; -import android.os.HidlSupport; import android.os.RemoteException; import android.util.Log; @@ -102,55 +99,13 @@ final class Utils { * @param value2 * @return true if equal */ - static boolean areVehiclePropValuesEqual(final VehiclePropValue value1, - final VehiclePropValue value2) { + static boolean areCarPropertyValuesEqual(final CarPropertyValue value1, + final CarPropertyValue value2) { return value1 == value2 || value1 != null && value2 != null - && value1.prop == value2.prop - && value1.areaId == value2.areaId - && HidlSupport.deepEquals(value1.value, value2.value); - } - - /** - * The method will convert prop ID to hexadecimal format, and omit timestamp and status - * - * @param value - * @return String - */ - static String vehiclePropValueToString(final VehiclePropValue value) { - return "{.prop = 0x" + toHexString(value.prop) - + ", .areaId = " + value.areaId - + ", .value = " + value.value + "}"; - } - - static VehiclePropValue fromHvacPropertyValue(CarPropertyValue value) { - VehiclePropValueBuilder builder = - VehiclePropValueBuilder.newBuilder( - VhalPropMaps.getHvacVhalProp(value.getPropertyId())); - return fromCarPropertyValue(value, builder); - } - - private static VehiclePropValue fromCarPropertyValue( - CarPropertyValue value, VehiclePropValueBuilder builder) { - builder.setAreaId(value.getAreaId()).setTimestamp(value.getTimestamp()); - - //TODO: Consider move this conversion to VehiclePropValueBuilder - Object o = value.getValue(); - if (o instanceof Boolean) { - builder.addIntValue((boolean) o ? 1 : 0); - } else if (o instanceof Integer) { - builder.addIntValue((int) o); - } else if (o instanceof Float) { - builder.addFloatValue((float) o); - } else if (o instanceof Long) { - builder.setInt64Value((long) o); - } else if (o instanceof String) { - builder.setStringValue((String) o); - } else { //TODO: Add support for MIXED type - throw new IllegalArgumentException("Unrecognized car property value type, " - + o.getClass()); - } - return builder.build(); + && value1.getPropertyId() == value2.getPropertyId() + && value1.getAreaId() == value2.getAreaId() + && value1.getValue().equals(value2.getValue()); } } diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalEventVerifier.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalEventVerifier.java index 5ac92cae77..62dbf5cc70 100644 --- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalEventVerifier.java +++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalEventVerifier.java @@ -15,7 +15,7 @@ */ package com.android.car.vehiclehal.test; -import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; +import android.car.hardware.CarPropertyValue; import android.os.ConditionVariable; import java.util.ArrayList; @@ -28,7 +28,7 @@ import java.util.List; * The verifier will provide formatted result for all mismatched events in sequence. */ class VhalEventVerifier { - private List<VehiclePropValue> mExpectedEvents; + private List<CarPropertyValue> mExpectedEvents; // A pointer to keep track of the next expected event in the list private int mIdx; private List<MismatchedEventPair> mMismatchedEvents; @@ -37,10 +37,10 @@ class VhalEventVerifier { static class MismatchedEventPair { public final int idx; - public final VehiclePropValue expectedEvent; - public final VehiclePropValue mismatchedEvent; + public final CarPropertyValue expectedEvent; + public final CarPropertyValue mismatchedEvent; - MismatchedEventPair(VehiclePropValue expectedEvent, VehiclePropValue mismatchedEvent, + MismatchedEventPair(CarPropertyValue expectedEvent, CarPropertyValue mismatchedEvent, int idx) { this.idx = idx; this.expectedEvent = expectedEvent; @@ -48,7 +48,7 @@ class VhalEventVerifier { } } - VhalEventVerifier(List<VehiclePropValue> expectedEvents) { + VhalEventVerifier(List<CarPropertyValue> expectedEvents) { mExpectedEvents = expectedEvents; mIdx = 0; mMismatchedEvents = new ArrayList<>(); @@ -62,12 +62,12 @@ class VhalEventVerifier { * * @param nextEvent to be verified */ - public void verify(VehiclePropValue nextEvent) { + public void verify(CarPropertyValue nextEvent) { if (mIdx >= mExpectedEvents.size()) { return; } - VehiclePropValue expectedEvent = mExpectedEvents.get(mIdx); - if (!Utils.areVehiclePropValuesEqual(expectedEvent, nextEvent)) { + CarPropertyValue expectedEvent = mExpectedEvents.get(mIdx); + if (!Utils.areCarPropertyValuesEqual(expectedEvent, nextEvent)) { mMismatchedEvents.add(new MismatchedEventPair(expectedEvent, nextEvent, mIdx)); } if (++mIdx == mExpectedEvents.size()) { @@ -87,8 +87,8 @@ class VhalEventVerifier { StringBuilder resultBuilder = new StringBuilder(); for (MismatchedEventPair pair : mMismatchedEvents) { resultBuilder.append("Index " + pair.idx + ": Expected " - + Utils.vehiclePropValueToString(pair.expectedEvent) + ", Received " - + Utils.vehiclePropValueToString(pair.mismatchedEvent) + "\n"); + + pair.expectedEvent + ", Received " + + pair.mismatchedEvent + "\n"); } return resultBuilder.toString(); } diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalJsonReader.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalJsonReader.java index bf4e32fa59..01a62fc070 100644 --- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalJsonReader.java +++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalJsonReader.java @@ -17,10 +17,9 @@ package com.android.car.vehiclehal.test; import static java.lang.Integer.toHexString; -import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; +import android.car.hardware.CarPropertyValue; import android.hardware.automotive.vehicle.V2_0.VehiclePropertyType; -import com.android.car.vehiclehal.VehiclePropValueBuilder; import org.json.JSONArray; import org.json.JSONException; @@ -45,10 +44,10 @@ class VhalJsonReader { private static final String JSON_FIELD_TIMESTAMP = "timestamp"; private static final String JSON_FIELD_VALUE = "value"; - public static List<VehiclePropValue> readFromJson(InputStream in) + public static List<CarPropertyValue> readFromJson(InputStream in) throws IOException, JSONException { JSONArray rawEvents = new JSONArray(readJsonString(in)); - List<VehiclePropValue> events = new ArrayList<>(); + List<CarPropertyValue> events = new ArrayList<>(); for (int i = 0; i < rawEvents.length(); i++) { events.add(getEvent(rawEvents.getJSONObject(i))); } @@ -64,32 +63,33 @@ class VhalJsonReader { return builder.toString(); } - private static VehiclePropValue getEvent(JSONObject rawEvent) throws JSONException { + private static CarPropertyValue<?> getEvent(JSONObject rawEvent) throws JSONException { int prop = rawEvent.getInt(JSON_FIELD_PROP); - VehiclePropValueBuilder builder = VehiclePropValueBuilder.newBuilder(prop) - .setAreaId(rawEvent.getInt(JSON_FIELD_AREA_ID)) - .setTimestamp(rawEvent.getLong(JSON_FIELD_TIMESTAMP)); + int areaId = rawEvent.getInt(JSON_FIELD_AREA_ID); + long timestamp = rawEvent.getLong(JSON_FIELD_TIMESTAMP); switch (prop & VehiclePropertyType.MASK) { case VehiclePropertyType.BOOLEAN: + return new CarPropertyValue<>(prop, areaId, CarPropertyValue.STATUS_AVAILABLE, + timestamp, rawEvent.getInt(JSON_FIELD_VALUE) != 0); case VehiclePropertyType.INT32: - builder.addIntValue(rawEvent.getInt(JSON_FIELD_VALUE)); - break; + return new CarPropertyValue<>(prop, areaId, CarPropertyValue.STATUS_AVAILABLE, + timestamp, rawEvent.getInt(JSON_FIELD_VALUE)); case VehiclePropertyType.INT64: - builder.setInt64Value(rawEvent.getLong(JSON_FIELD_VALUE)); - break; + return new CarPropertyValue<>(prop, areaId, CarPropertyValue.STATUS_AVAILABLE, + timestamp, rawEvent.getLong(JSON_FIELD_VALUE)); case VehiclePropertyType.FLOAT: - builder.addFloatValue((float) rawEvent.getDouble(JSON_FIELD_VALUE)); - break; + return new CarPropertyValue<>(prop, areaId, + CarPropertyValue.STATUS_AVAILABLE, timestamp, + (float) rawEvent.getDouble(JSON_FIELD_VALUE)); case VehiclePropertyType.STRING: - builder.setStringValue(rawEvent.getString(JSON_FIELD_VALUE)); - break; + return new CarPropertyValue<>(prop, areaId, CarPropertyValue.STATUS_AVAILABLE, + timestamp, rawEvent.getString(JSON_FIELD_VALUE)); //TODO: Add VehiclePropertyType.MIXED type support default: throw new IllegalArgumentException("Property type 0x" + toHexString(prop & VehiclePropertyType.MASK) + " is not supported in the test."); } - return builder.build(); } } diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalPropMaps.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalPropMaps.java deleted file mode 100644 index f24cad68d8..0000000000 --- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalPropMaps.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2018 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 com.android.car.vehiclehal.test; - -import android.car.hardware.hvac.CarHvacManager; -import android.hardware.automotive.vehicle.V2_0.VehicleProperty; -import android.util.SparseIntArray; - -class VhalPropMaps { - - private static final SparseIntArray HVAC_PROP_MAP; - - static { - HVAC_PROP_MAP = new SparseIntArray(); - HVAC_PROP_MAP.put(CarHvacManager.ID_MIRROR_DEFROSTER_ON, - VehicleProperty.HVAC_SIDE_MIRROR_HEAT); - HVAC_PROP_MAP.put(CarHvacManager.ID_STEERING_WHEEL_HEAT, - VehicleProperty.HVAC_STEERING_WHEEL_HEAT); - HVAC_PROP_MAP.put(CarHvacManager.ID_OUTSIDE_AIR_TEMP, - VehicleProperty.ENV_OUTSIDE_TEMPERATURE); - HVAC_PROP_MAP.put(CarHvacManager.ID_TEMPERATURE_DISPLAY_UNITS, - VehicleProperty.HVAC_TEMPERATURE_DISPLAY_UNITS); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_TEMP_SETPOINT, - VehicleProperty.HVAC_TEMPERATURE_SET); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_TEMP_ACTUAL, - VehicleProperty.HVAC_TEMPERATURE_CURRENT); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_FAN_SPEED_SETPOINT, - VehicleProperty.HVAC_FAN_SPEED); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_FAN_SPEED_RPM, - VehicleProperty.HVAC_ACTUAL_FAN_SPEED_RPM); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_FAN_DIRECTION_AVAILABLE, - VehicleProperty.HVAC_FAN_DIRECTION_AVAILABLE); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_FAN_DIRECTION, - VehicleProperty.HVAC_FAN_DIRECTION); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_SEAT_TEMP, - VehicleProperty.HVAC_SEAT_TEMPERATURE); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_AC_ON, - VehicleProperty.HVAC_AC_ON); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_AUTOMATIC_MODE_ON, - VehicleProperty.HVAC_AUTO_ON); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_AIR_RECIRCULATION_ON, - VehicleProperty.HVAC_RECIRC_ON); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_MAX_AC_ON, - VehicleProperty.HVAC_MAX_AC_ON); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_DUAL_ZONE_ON, - VehicleProperty.HVAC_DUAL_ON); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_MAX_DEFROST_ON, - VehicleProperty.HVAC_MAX_DEFROST_ON); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_HVAC_POWER_ON, - VehicleProperty.HVAC_POWER_ON); - HVAC_PROP_MAP.put(CarHvacManager.ID_ZONED_HVAC_AUTO_RECIRC_ON, - VehicleProperty.HVAC_AUTO_RECIRC_ON); - HVAC_PROP_MAP.put(CarHvacManager.ID_WINDOW_DEFROSTER_ON, - VehicleProperty.HVAC_DEFROSTER); - } - - static int getHvacVhalProp(final int hvacProp) { - return HVAC_PROP_MAP.get(hvacProp); - } -} |