Extract logic of storing values to separate class

Also rename DefaultVehicleHal to EmulatedVehicleHal and
extract emulator related code to VehicleEmulator class

Test: mm -j32 ; verified Car Service worked

Change-Id: I34361fdec6f94629cf7ef6c35ff56ef9ce78b855
diff --git a/automotive/vehicle/2.1/default/Android.mk b/automotive/vehicle/2.1/default/Android.mk
index 51cb146..32ec456 100644
--- a/automotive/vehicle/2.1/default/Android.mk
+++ b/automotive/vehicle/2.1/default/Android.mk
@@ -49,7 +49,7 @@
 
 LOCAL_MODULE:= $(vhal_v2_1)-default-impl-lib
 LOCAL_SRC_FILES:= \
-    impl/vhal_v2_1/DefaultVehicleHal.cpp \
+    impl/vhal_v2_1/EmulatedVehicleHal.cpp \
 
 LOCAL_C_INCLUDES := \
     $(LOCAL_PATH)/impl/vhal_v2_1 \
diff --git a/automotive/vehicle/2.1/default/common/include/vhal_v2_1/Obd2SensorStore.h b/automotive/vehicle/2.1/default/common/include/vhal_v2_1/Obd2SensorStore.h
index 945e3e0..6c44626 100644
--- a/automotive/vehicle/2.1/default/common/include/vhal_v2_1/Obd2SensorStore.h
+++ b/automotive/vehicle/2.1/default/common/include/vhal_v2_1/Obd2SensorStore.h
@@ -55,8 +55,7 @@
     const std::vector<uint8_t>& getSensorsBitmask() const;
 
     // Given a stringValue, fill in a VehiclePropValue
-    void fillPropValue(V2_0::VehiclePropValue *propValue,
-            std::string dtc) const;
+    void fillPropValue(const std::string& dtc, V2_0::VehiclePropValue *propValue) const;
 
 private:
     class BitmaskInVector {
diff --git a/automotive/vehicle/2.1/default/common/src/Obd2SensorStore.cpp b/automotive/vehicle/2.1/default/common/src/Obd2SensorStore.cpp
index b07717b..f4c63a9 100644
--- a/automotive/vehicle/2.1/default/common/src/Obd2SensorStore.cpp
+++ b/automotive/vehicle/2.1/default/common/src/Obd2SensorStore.cpp
@@ -99,8 +99,8 @@
     return mSensorsBitmask.getBitmask();
 }
 
