Loading automotive/can/1.0/default/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -64,4 +64,5 @@ cc_binary { "android.hardware.automotive@libc++fs", "libnl++", ], vintf_fragments: ["manifest_android.hardware.automotive.can@1.0.xml"], } automotive/can/1.0/default/manifest_android.hardware.automotive.can@1.0.xml 0 → 100644 +22 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (C) 2020 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. --> <manifest version="1.0" type="device" > <hal format="hidl"> <name>android.hardware.automotive.can</name> <transport>hwbinder</transport> <fqname>@1.0::ICanController/socketcan</fqname> </hal> </manifest> automotive/vehicle/aidl/impl/fake_impl/hardware/Android.bp +7 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,12 @@ cc_library { "VehicleHalDefaultConfig", ], export_header_lib_headers: ["IVehicleHardware"], static_libs: ["VehicleHalUtils"], static_libs: [ "VehicleHalUtils", "FakeVehicleHalValueGenerators", ], shared_libs: [ "libjsoncpp", ], export_static_lib_headers: ["VehicleHalUtils"], } automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h +14 −4 Original line number Diff line number Diff line Loading @@ -82,10 +82,8 @@ class FakeVehicleHardware final : public IVehicleHardware { void registerOnPropertySetErrorEvent(OnPropertySetErrorCallback&& callback) override; private: void storePropInitialValue(const defaultconfig::ConfigDeclaration& config); void init(std::shared_ptr<VehiclePropValuePool> valuePool); void onValueChangeCallback( const ::aidl::android::hardware::automotive::vehicle::VehiclePropValue& value); // Expose private methods to unit test. friend class FakeVehicleHardwareTestHelper; std::unique_ptr<VehiclePropertyStore> mServerSidePropStore; // mValuePool is also used in mServerSidePropStore. Loading @@ -93,6 +91,18 @@ class FakeVehicleHardware final : public IVehicleHardware { std::mutex mCallbackLock; OnPropertyChangeCallback mOnPropertyChangeCallback GUARDED_BY(mCallbackLock); OnPropertySetErrorCallback mOnPropertySetErrorCallback GUARDED_BY(mCallbackLock); void init(std::shared_ptr<VehiclePropValuePool> valuePool); // Stores the initial value to property store. void storePropInitialValue(const defaultconfig::ConfigDeclaration& config); // The callback that would be called when a vehicle property value change happens. void onValueChangeCallback( const ::aidl::android::hardware::automotive::vehicle::VehiclePropValue& value); // If property "persist.vendor.vhal_init_value_override" is set to true, override the properties // using config files in 'overrideDir'. void maybeOverrideProperties(const char* overrideDir); // Override the properties using config files in 'overrideDir'. void overrideProperties(const char* overrideDir); }; } // namespace fake Loading automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp +48 −0 Original line number Diff line number Diff line Loading @@ -17,11 +17,17 @@ #include "FakeVehicleHardware.h" #include <DefaultConfig.h> #include <JsonFakeValueGenerator.h> #include <VehicleHalTypes.h> #include <VehicleUtils.h> #include <android-base/properties.h> #include <utils/Log.h> #include <utils/SystemClock.h> #include <dirent.h> #include <sys/types.h> #include <fstream> #include <regex> #include <vector> namespace android { Loading @@ -30,6 +36,8 @@ namespace automotive { namespace vehicle { namespace fake { namespace { using ::aidl::android::hardware::automotive::vehicle::GetValueRequest; using ::aidl::android::hardware::automotive::vehicle::GetValueResult; using ::aidl::android::hardware::automotive::vehicle::RawPropValues; Loading @@ -40,6 +48,11 @@ using ::aidl::android::hardware::automotive::vehicle::VehiclePropConfig; using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyStatus; using ::aidl::android::hardware::automotive::vehicle::VehiclePropValue; const char* VENDOR_OVERRIDE_DIR = "/vendor/etc/automotive/vhaloverride/"; const char* OVERRIDE_PROPERTY = "persist.vendor.vhal_init_value_override"; } // namespace void FakeVehicleHardware::storePropInitialValue(const defaultconfig::ConfigDeclaration& config) { const VehiclePropConfig& vehiclePropConfig = config.config; int propId = vehiclePropConfig.prop; Loading Loading @@ -99,6 +112,8 @@ void FakeVehicleHardware::init(std::shared_ptr<VehiclePropValuePool> valuePool) storePropInitialValue(it); } maybeOverrideProperties(VENDOR_OVERRIDE_DIR); mServerSidePropStore->setOnValueChangeCallback( [this](const VehiclePropValue& value) { return onValueChangeCallback(value); }); } Loading Loading @@ -201,6 +216,39 @@ void FakeVehicleHardware::onValueChangeCallback(const VehiclePropValue& value) { } } void FakeVehicleHardware::maybeOverrideProperties(const char* overrideDir) { if (android::base::GetBoolProperty(OVERRIDE_PROPERTY, false)) { overrideProperties(overrideDir); } } void FakeVehicleHardware::overrideProperties(const char* overrideDir) { ALOGI("loading vendor override properties from %s", overrideDir); if (auto dir = opendir(overrideDir); dir != NULL) { std::regex regJson(".*[.]json", std::regex::icase); while (auto f = readdir(dir)) { if (!std::regex_match(f->d_name, regJson)) { continue; } std::string file = overrideDir + std::string(f->d_name); JsonFakeValueGenerator tmpGenerator(file); std::vector<VehiclePropValue> propValues = tmpGenerator.getAllEvents(); for (const VehiclePropValue& prop : propValues) { auto propToStore = mValuePool->obtain(prop); propToStore->timestamp = elapsedRealtimeNano(); if (auto result = mServerSidePropStore->writeValue(std::move(propToStore), /*updateStatus=*/true); !result.ok()) { ALOGW("failed to write vendor override properties: %d, error: %s", prop.prop, result.error().message().c_str()); } } } closedir(dir); } } } // namespace fake } // namespace vehicle } // namespace automotive Loading Loading
automotive/can/1.0/default/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -64,4 +64,5 @@ cc_binary { "android.hardware.automotive@libc++fs", "libnl++", ], vintf_fragments: ["manifest_android.hardware.automotive.can@1.0.xml"], }
automotive/can/1.0/default/manifest_android.hardware.automotive.can@1.0.xml 0 → 100644 +22 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (C) 2020 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. --> <manifest version="1.0" type="device" > <hal format="hidl"> <name>android.hardware.automotive.can</name> <transport>hwbinder</transport> <fqname>@1.0::ICanController/socketcan</fqname> </hal> </manifest>
automotive/vehicle/aidl/impl/fake_impl/hardware/Android.bp +7 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,12 @@ cc_library { "VehicleHalDefaultConfig", ], export_header_lib_headers: ["IVehicleHardware"], static_libs: ["VehicleHalUtils"], static_libs: [ "VehicleHalUtils", "FakeVehicleHalValueGenerators", ], shared_libs: [ "libjsoncpp", ], export_static_lib_headers: ["VehicleHalUtils"], }
automotive/vehicle/aidl/impl/fake_impl/hardware/include/FakeVehicleHardware.h +14 −4 Original line number Diff line number Diff line Loading @@ -82,10 +82,8 @@ class FakeVehicleHardware final : public IVehicleHardware { void registerOnPropertySetErrorEvent(OnPropertySetErrorCallback&& callback) override; private: void storePropInitialValue(const defaultconfig::ConfigDeclaration& config); void init(std::shared_ptr<VehiclePropValuePool> valuePool); void onValueChangeCallback( const ::aidl::android::hardware::automotive::vehicle::VehiclePropValue& value); // Expose private methods to unit test. friend class FakeVehicleHardwareTestHelper; std::unique_ptr<VehiclePropertyStore> mServerSidePropStore; // mValuePool is also used in mServerSidePropStore. Loading @@ -93,6 +91,18 @@ class FakeVehicleHardware final : public IVehicleHardware { std::mutex mCallbackLock; OnPropertyChangeCallback mOnPropertyChangeCallback GUARDED_BY(mCallbackLock); OnPropertySetErrorCallback mOnPropertySetErrorCallback GUARDED_BY(mCallbackLock); void init(std::shared_ptr<VehiclePropValuePool> valuePool); // Stores the initial value to property store. void storePropInitialValue(const defaultconfig::ConfigDeclaration& config); // The callback that would be called when a vehicle property value change happens. void onValueChangeCallback( const ::aidl::android::hardware::automotive::vehicle::VehiclePropValue& value); // If property "persist.vendor.vhal_init_value_override" is set to true, override the properties // using config files in 'overrideDir'. void maybeOverrideProperties(const char* overrideDir); // Override the properties using config files in 'overrideDir'. void overrideProperties(const char* overrideDir); }; } // namespace fake Loading
automotive/vehicle/aidl/impl/fake_impl/hardware/src/FakeVehicleHardware.cpp +48 −0 Original line number Diff line number Diff line Loading @@ -17,11 +17,17 @@ #include "FakeVehicleHardware.h" #include <DefaultConfig.h> #include <JsonFakeValueGenerator.h> #include <VehicleHalTypes.h> #include <VehicleUtils.h> #include <android-base/properties.h> #include <utils/Log.h> #include <utils/SystemClock.h> #include <dirent.h> #include <sys/types.h> #include <fstream> #include <regex> #include <vector> namespace android { Loading @@ -30,6 +36,8 @@ namespace automotive { namespace vehicle { namespace fake { namespace { using ::aidl::android::hardware::automotive::vehicle::GetValueRequest; using ::aidl::android::hardware::automotive::vehicle::GetValueResult; using ::aidl::android::hardware::automotive::vehicle::RawPropValues; Loading @@ -40,6 +48,11 @@ using ::aidl::android::hardware::automotive::vehicle::VehiclePropConfig; using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyStatus; using ::aidl::android::hardware::automotive::vehicle::VehiclePropValue; const char* VENDOR_OVERRIDE_DIR = "/vendor/etc/automotive/vhaloverride/"; const char* OVERRIDE_PROPERTY = "persist.vendor.vhal_init_value_override"; } // namespace void FakeVehicleHardware::storePropInitialValue(const defaultconfig::ConfigDeclaration& config) { const VehiclePropConfig& vehiclePropConfig = config.config; int propId = vehiclePropConfig.prop; Loading Loading @@ -99,6 +112,8 @@ void FakeVehicleHardware::init(std::shared_ptr<VehiclePropValuePool> valuePool) storePropInitialValue(it); } maybeOverrideProperties(VENDOR_OVERRIDE_DIR); mServerSidePropStore->setOnValueChangeCallback( [this](const VehiclePropValue& value) { return onValueChangeCallback(value); }); } Loading Loading @@ -201,6 +216,39 @@ void FakeVehicleHardware::onValueChangeCallback(const VehiclePropValue& value) { } } void FakeVehicleHardware::maybeOverrideProperties(const char* overrideDir) { if (android::base::GetBoolProperty(OVERRIDE_PROPERTY, false)) { overrideProperties(overrideDir); } } void FakeVehicleHardware::overrideProperties(const char* overrideDir) { ALOGI("loading vendor override properties from %s", overrideDir); if (auto dir = opendir(overrideDir); dir != NULL) { std::regex regJson(".*[.]json", std::regex::icase); while (auto f = readdir(dir)) { if (!std::regex_match(f->d_name, regJson)) { continue; } std::string file = overrideDir + std::string(f->d_name); JsonFakeValueGenerator tmpGenerator(file); std::vector<VehiclePropValue> propValues = tmpGenerator.getAllEvents(); for (const VehiclePropValue& prop : propValues) { auto propToStore = mValuePool->obtain(prop); propToStore->timestamp = elapsedRealtimeNano(); if (auto result = mServerSidePropStore->writeValue(std::move(propToStore), /*updateStatus=*/true); !result.ok()) { ALOGW("failed to write vendor override properties: %d, error: %s", prop.prop, result.error().message().c_str()); } } } closedir(dir); } } } // namespace fake } // namespace vehicle } // namespace automotive Loading