From: Enrico Granata Date: Mon, 3 Apr 2017 19:59:00 +0000 (-0700) Subject: Fix an issue where Vehicle HAL would crash when trying to update a continuous propert... X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=5ecfdeacd96c28403ad3963de9b645140ec50c10;p=android-x86%2Fhardware-interfaces.git Fix an issue where Vehicle HAL would crash when trying to update a continuous property without an initial floating-point value Bug: 36858992 Test: build, flash and boot (cherry picked from commit 945d0bbc866ce21f262a1715c5a2560898c8aca1) Merged-In: I9906abbf386cf75e838102299e3e97de3475db63 Change-Id: I19ef534fde190a3a1adaca377e8f09760c0ccf4e --- diff --git a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h index 68f94dcd..b7ef8960 100644 --- a/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h +++ b/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h @@ -212,7 +212,7 @@ const ConfigDeclaration kVehicleProperties[] { .minSampleRate = 1.0f, .maxSampleRate = 2.0f, }, - .initialValue = { .int32Values = {25} } + .initialValue = { .floatValues = {25.0f} } }, { 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 d965afe4..e1749328 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 @@ -540,6 +540,12 @@ void DefaultVehicleHal::onContinuousPropertyTimer(const std::vector& pr if (VehiclePropertyType::FLOAT == getPropType(property)) { // Just get some randomness to continuous properties to see slightly differnt values // on the other end. + if (v->value.floatValues.size() == 0) { + ALOGW("continuous property 0x%x is of type float but does not have a" + " float value. defaulting to zero", + property); + v->value.floatValues = android::hardware::hidl_vec{0.0f}; + } v->value.floatValues[0] = v->value.floatValues[0] + std::rand() % 5; } } else {