Add fake OBD2 frame logic to default VHAL.
Test: unit test
Bug: 193831021
Change-Id: Ie26cf0c5468984781bd6d7a0bf7edc2e0b2426e3
diff --git a/automotive/vehicle/2.0/default/Android.bp b/automotive/vehicle/2.0/default/Android.bp
index 3be460c..8bf6bbe 100644
--- a/automotive/vehicle/2.0/default/Android.bp
+++ b/automotive/vehicle/2.0/default/Android.bp
@@ -92,6 +92,7 @@
"impl/vhal_v2_0/LinearFakeValueGenerator.cpp",
"impl/vhal_v2_0/JsonFakeValueGenerator.cpp",
"impl/vhal_v2_0/GeneratorHub.cpp",
+ "impl/vhal_v2_0/FakeObd2Frame.cpp",
],
local_include_dirs: ["common/include/vhal_v2_0"],
export_include_dirs: ["impl"],
@@ -141,6 +142,7 @@
"impl/vhal_v2_0/JsonFakeValueGenerator.cpp",
"impl/vhal_v2_0/LinearFakeValueGenerator.cpp",
"impl/vhal_v2_0/DefaultVehicleHalServer.cpp",
+ "impl/vhal_v2_0/FakeObd2Frame.cpp",
],
whole_static_libs: [
"android.hardware.automotive.vehicle@2.0-server-common-lib",
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultVehicleHal.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultVehicleHal.cpp
index 51ba6fd..74337b8 100644
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultVehicleHal.cpp
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultVehicleHal.cpp
@@ -23,6 +23,7 @@
#include <vhal_v2_0/RecurrentTimer.h>
#include <unordered_set>
+#include "FakeObd2Frame.h"
#include "PropertyUtils.h"
#include "VehicleUtils.h"
@@ -94,6 +95,17 @@
ALOGV("get(%d)", propId);
VehiclePropValuePtr v = nullptr;
+ if (propId == OBD2_FREEZE_FRAME) {
+ v = getValuePool()->obtainComplex();
+ *outStatus = fillObd2FreezeFrame(mPropStore, requestedPropValue, v.get());
+ return addTimestamp(std::move(v));
+ }
+
+ if (propId == OBD2_FREEZE_FRAME_INFO) {
+ v = getValuePool()->obtainComplex();
+ *outStatus = fillObd2DtcInfo(mPropStore, v.get());
+ return addTimestamp(std::move(v));
+ }
auto internalPropValue = mPropStore->readValueOrNull(requestedPropValue);
if (internalPropValue != nullptr) {
@@ -296,6 +308,9 @@
}
}
+ if (propValue.prop == OBD2_FREEZE_FRAME_CLEAR) {
+ return clearObd2FreezeFrames(mPropStore, propValue);
+ }
if (propValue.prop == VEHICLE_MAP_SERVICE) {
// Placeholder for future implementation of VMS property in the default hal. For
// now, just returns OK; otherwise, hal clients crash with property not supported.
@@ -347,6 +362,12 @@
auto configs = mVehicleClient->getAllPropertyConfig();
for (const auto& cfg : configs) {
+ if (isDiagnosticProperty(cfg)) {
+ // do not write an initial empty value for the diagnostic properties
+ // as we will initialize those separately.
+ continue;
+ }
+
int32_t numAreas = isGlobalProp(cfg.prop) ? 1 : cfg.areaConfigs.size();
for (int i = 0; i < numAreas; i++) {
@@ -365,6 +386,9 @@
mVehicleClient->triggerSendAllValues();
+ initObd2LiveFrame(mPropStore, *mPropStore->getConfigOrDie(OBD2_LIVE_FRAME));
+ initObd2FreezeFrame(mPropStore, *mPropStore->getConfigOrDie(OBD2_FREEZE_FRAME));
+
registerHeartBeatEvent();
}
@@ -474,7 +498,21 @@
void DefaultVehicleHal::initStaticConfig() {
auto configs = mVehicleClient->getAllPropertyConfig();
for (auto&& cfg : configs) {
- mPropStore->registerProperty(cfg, nullptr);
+ VehiclePropertyStore::TokenFunction tokenFunction = nullptr;
+
+ switch (cfg.prop) {
+ case OBD2_FREEZE_FRAME: {
+ // We use timestamp as token for OBD2_FREEZE_FRAME
+ tokenFunction = [](const VehiclePropValue& propValue) {
+ return propValue.timestamp;
+ };
+ break;
+ }
+ default:
+ break;
+ }
+
+ mPropStore->registerProperty(cfg, tokenFunction);
}
}
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultVehicleHalServer.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultVehicleHalServer.cpp
index 595a1d1..0aaa4c1 100644
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultVehicleHalServer.cpp
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultVehicleHalServer.cpp
@@ -27,6 +27,7 @@
#include <utils/SystemClock.h>
#include "DefaultConfig.h"
+#include "FakeObd2Frame.h"
#include "JsonFakeValueGenerator.h"
#include "LinearFakeValueGenerator.h"
@@ -78,6 +79,10 @@
for (auto& it : kVehicleProperties) {
VehiclePropConfig cfg = it.config;
mServerSidePropStore.registerProperty(cfg);
+ // Skip diagnostic properties since there is special logic to handle those.
+ if (isDiagnosticProperty(cfg)) {
+ continue;
+ }
storePropInitialValue(it);
}
maybeOverrideProperties(VENDOR_OVERRIDE_DIR);
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/FakeObd2Frame.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/FakeObd2Frame.cpp
new file mode 100644
index 0000000..d95584d
--- /dev/null
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/FakeObd2Frame.cpp
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#include <android/hardware/automotive/vehicle/2.0/types.h>
+#include <utils/Log.h>
+#include <vhal_v2_0/Obd2SensorStore.h>
+#include <vhal_v2_0/PropertyUtils.h>
+#include <vhal_v2_0/VehiclePropertyStore.h>
+#include <vhal_v2_0/VehicleUtils.h>
+
+namespace android {
+namespace hardware {
+namespace automotive {
+namespace vehicle {
+namespace V2_0 {
+
+namespace impl {
+
+namespace {
+
+std::unique_ptr<Obd2SensorStore> fillDefaultObd2Frame(size_t numVendorIntegerSensors,
+ size_t numVendorFloatSensors) {
+ std::unique_ptr<Obd2SensorStore> sensorStore(
+ new Obd2SensorStore(numVendorIntegerSensors, numVendorFloatSensors));
+
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::FUEL_SYSTEM_STATUS,
+ toInt(Obd2FuelSystemStatus::CLOSED_LOOP));
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::MALFUNCTION_INDICATOR_LIGHT_ON, 0);
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::IGNITION_MONITORS_SUPPORTED,
+ toInt(Obd2IgnitionMonitorKind::SPARK));
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::IGNITION_SPECIFIC_MONITORS,
+ Obd2CommonIgnitionMonitors::COMPONENTS_AVAILABLE |
+ Obd2CommonIgnitionMonitors::MISFIRE_AVAILABLE |
+ Obd2SparkIgnitionMonitors::AC_REFRIGERANT_AVAILABLE |
+ Obd2SparkIgnitionMonitors::EVAPORATIVE_SYSTEM_AVAILABLE);
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::INTAKE_AIR_TEMPERATURE, 35);
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::COMMANDED_SECONDARY_AIR_STATUS,
+ toInt(Obd2SecondaryAirStatus::FROM_OUTSIDE_OR_OFF));
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::NUM_OXYGEN_SENSORS_PRESENT, 1);
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::RUNTIME_SINCE_ENGINE_START, 500);
+ sensorStore->setIntegerSensor(
+ DiagnosticIntegerSensorIndex::DISTANCE_TRAVELED_WITH_MALFUNCTION_INDICATOR_LIGHT_ON, 0);
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::WARMUPS_SINCE_CODES_CLEARED, 51);
+ sensorStore->setIntegerSensor(
+ DiagnosticIntegerSensorIndex::DISTANCE_TRAVELED_SINCE_CODES_CLEARED, 365);
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::ABSOLUTE_BAROMETRIC_PRESSURE, 30);
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::CONTROL_MODULE_VOLTAGE, 12);
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::AMBIENT_AIR_TEMPERATURE, 18);
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::MAX_FUEL_AIR_EQUIVALENCE_RATIO, 1);
+ sensorStore->setIntegerSensor(DiagnosticIntegerSensorIndex::FUEL_TYPE,
+ toInt(Obd2FuelType::GASOLINE));
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::CALCULATED_ENGINE_LOAD, 0.153);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::SHORT_TERM_FUEL_TRIM_BANK1, -0.16);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::LONG_TERM_FUEL_TRIM_BANK1, -0.16);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::SHORT_TERM_FUEL_TRIM_BANK2, -0.16);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::LONG_TERM_FUEL_TRIM_BANK2, -0.16);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::INTAKE_MANIFOLD_ABSOLUTE_PRESSURE, 7.5);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::ENGINE_RPM, 1250.);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::VEHICLE_SPEED, 40.);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::TIMING_ADVANCE, 2.5);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::THROTTLE_POSITION, 19.75);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::OXYGEN_SENSOR1_VOLTAGE, 0.265);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::FUEL_TANK_LEVEL_INPUT, 0.824);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::EVAPORATION_SYSTEM_VAPOR_PRESSURE,
+ -0.373);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::CATALYST_TEMPERATURE_BANK1_SENSOR1,
+ 190.);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::RELATIVE_THROTTLE_POSITION, 3.);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::ABSOLUTE_THROTTLE_POSITION_B, 0.306);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::ACCELERATOR_PEDAL_POSITION_D, 0.188);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::ACCELERATOR_PEDAL_POSITION_E, 0.094);
+ sensorStore->setFloatSensor(DiagnosticFloatSensorIndex::COMMANDED_THROTTLE_ACTUATOR, 0.024);
+
+ return sensorStore;
+}
+
+} // namespace
+
+void initObd2LiveFrame(VehiclePropertyStore* propStore, const VehiclePropConfig& propConfig) {
+ auto liveObd2Frame = createVehiclePropValue(VehiclePropertyType::MIXED, 0);
+ auto sensorStore = fillDefaultObd2Frame(static_cast<size_t>(propConfig.configArray[0]),
+ static_cast<size_t>(propConfig.configArray[1]));
+ sensorStore->fillPropValue("", liveObd2Frame.get());
+ liveObd2Frame->prop = OBD2_LIVE_FRAME;
+
+ propStore->writeValue(*liveObd2Frame, true);
+}
+
+void initObd2FreezeFrame(VehiclePropertyStore* propStore, const VehiclePropConfig& propConfig) {
+ auto sensorStore = fillDefaultObd2Frame(static_cast<size_t>(propConfig.configArray[0]),
+ static_cast<size_t>(propConfig.configArray[1]));
+
+ static std::vector<std::string> sampleDtcs = {"P0070", "P0102", "P0123"};
+ for (auto&& dtc : sampleDtcs) {
+ auto freezeFrame = createVehiclePropValue(VehiclePropertyType::MIXED, 0);
+ sensorStore->fillPropValue(dtc, freezeFrame.get());
+ freezeFrame->prop = OBD2_FREEZE_FRAME;
+ ALOGE("freeze frame: %lld", (long long)freezeFrame->timestamp);
+
+ propStore->writeValue(*freezeFrame, true);
+ }
+}
+
+StatusCode fillObd2FreezeFrame(VehiclePropertyStore* propStore,
+ const VehiclePropValue& requestedPropValue,
+ VehiclePropValue* outValue) {
+ if (requestedPropValue.value.int64Values.size() != 1) {
+ ALOGE("asked for OBD2_FREEZE_FRAME without valid timestamp");
+ return StatusCode::INVALID_ARG;
+ }
+ if (propStore->readValuesForProperty(OBD2_FREEZE_FRAME).size() == 0) {
+ // Should no freeze frame be available at the given timestamp, a response of NOT_AVAILABLE
+ // must be returned by the implementation
+ return StatusCode::NOT_AVAILABLE;
+ }
+ auto timestamp = requestedPropValue.value.int64Values[0];
+ auto freezeFrame = propStore->readValueOrNull(OBD2_FREEZE_FRAME, 0, timestamp);
+ if (freezeFrame == nullptr) {
+ ALOGE("asked for OBD2_FREEZE_FRAME at invalid timestamp");
+ return StatusCode::INVALID_ARG;
+ }
+ outValue->prop = OBD2_FREEZE_FRAME;
+ outValue->value.int32Values = freezeFrame->value.int32Values;
+ outValue->value.floatValues = freezeFrame->value.floatValues;
+ outValue->value.bytes = freezeFrame->value.bytes;
+ outValue->value.stringValue = freezeFrame->value.stringValue;
+ outValue->timestamp = freezeFrame->timestamp;
+ return StatusCode::OK;
+}
+
+StatusCode fillObd2DtcInfo(VehiclePropertyStore* propStore, VehiclePropValue* outValue) {
+ std::vector<int64_t> timestamps;
+ for (const auto& freezeFrame : propStore->readValuesForProperty(OBD2_FREEZE_FRAME)) {
+ timestamps.push_back(freezeFrame.timestamp);
+ }
+ outValue->value.int64Values = timestamps;
+ outValue->prop = OBD2_FREEZE_FRAME_INFO;
+ return StatusCode::OK;
+}
+
+StatusCode clearObd2FreezeFrames(VehiclePropertyStore* propStore,
+ const VehiclePropValue& propValue) {
+ if (propValue.value.int64Values.size() == 0) {
+ propStore->removeValuesForProperty(OBD2_FREEZE_FRAME);
+ return StatusCode::OK;
+ } else {
+ for (int64_t timestamp : propValue.value.int64Values) {
+ auto freezeFrame = propStore->readValueOrNull(OBD2_FREEZE_FRAME, 0, timestamp);
+ if (freezeFrame == nullptr) {
+ ALOGE("asked for OBD2_FREEZE_FRAME at invalid timestamp");
+ return StatusCode::INVALID_ARG;
+ }
+ propStore->removeValue(*freezeFrame);
+ }
+ }
+ return StatusCode::OK;
+}
+
+bool isDiagnosticProperty(const VehiclePropConfig& propConfig) {
+ return (propConfig.prop == OBD2_LIVE_FRAME || propConfig.prop == OBD2_FREEZE_FRAME ||
+ propConfig.prop == OBD2_FREEZE_FRAME_CLEAR ||
+ propConfig.prop == OBD2_FREEZE_FRAME_INFO);
+}
+
+} // namespace impl
+
+} // namespace V2_0
+} // namespace vehicle
+} // namespace automotive
+} // namespace hardware
+} // namespace android
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/FakeObd2Frame.h b/automotive/vehicle/2.0/default/impl/vhal_v2_0/FakeObd2Frame.h
new file mode 100644
index 0000000..704964c
--- /dev/null
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/FakeObd2Frame.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+#ifndef android_hardware_automotive_vehicle_V2_0_impl_FakeObd2Frame_H_
+#define android_hardware_automotive_vehicle_V2_0_impl_FakeObd2Frame_H_
+
+#include <android/hardware/automotive/vehicle/2.0/types.h>
+#include <vhal_v2_0/VehiclePropertyStore.h>
+
+namespace android {
+namespace hardware {
+namespace automotive {
+namespace vehicle {
+namespace V2_0 {
+
+namespace impl {
+
+void initObd2LiveFrame(VehiclePropertyStore* propStore, const VehiclePropConfig& propConfig);
+void initObd2FreezeFrame(VehiclePropertyStore* propStore, const VehiclePropConfig& propConfig);
+StatusCode fillObd2FreezeFrame(VehiclePropertyStore* propStore,
+ const VehiclePropValue& requestedPropValue,
+ VehiclePropValue* outValue);
+StatusCode fillObd2DtcInfo(VehiclePropertyStore* propStore, VehiclePropValue* outValue);
+StatusCode clearObd2FreezeFrames(VehiclePropertyStore* propStore,
+ const VehiclePropValue& propValue);
+bool isDiagnosticProperty(const VehiclePropConfig& propConfig);
+
+} // namespace impl
+
+} // namespace V2_0
+} // namespace vehicle
+} // namespace automotive
+} // namespace hardware
+} // namespace android
+
+#endif // android_hardware_automotive_vehicle_V2_0_impl_FakeObd2Frame_H_
diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp b/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp
index 4fb74f6..27c1f4d 100644
--- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp
+++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp
@@ -906,4 +906,145 @@
ASSERT_EQ(4, gotValue->value.int32Values[0]);
}
+TEST_F(DefaultVhalImplTest, testGetObd2FreezeFrameNoTimestamp) {
+ VehiclePropValue value;
+ value.prop = OBD2_FREEZE_FRAME;
+ StatusCode status;
+
+ auto gotValue = mHal->get(value, &status);
+
+ ASSERT_EQ(StatusCode::INVALID_ARG, status);
+}
+
+TEST_F(DefaultVhalImplTest, testGetObd2FreezeFrameInvalidTimestamp) {
+ VehiclePropValue value;
+ value.prop = OBD2_FREEZE_FRAME;
+ value.value.int64Values.resize(1);
+ value.value.int64Values[0] = 0;
+ StatusCode status;
+
+ auto gotValue = mHal->get(value, &status);
+
+ ASSERT_EQ(StatusCode::INVALID_ARG, status);
+}
+
+TEST_F(DefaultVhalImplTest, testGetObd2FreezeFrameInfoGetObd2FreezeFrame) {
+ VehiclePropValue value;
+ value.prop = OBD2_FREEZE_FRAME_INFO;
+ StatusCode status;
+
+ auto gotValue = mHal->get(value, &status);
+
+ ASSERT_EQ(StatusCode::OK, status);
+ ASSERT_EQ((size_t)3, gotValue->value.int64Values.size());
+
+ std::vector<std::string> dtcs;
+ std::vector<std::string> sampleDtcs = {"P0070", "P0102", "P0123"};
+ for (int64_t timestamp : gotValue->value.int64Values) {
+ VehiclePropValue freezeFrameRequest;
+ freezeFrameRequest.prop = OBD2_FREEZE_FRAME;
+ freezeFrameRequest.value.int64Values.resize(1);
+ freezeFrameRequest.value.int64Values[0] = timestamp;
+
+ auto freezeFrameValue = mHal->get(freezeFrameRequest, &status);
+
+ ASSERT_EQ(StatusCode::OK, status);
+ // Obd2IntegerSensorIndex.LAST_SYSTEM_INDEX + 1
+ EXPECT_EQ((size_t)32, freezeFrameValue->value.int32Values.size());
+ // Obd2FloatSensorIndex.LAST_SYSTEM_INDEX + 1
+ EXPECT_EQ((size_t)71, freezeFrameValue->value.floatValues.size());
+ // (intValues.size() + floatValues.size()) / 8
+ EXPECT_EQ((size_t)13, freezeFrameValue->value.bytes.size());
+
+ dtcs.push_back(freezeFrameValue->value.stringValue);
+ }
+
+ for (std::string expectDtc : sampleDtcs) {
+ EXPECT_NE(std::find(dtcs.begin(), dtcs.end(), expectDtc), dtcs.end());
+ }
+}
+
+TEST_F(DefaultVhalImplTest, testGetObd2LiveFrame) {
+ VehiclePropValue value;
+ value.prop = OBD2_LIVE_FRAME;
+ StatusCode status;
+
+ auto gotValue = mHal->get(value, &status);
+
+ ASSERT_EQ(StatusCode::OK, status);
+ // Obd2IntegerSensorIndex.LAST_SYSTEM_INDEX + 1
+ EXPECT_EQ((size_t)32, gotValue->value.int32Values.size());
+ // Obd2FloatSensorIndex.LAST_SYSTEM_INDEX + 1
+ EXPECT_EQ((size_t)71, gotValue->value.floatValues.size());
+ // (intValues.size() + floatValues.size()) / 8
+ EXPECT_EQ((size_t)13, gotValue->value.bytes.size());
+}
+
+TEST_F(DefaultVhalImplTest, testClearObd2FreezeFrameAll) {
+ VehiclePropValue value;
+ value.prop = OBD2_FREEZE_FRAME_CLEAR;
+ // No int64Values is to clear all frames.
+
+ auto status = mHal->set(value);
+
+ EXPECT_EQ(StatusCode::OK, status);
+
+ VehiclePropValue freezeFrameRequest;
+ freezeFrameRequest.prop = OBD2_FREEZE_FRAME;
+ freezeFrameRequest.value.int64Values.resize(1);
+
+ auto gotValue = mHal->get(freezeFrameRequest, &status);
+
+ EXPECT_EQ(StatusCode::NOT_AVAILABLE, status);
+
+ VehiclePropValue freezeFrameInfoRequest;
+ freezeFrameInfoRequest.prop = OBD2_FREEZE_FRAME_INFO;
+
+ gotValue = mHal->get(freezeFrameInfoRequest, &status);
+
+ EXPECT_EQ(StatusCode::OK, status);
+ EXPECT_EQ((size_t)0, gotValue->value.int64Values.size());
+}
+
+TEST_F(DefaultVhalImplTest, testClearObd2FreezeFrameOneFrame) {
+ // Get existing freeze frame info first.
+ VehiclePropValue frameInfoRequest;
+ frameInfoRequest.prop = OBD2_FREEZE_FRAME_INFO;
+ StatusCode status;
+ auto gotValue = mHal->get(frameInfoRequest, &status);
+ ASSERT_EQ(StatusCode::OK, status);
+ ASSERT_EQ((size_t)3, gotValue->value.int64Values.size());
+
+ VehiclePropValue clearRequest;
+ int64_t timestamp = gotValue->value.int64Values[0];
+ clearRequest.prop = OBD2_FREEZE_FRAME_CLEAR;
+ clearRequest.value.int64Values.resize(1);
+ clearRequest.value.int64Values[0] = timestamp;
+
+ // Try to clear the first frame.
+ status = mHal->set(clearRequest);
+
+ // Get freeze frame info again.
+ gotValue = mHal->get(frameInfoRequest, &status);
+
+ ASSERT_EQ(StatusCode::OK, status);
+ // Now we should only have 2 frames.
+ ASSERT_EQ((size_t)2, gotValue->value.int64Values.size());
+
+ // Try to get the deleted frame, should fail.
+ VehiclePropValue frameRequest;
+ frameRequest.prop = OBD2_FREEZE_FRAME;
+ frameRequest.value.int64Values.resize(1);
+ frameRequest.value.int64Values[0] = timestamp;
+
+ gotValue = mHal->get(frameRequest, &status);
+
+ ASSERT_EQ(StatusCode::INVALID_ARG, status);
+
+ // Clear the same frame again should fail.
+ status = mHal->set(clearRequest);
+
+ ASSERT_EQ(StatusCode::INVALID_ARG, status);
+}
+
} // namespace