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

Commit 563322e6 authored by Peng Xu's avatar Peng Xu Committed by Android (Google) Code Review
Browse files

Merge "Add function to determine if SensorDevice support direct report"

parents 6cf6af02 5363254b
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -491,6 +491,11 @@ void SensorDevice::notifyConnectionDestroyed(void* ident) {
}
}


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

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

    Mutex::Autolock _l(mLock);
    Mutex::Autolock _l(mLock);


    int32_t channelHandle = mSensorDevice->register_direct_channel(
    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,
int32_t SensorDevice::configureDirectChannel(int32_t sensorHandle, int32_t channelHandle,
        const struct sensors_direct_cfg_t *config) {
        const struct sensors_direct_cfg_t *config) {

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

    Mutex::Autolock _l(mLock);
    Mutex::Autolock _l(mLock);


    int32_t ret = mSensorDevice->config_direct_report(
    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);
    ALOGE_IF(ret < 0, "SensorDevice::configureDirectChannel ret %d", ret);
    return ret;
    return ret;
}
}

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


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

    bool mIsDirectReportSupported;
#endif  // ENABLE_TREBLE
#endif  // ENABLE_TREBLE
};
};


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

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


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


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

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