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

Commit 5363254b authored by Peng Xu's avatar Peng Xu
Browse files

Add function to determine if SensorDevice support direct report

Added a function to SensorDevice to indicate if direct report is
supported. This avoided a crash condition in non-HIDL implementation.

Test: test with demo app on a HAL w/ and w/o direct report support
Change-Id: If68497bb8890b9e6003c2afeec38d16daf81f237
parent 2d7a1261
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -491,6 +491,11 @@ void SensorDevice::notifyConnectionDestroyed(void* ident) {
}

int32_t SensorDevice::registerDirectChannel(const sensors_direct_mem_t* memory) {

    if (!isDirectReportSupported()) {
        return INVALID_OPERATION;
    }

    Mutex::Autolock _l(mLock);

    int32_t channelHandle = mSensorDevice->register_direct_channel(
@@ -506,6 +511,11 @@ void SensorDevice::unregisterDirectChannel(int32_t channelHandle) {

int32_t SensorDevice::configureDirectChannel(int32_t sensorHandle, int32_t channelHandle,
        const struct sensors_direct_cfg_t *config) {

    if (!isDirectReportSupported()) {
        return INVALID_OPERATION;
    }

    Mutex::Autolock _l(mLock);

    int32_t ret = mSensorDevice->config_direct_report(
@@ -513,6 +523,12 @@ int32_t SensorDevice::configureDirectChannel(int32_t sensorHandle, int32_t chann
    ALOGE_IF(ret < 0, "SensorDevice::configureDirectChannel ret %d", ret);
    return ret;
}

bool SensorDevice::isDirectReportSupported() const {
    bool ret = mSensorDevice->register_direct_channel != nullptr
            && mSensorDevice->config_direct_report != nullptr;
    return ret;
}
// ---------------------------------------------------------------------------
}; // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ public:
    status_t flush(void* ident, int handle);
    status_t setMode(uint32_t mode);

    bool isDirectReportSupported() const;
    int32_t registerDirectChannel(const sensors_direct_mem_t *memory);
    void unregisterDirectChannel(int32_t channelHandle);
    int32_t configureDirectChannel(int32_t sensorHandle,
@@ -147,6 +148,8 @@ private:
            const hardware::hidl_vec<Event> &src,
            const hardware::hidl_vec<SensorInfo> &dynamicSensorsAdded,
            sensors_event_t *dst);

    bool mIsDirectReportSupported;
#endif  // ENABLE_TREBLE
};

+7 −0
Original line number Diff line number Diff line
@@ -77,6 +77,9 @@ SensorDevice::SensorDevice() {
                    mSensors->activate(list[i].sensorHandle, 0 /* enabled */);
                }
            });

    mIsDirectReportSupported =
           (mSensors->unregisterDirectChannel(-1) != Result::INVALID_OPERATION);
}

void SensorDevice::handleDynamicSensorConnection(int handle, bool connected) {
@@ -581,6 +584,10 @@ int32_t SensorDevice::configureDirectChannel(int32_t sensorHandle,
    return ret;
}

bool SensorDevice::isDirectReportSupported() const {
    return mIsDirectReportSupported;
}

void SensorDevice::convertToSensorEvent(
        const Event &src, sensors_event_t *dst) {
    ::android::hardware::sensors::V1_0::implementation::convertToSensorEvent(