Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20c7ece3 authored by Peng Xu's avatar Peng Xu
Browse files

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
parent dc314a30
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -97,6 +97,15 @@ Sensors::Sensors()
    // 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 @@ int Sensors::getHalDeviceVersion() const {
}

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::flush(int32_t sensor_handle) {
}

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;
    }