Avoid calling non-exist set_mode hal function
Add gating condition before calling the hal function pointers for
set_mode and inject_sensor_data.
Bug: 36073404
Test: compiles
Change-Id: I9c194c1a286fb64304b4329f43c3de2a3d6ae939
diff --git a/sensors/1.0/default/Sensors.cpp b/sensors/1.0/default/Sensors.cpp
index 2457310..1100dd6 100644
--- a/sensors/1.0/default/Sensors.cpp
+++ b/sensors/1.0/default/Sensors.cpp
@@ -97,6 +97,15 @@
// is considered optional.
CHECK_GE(getHalDeviceVersion(), SENSORS_DEVICE_API_VERSION_1_3);
+ if (getHalDeviceVersion() == SENSORS_DEVICE_API_VERSION_1_4) {
+ if (mSensorDevice->inject_sensor_data == nullptr) {
+ LOG(ERROR) << "HAL specifies version 1.4, but does not implement inject_sensor_data()";
+ }
+ if (mSensorModule->set_operation_mode == nullptr) {
+ LOG(ERROR) << "HAL specifies version 1.4, but does not implement set_operation_mode()";
+ }
+ }
+
mInitCheck = OK;
}
@@ -132,6 +141,10 @@
}
Return<Result> Sensors::setOperationMode(OperationMode mode) {
+ if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4
+ || mSensorModule->set_operation_mode == nullptr) {
+ return Result::INVALID_OPERATION;
+ }
return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode));
}
@@ -236,7 +249,8 @@
}
Return<Result> Sensors::injectSensorData(const Event& event) {
- if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4) {
+ if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4
+ || mSensorDevice->inject_sensor_data == nullptr) {
return Result::INVALID_OPERATION;
}