From c8fd7b31e018633db2508d8b7775baa34a1675d4 Mon Sep 17 00:00:00 2001 From: karthik bharadwaj Date: Sun, 15 Nov 2020 20:50:06 -0800 Subject: [PATCH] Strip hinge angle sensor when running a 2.1 HAL as 2.0 VTS ensures that 2.0 HALs don't expose the hinge angle sensor, but the 2.1 HALs must run 2.0 VTS tests. This CL ensures that we don't expose the hinge angle sensor on the 2.0 HAL, to avoid failing those VTS tests. Bug: 173135479 Test: run vts -a x86 -m VtsHalSensorsV2_0TargetTest Change-Id: I944bfb0b01be0831e45cfd3d6ed7dab6770d1b80 --- sensors/2.0/default/SensorsV2_0.h | 13 +++++++++++++ sensors/2.1/default/SensorsV2_1.h | 19 ++++++++++++++++++- sensors/common/default/2.X/Sensors.h | 13 ------------- .../common/default/2.X/multihal/HalProxy.cpp | 2 ++ .../vts/2_X/VtsHalSensorsV2_XTargetTest.h | 2 +- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/sensors/2.0/default/SensorsV2_0.h b/sensors/2.0/default/SensorsV2_0.h index 345835a186..8270a352eb 100644 --- a/sensors/2.0/default/SensorsV2_0.h +++ b/sensors/2.0/default/SensorsV2_0.h @@ -28,6 +28,19 @@ namespace V2_0 { namespace implementation { struct SensorsV2_0 : public ::android::hardware::sensors::V2_X::implementation::Sensors { + Return + getSensorsList(V2_0::ISensors::getSensorsList_cb _hidl_cb) override { + std::vector sensors; + for (const auto &sensor : mSensors) { + sensors.push_back(V2_1::implementation::convertToOldSensorInfo( + sensor.second->getSensorInfo())); + } + + // Call the HIDL callback with the SensorInfo + _hidl_cb(sensors); + + return Void(); + } }; } // namespace implementation diff --git a/sensors/2.1/default/SensorsV2_1.h b/sensors/2.1/default/SensorsV2_1.h index 9f7fe04ff7..c748383a25 100644 --- a/sensors/2.1/default/SensorsV2_1.h +++ b/sensors/2.1/default/SensorsV2_1.h @@ -54,6 +54,23 @@ struct SensorsV2_1 : public Sensors { // Methods from ::android::hardware::sensors::V2_1::ISensors follow. Return getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb) override; + Return + getSensorsList(V2_0::ISensors::getSensorsList_cb _hidl_cb) override { + std::vector sensors; + for (const auto &sensor : mSensors) { + auto &info = sensor.second->getSensorInfo(); + if (info.type != SensorType::HINGE_ANGLE) { + sensors.push_back(V2_1::implementation::convertToOldSensorInfo( + sensor.second->getSensorInfo())); + } + } + + // Call the HIDL callback with the SensorInfo + _hidl_cb(sensors); + + return Void(); + } + Return initialize_2_1( const ::android::hardware::MQDescriptorSync& eventQueueDescriptor, const ::android::hardware::MQDescriptorSync& wakeLockDescriptor, @@ -71,4 +88,4 @@ struct SensorsV2_1 : public Sensors { } // namespace hardware } // namespace android -#endif // ANDROID_HARDWARE_SENSORS_V2_1_H \ No newline at end of file +#endif // ANDROID_HARDWARE_SENSORS_V2_1_H diff --git a/sensors/common/default/2.X/Sensors.h b/sensors/common/default/2.X/Sensors.h index 8969c0f5fd..1124425f99 100644 --- a/sensors/common/default/2.X/Sensors.h +++ b/sensors/common/default/2.X/Sensors.h @@ -78,19 +78,6 @@ struct Sensors : public ISensorsInterface, public ISensorsEventCallback { } // Methods from ::android::hardware::sensors::V2_0::ISensors follow. - Return getSensorsList(V2_0::ISensors::getSensorsList_cb _hidl_cb) override { - std::vector sensors; - for (const auto& sensor : mSensors) { - sensors.push_back( - V2_1::implementation::convertToOldSensorInfo(sensor.second->getSensorInfo())); - } - - // Call the HIDL callback with the SensorInfo - _hidl_cb(sensors); - - return Void(); - } - Return setOperationMode(OperationMode mode) override { for (auto sensor : mSensors) { sensor.second->setOperationMode(mode); diff --git a/sensors/common/default/2.X/multihal/HalProxy.cpp b/sensors/common/default/2.X/multihal/HalProxy.cpp index 4527c75e31..650d7dccb5 100644 --- a/sensors/common/default/2.X/multihal/HalProxy.cpp +++ b/sensors/common/default/2.X/multihal/HalProxy.cpp @@ -124,7 +124,9 @@ Return HalProxy::getSensorsList_2_1(ISensorsV2_1::getSensorsList_2_1_cb _h Return HalProxy::getSensorsList(ISensorsV2_0::getSensorsList_cb _hidl_cb) { std::vector sensors; for (const auto& iter : mSensors) { + if (iter.second.type != SensorType::HINGE_ANGLE) { sensors.push_back(convertToOldSensorInfo(iter.second)); + } } _hidl_cb(sensors); return Void(); diff --git a/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h b/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h index f85782782e..8cf5003f91 100644 --- a/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h +++ b/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h @@ -366,7 +366,7 @@ int32_t SensorsHidlTest::getInvalidSensorHandle() { for (const SensorInfoType& sensor : getSensorsList()) { maxHandle = std::max(maxHandle, sensor.sensorHandle); } - return maxHandle + 1; + return maxHandle + 42; } // Test if sensor list returned is valid