-void Obd2SensorStore::fillPropValue(V2_0::VehiclePropValue *propValue,
-                                    std::string dtc) const {
+void Obd2SensorStore::fillPropValue(const std::string& dtc,
+                                    V2_0::VehiclePropValue *propValue) const {
     propValue->timestamp = elapsedRealtimeNano();
     propValue->value.int32Values = getIntegerSensors();
     propValue->value.floatValues = getFloatSensors();
diff --git a/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultConfig.h b/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultConfig.h
index 6bdec59..aa9aa3c 100644
--- a/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultConfig.h
+++ b/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultConfig.h
@@ -28,41 +28,50 @@
 
 namespace impl {
 
+// Some handy constants to avoid conversions from enum to int.
+constexpr int OBD2_LIVE_FRAME = (int) V2_1::VehicleProperty::OBD2_LIVE_FRAME;
+constexpr int OBD2_FREEZE_FRAME = (int) V2_1::VehicleProperty::OBD2_FREEZE_FRAME;
+constexpr int OBD2_FREEZE_FRAME_INFO = (int) V2_1::VehicleProperty::OBD2_FREEZE_FRAME_INFO;
+constexpr int OBD2_FREEZE_FRAME_CLEAR = (int) V2_1::VehicleProperty::OBD2_FREEZE_FRAME_CLEAR;
+constexpr int VEHICLE_MAP_SERVICE = (int) V2_1::VehicleProperty::VEHICLE_MAP_SERVICE;
+constexpr int WHEEL_TICK = (int) V2_1::VehicleProperty::WHEEL_TICK;
+
+
 const V2_0::VehiclePropConfig kVehicleProperties[] = {
     {
-        .prop = V2_0::toInt(V2_1::VehicleProperty::WHEEL_TICK),
+        .prop = WHEEL_TICK,
         .access = V2_0::VehiclePropertyAccess::READ,
         .changeMode = V2_0::VehiclePropertyChangeMode::CONTINUOUS,
     },
 
     {
-        .prop = V2_0::toInt(V2_1::VehicleProperty::OBD2_LIVE_FRAME),
+        .prop = OBD2_LIVE_FRAME,
         .access = V2_0::VehiclePropertyAccess::READ,
         .changeMode = V2_0::VehiclePropertyChangeMode::ON_CHANGE,
         .configArray = {0,0}
     },
 
     {
-        .prop = V2_0::toInt(V2_1::VehicleProperty::OBD2_FREEZE_FRAME),
+        .prop = OBD2_FREEZE_FRAME,
         .access = V2_0::VehiclePropertyAccess::READ,
         .changeMode = V2_0::VehiclePropertyChangeMode::ON_CHANGE,
         .configArray = {0,0}
     },
 
     {
-        .prop = V2_0::toInt(V2_1::VehicleProperty::OBD2_FREEZE_FRAME_INFO),
+        .prop = OBD2_FREEZE_FRAME_INFO,
         .access = V2_0::VehiclePropertyAccess::READ,
         .changeMode = V2_0::VehiclePropertyChangeMode::ON_CHANGE
     },
 
     {
-        .prop = V2_0::toInt(V2_1::VehicleProperty::OBD2_FREEZE_FRAME_CLEAR),
+        .prop = OBD2_FREEZE_FRAME_CLEAR,
         .access = V2_0::VehiclePropertyAccess::WRITE,
         .changeMode = V2_0::VehiclePropertyChangeMode::ON_CHANGE
     },
 
     {
-        .prop = V2_0::toInt(VehicleProperty::VEHICLE_MAP_SERVICE),
+        .prop = VEHICLE_MAP_SERVICE,
         .access = V2_0::VehiclePropertyAccess::READ_WRITE,
         .changeMode = V2_0::VehiclePropertyChangeMode::ON_CHANGE
     }
diff --git a/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultVehicleHal.h b/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultVehicleHal.h
deleted file mode 100644
index af21138..0000000
--- a/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultVehicleHal.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2016 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_1_impl_DefaultVehicleHal_H_
-#define android_hardware_automotive_vehicle_V2_1_impl_DefaultVehicleHal_H_
-
-#include <memory>
-
-#include <utils/SystemClock.h>
-
-#include <vhal_v2_0/VehicleHal.h>
-#include <vhal_v2_0/DefaultVehicleHal.h>
-#include <vhal_v2_1/Obd2SensorStore.h>
-
-#include "DefaultConfig.h"
-
-namespace android {
-namespace hardware {
-namespace automotive {
-namespace vehicle {
-namespace V2_1 {
-
-namespace impl {
-
-using namespace std::placeholders;
-
-class DefaultVehicleHal : public V2_0::VehicleHal {
-public:
-    DefaultVehicleHal(V2_0::impl::DefaultVehicleHal* vhal20) :
-          mVehicleHal20(vhal20) {}
-
-    std::vector<V2_0::VehiclePropConfig> listProperties() override {
-        std::vector<V2_0::VehiclePropConfig> propConfigs(mVehicleHal20->listProperties());
-
-        // Join Vehicle Hal 2.0 and 2.1 configs.
-        propConfigs.insert(propConfigs.end(),
-                           std::begin(kVehicleProperties),
-                           std::end(kVehicleProperties));
-
-        return propConfigs;
-    }
-
-    VehiclePropValuePtr get(const V2_0::VehiclePropValue& requestedPropValue,
-                            V2_0::StatusCode* outStatus) override;
-
-    V2_0::StatusCode set(const V2_0::VehiclePropValue& propValue) override;
-
-    V2_0::StatusCode subscribe(int32_t property,
-                               int32_t areas,
-                               float sampleRate) override {
-        return mVehicleHal20->subscribe(property, areas, sampleRate);
-    }
-
-    V2_0::StatusCode unsubscribe(int32_t property) override {
-        return mVehicleHal20->unsubscribe(property);
-    }
-
-    void onCreate() override;
-
-private:
-    void initObd2LiveFrame(V2_0::VehiclePropConfig& propConfig,
-        V2_0::VehiclePropValue* liveObd2Frame);
-    void initObd2FreezeFrame(V2_0::VehiclePropConfig& propConfig);
-    V2_0::StatusCode fillObd2FreezeFrame(const V2_0::VehiclePropValue& requestedPropValue,
-            V2_0::VehiclePropValue* v);
-    V2_0::StatusCode fillObd2DtcInfo(V2_0::VehiclePropValue *v);
-    V2_0::StatusCode clearObd2FreezeFrames(const V2_0::VehiclePropValue& propValue);
-
-private:
-    V2_0::impl::DefaultVehicleHal* mVehicleHal20;
-    std::vector<std::unique_ptr<V2_0::VehiclePropValue>> mFreezeObd2Frames;
-};
-
-}  // impl
-
-}  // namespace V2_1
-}  // namespace vehicle
-}  // namespace automotive
-}  // namespace hardware
-}  // namespace android
-
-
-#endif  // android_hardware_automotive_vehicle_V2_0_impl_DefaultVehicleHal_H_
diff --git a/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultVehicleHal.cpp b/automotive/vehicle/2.1/default/impl/vhal_v2_1/EmulatedVehicleHal.cpp
similarity index 63%
rename from automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultVehicleHal.cpp
rename to automotive/vehicle/2.1/default/impl/vhal_v2_1/EmulatedVehicleHal.cpp
index b147ce7..ae7f416 100644
--- a/automotive/vehicle/2.1/default/impl/vhal_v2_1/DefaultVehicleHal.cpp
+++ b/automotive/vehicle/2.1/default/impl/vhal_v2_1/EmulatedVehicleHal.cpp
@@ -21,7 +21,7 @@
 #include <netinet/in.h>
 #include <sys/socket.h>
 
-#include "DefaultVehicleHal.h"
+#include "EmulatedVehicleHal.h"
 #include "VehicleHalProto.pb.h"
 
 #define DEBUG_SOCKET    (33452)
@@ -120,118 +120,103 @@
     return sensorStore;
 }
 
-void DefaultVehicleHal::initObd2LiveFrame(V2_0::VehiclePropConfig& propConfig,
-    V2_0::VehiclePropValue* liveObd2Frame) {
-    auto sensorStore = fillDefaultObd2Frame(propConfig.configArray[0],
-            propConfig.configArray[1]);
-    sensorStore->fillPropValue(liveObd2Frame, "");
-    liveObd2Frame->prop = V2_0::toInt(VehicleProperty::OBD2_LIVE_FRAME);
+void EmulatedVehicleHal::initObd2LiveFrame(const V2_0::VehiclePropConfig& propConfig) {
+    auto liveObd2Frame = createVehiclePropValue(V2_0::VehiclePropertyType::COMPLEX, 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;
+
+    mPropStore->writeValue(*liveObd2Frame);
 }
 
-void DefaultVehicleHal::initObd2FreezeFrame(V2_0::VehiclePropConfig& propConfig) {
-    auto sensorStore = fillDefaultObd2Frame(propConfig.configArray[0],
-            propConfig.configArray[1]);
+void EmulatedVehicleHal::initObd2FreezeFrame(const V2_0::VehiclePropConfig& propConfig) {
+    auto sensorStore = fillDefaultObd2Frame(static_cast<size_t>(propConfig.configArray[0]),
+                                            static_cast<size_t>(propConfig.configArray[1]));
 
-    mFreezeObd2Frames.push_back(
-            createVehiclePropValue(V2_0::VehiclePropertyType::COMPLEX,0));
-    mFreezeObd2Frames.push_back(
-            createVehiclePropValue(V2_0::VehiclePropertyType::COMPLEX,0));
-    mFreezeObd2Frames.push_back(
-            createVehiclePropValue(V2_0::VehiclePropertyType::COMPLEX,0));
-
-    sensorStore->fillPropValue(mFreezeObd2Frames[0].get(), "P0070");
-    sensorStore->fillPropValue(mFreezeObd2Frames[1].get(), "P0102");
-    sensorStore->fillPropValue(mFreezeObd2Frames[2].get(), "P0123");
+    static std::vector<std::string> sampleDtcs = { "P0070", "P0102" "P0123" };
+    for (auto&& dtc : sampleDtcs) {
+        auto freezeFrame = createVehiclePropValue(V2_0::VehiclePropertyType::COMPLEX, 0);
+        sensorStore->fillPropValue(dtc, freezeFrame.get());
+        mPropStore->writeValue(*freezeFrame);
+    }
 }
 
-template<typename Iterable>
-typename Iterable::const_iterator findPropValueAtTimestamp(
-        const Iterable& frames,
-        int64_t timestamp) {
-    return std::find_if(frames.begin(),
-            frames.end(),
-            [timestamp] (const std::unique_ptr<V2_0::VehiclePropValue>&
-                         propValue) -> bool {
-                             return propValue->timestamp == timestamp;
-            });
-}
-
-V2_0::StatusCode DefaultVehicleHal::fillObd2FreezeFrame(
+V2_0::StatusCode EmulatedVehicleHal::fillObd2FreezeFrame(
         const V2_0::VehiclePropValue& requestedPropValue,
-        V2_0::VehiclePropValue* v) {
+        V2_0::VehiclePropValue* outValue) {
     if (requestedPropValue.value.int64Values.size() != 1) {
         ALOGE("asked for OBD2_FREEZE_FRAME without valid timestamp");
         return V2_0::StatusCode::INVALID_ARG;
     }
     auto timestamp = requestedPropValue.value.int64Values[0];
-    auto freezeFrameIter = findPropValueAtTimestamp(mFreezeObd2Frames,
-            timestamp);
-    if(mFreezeObd2Frames.end() == freezeFrameIter) {
+    auto freezeFrame = mPropStore->readValueOrNull(OBD2_FREEZE_FRAME, 0, timestamp);
+    if(freezeFrame == nullptr) {
         ALOGE("asked for OBD2_FREEZE_FRAME at invalid timestamp");
         return V2_0::StatusCode::INVALID_ARG;
     }
-    const auto& freezeFrame = *freezeFrameIter;
-    v->prop = V2_0::toInt(VehicleProperty::OBD2_FREEZE_FRAME);
-    v->value.int32Values = freezeFrame->value.int32Values;
-    v->value.floatValues = freezeFrame->value.floatValues;
-    v->value.bytes = freezeFrame->value.bytes;
-    v->value.stringValue = freezeFrame->value.stringValue;
-    v->timestamp = freezeFrame->timestamp;
+    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 V2_0::StatusCode::OK;
 }
 
-V2_0::StatusCode DefaultVehicleHal::clearObd2FreezeFrames(
-    const V2_0::VehiclePropValue& propValue) {
+V2_0::StatusCode EmulatedVehicleHal::clearObd2FreezeFrames(const V2_0::VehiclePropValue& propValue) {
     if (propValue.value.int64Values.size() == 0) {
-        mFreezeObd2Frames.clear();
+        mPropStore->removeValuesForProperty(OBD2_FREEZE_FRAME);
         return V2_0::StatusCode::OK;
     } else {
         for(int64_t timestamp: propValue.value.int64Values) {
-            auto freezeFrameIter = findPropValueAtTimestamp(mFreezeObd2Frames,
-                    timestamp);
-            if(mFreezeObd2Frames.end() == freezeFrameIter) {
+            auto freezeFrame = mPropStore->readValueOrNull(OBD2_FREEZE_FRAME, 0, timestamp);
+            if(freezeFrame == nullptr) {
                 ALOGE("asked for OBD2_FREEZE_FRAME at invalid timestamp");
                 return V2_0::StatusCode::INVALID_ARG;
             }
-            mFreezeObd2Frames.erase(freezeFrameIter);
+            mPropStore->removeValue(*freezeFrame);
         }
     }
     return V2_0::StatusCode::OK;
 }
 
-V2_0::StatusCode DefaultVehicleHal::fillObd2DtcInfo(V2_0::VehiclePropValue* v) {
+V2_0::StatusCode EmulatedVehicleHal::fillObd2DtcInfo(V2_0::VehiclePropValue* outValue) {
     std::vector<int64_t> timestamps;
-    for(const auto& freezeFrame: mFreezeObd2Frames) {
-        timestamps.push_back(freezeFrame->timestamp);
+    for(const auto& freezeFrame: mPropStore->readValuesForProperty(OBD2_FREEZE_FRAME)) {
+        timestamps.push_back(freezeFrame.timestamp);
     }
-    v->value.int64Values = timestamps;
+    outValue->value.int64Values = timestamps;
     return V2_0::StatusCode::OK;
 }
 
-void DefaultVehicleHal::onCreate() {
-    mVehicleHal20->init(getValuePool(),
-                        std::bind(&DefaultVehicleHal::doHalEvent, this, _1),
-                        std::bind(&DefaultVehicleHal::doHalPropertySetError, this, _1, _2, _3));
+void EmulatedVehicleHal::onCreate() {
+    V2_0::impl::EmulatedVehicleHal::onCreate();
 
-    std::vector<V2_0::VehiclePropConfig> configs = listProperties();
-    for (auto& cfg : configs) {
-        switch(cfg.prop) {
-            case V2_0::toInt(V2_1::VehicleProperty::OBD2_LIVE_FRAME): {
-                auto liveObd2Frame = createVehiclePropValue(V2_0::VehiclePropertyType::COMPLEX, 0);
-                initObd2LiveFrame(cfg, liveObd2Frame.get());
-                mVehicleHal20->addCustomProperty(*liveObd2Frame);
+    initObd2LiveFrame(*mPropStore->getConfigOrDie(OBD2_LIVE_FRAME));
+    initObd2FreezeFrame(*mPropStore->getConfigOrDie(OBD2_FREEZE_FRAME));
+}
+
+void EmulatedVehicleHal::initStaticConfig() {
+    for (auto&& cfg = std::begin(kVehicleProperties); cfg != std::end(kVehicleProperties); ++cfg) {
+        V2_0::VehiclePropertyStore::TokenFunction tokenFunction = nullptr;
+
+        switch (cfg->prop) {
+            case OBD2_FREEZE_FRAME: {
+                tokenFunction = [] (const V2_0::VehiclePropValue& propValue) {
+                    return propValue.timestamp;
+                };
+                break;
             }
-                break;
-            case V2_0::toInt(V2_1::VehicleProperty::OBD2_FREEZE_FRAME):
-                initObd2FreezeFrame(cfg);
-                break;
             default:
                 break;
         }
+
+        mPropStore->registerProperty(*cfg, tokenFunction);
     }
 }
 
-DefaultVehicleHal::VehiclePropValuePtr DefaultVehicleHal::get(
+EmulatedVehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get(
         const V2_0::VehiclePropValue& requestedPropValue,
         V2_0::StatusCode* outStatus) {
 
@@ -240,34 +225,30 @@
     auto& pool = *getValuePool();
 
     switch (propId) {
-    case V2_0::toInt(V2_1::VehicleProperty::OBD2_FREEZE_FRAME):
+    case OBD2_FREEZE_FRAME:
         v = pool.obtainComplex();
         *outStatus = fillObd2FreezeFrame(requestedPropValue, v.get());
         return v;
-    case V2_0::toInt(V2_1::VehicleProperty::OBD2_FREEZE_FRAME_INFO):
+    case OBD2_FREEZE_FRAME_INFO:
         v = pool.obtainComplex();
         *outStatus = fillObd2DtcInfo(v.get());
         return v;
     default:
-        return mVehicleHal20->get(requestedPropValue, outStatus);
+        return V2_0::impl::EmulatedVehicleHal::get(requestedPropValue, outStatus);
     }
 }
 
-V2_0::StatusCode DefaultVehicleHal::set(
-        const V2_0::VehiclePropValue& propValue) {
-
+V2_0::StatusCode EmulatedVehicleHal::set(const V2_0::VehiclePropValue& propValue) {
     auto propId = propValue.prop;
     switch (propId) {
-    case V2_0::toInt(V2_1::VehicleProperty::OBD2_FREEZE_FRAME_CLEAR):
+    case OBD2_FREEZE_FRAME_CLEAR:
         return clearObd2FreezeFrames(propValue);
-        break;
-    case V2_0::toInt(V2_1::VehicleProperty::VEHICLE_MAP_SERVICE):
+    case 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.
         return V2_0::StatusCode::OK;
-        break;
     default:
-        return mVehicleHal20->set(propValue);
+        return V2_0::impl::EmulatedVehicleHal::set(propValue);
     }
 }
 
diff --git a/automotive/vehicle/2.1/default/impl/vhal_v2_1/EmulatedVehicleHal.h b/automotive/vehicle/2.1/default/impl/vhal_v2_1/EmulatedVehicleHal.h
new file mode 100644
index 0000000..7cc3b79
--- /dev/null
+++ b/automotive/vehicle/2.1/default/impl/vhal_v2_1/EmulatedVehicleHal.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2016 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_1_impl_EmulatedVehicleHal_H_
+#define android_hardware_automotive_vehicle_V2_1_impl_EmulatedVehicleHal_H_
+
+#include <memory>
+
+#include <utils/SystemClock.h>
+
+#include <vhal_v2_0/EmulatedVehicleHal.h>
+#include <vhal_v2_0/VehicleHal.h>
+#include <vhal_v2_0/VehiclePropertyStore.h>
+#include <vhal_v2_1/Obd2SensorStore.h>
+
+#include "DefaultConfig.h"
+
+namespace android {
+namespace hardware {
+namespace automotive {
+namespace vehicle {
+namespace V2_1 {
+
+namespace impl {
+
+using namespace std::placeholders;
+
+class EmulatedVehicleHal : public V2_0::impl::EmulatedVehicleHal {
+public:
+    EmulatedVehicleHal(V2_0::VehiclePropertyStore* propStore)
+        : V2_0::impl::EmulatedVehicleHal(propStore), mPropStore(propStore) {
+        initStaticConfig();
+    }
+
+    VehiclePropValuePtr get(const V2_0::VehiclePropValue& requestedPropValue,
+                            V2_0::StatusCode* outStatus) override;
+
+    V2_0::StatusCode set(const V2_0::VehiclePropValue& propValue) override;
+
+    void onCreate() override;
+
+private:
+    void initStaticConfig();
+    void initObd2LiveFrame(const V2_0::VehiclePropConfig& propConfig);
+    void initObd2FreezeFrame(const V2_0::VehiclePropConfig& propConfig);
+    V2_0::StatusCode fillObd2FreezeFrame(const V2_0::VehiclePropValue& requestedPropValue,
+                                        V2_0::VehiclePropValue* outValue);
+    V2_0::StatusCode fillObd2DtcInfo(V2_0::VehiclePropValue *outValue);
+    V2_0::StatusCode clearObd2FreezeFrames(const V2_0::VehiclePropValue& propValue);
+
+private:
+    V2_0::VehiclePropertyStore* mPropStore;
+};
+
+}  // impl
+
+}  // namespace V2_1
+}  // namespace vehicle
+}  // namespace automotive
+}  // namespace hardware
+}  // namespace android
+
+
+#endif  // android_hardware_automotive_vehicle_V2_0_impl_EmulatedVehicleHal_H_
diff --git a/automotive/vehicle/2.1/default/service.cpp b/automotive/vehicle/2.1/default/service.cpp
index 0844622..4873279 100644
--- a/automotive/vehicle/2.1/default/service.cpp
+++ b/automotive/vehicle/2.1/default/service.cpp
@@ -23,9 +23,10 @@
 #include <android/hardware/automotive/vehicle/2.1/IVehicle.h>
 
 #include <vhal_v2_0/VehicleHalManager.h>
-#include <vhal_v2_0/DefaultVehicleHal.h>
+#include <vhal_v2_0/VehiclePropertyStore.h>
+#include <vhal_v2_0/EmulatedVehicleHal.h>
 
-#include <vhal_v2_1/DefaultVehicleHal.h>
+#include <vhal_v2_1/EmulatedVehicleHal.h>
 
 using namespace android;
 using namespace android::hardware;
@@ -80,10 +81,10 @@
 };
 
 int main(int /* argc */, char* /* argv */ []) {
-    auto halImpl20 = std::make_unique<V2_0::impl::DefaultVehicleHal>();
-    auto halImpl21 = std::make_unique<V2_1::impl::DefaultVehicleHal>(halImpl20.get());
-
-    auto vehicleManager = std::make_unique<V2_0::VehicleHalManager>(halImpl21.get());
+    auto store = std::make_unique<V2_0::VehiclePropertyStore>();
+    auto hal = std::make_unique<V2_1::impl::EmulatedVehicleHal>(store.get());
+    auto emulator = std::make_unique<V2_0::impl::VehicleEmulator>(hal.get());
+    auto vehicleManager = std::make_unique<V2_0::VehicleHalManager>(hal.get());
 
     Vehicle_V2_1 vehicle21(vehicleManager.get());