diff --git a/hidl/sensors/1.0/.clang-format b/hidl/sensors/1.0/.clang-format new file mode 120000 index 0000000..f1b4f69 --- /dev/null +++ b/hidl/sensors/1.0/.clang-format @@ -0,0 +1 @@ +../../../../../build/soong/scripts/system-clang-format \ No newline at end of file diff --git a/hidl/sensors/1.0/Sensors.cpp b/hidl/sensors/1.0/Sensors.cpp index 1100dd6..ad90e21 100644 --- a/hidl/sensors/1.0/Sensors.cpp +++ b/hidl/sensors/1.0/Sensors.cpp @@ -35,7 +35,7 @@ namespace implementation { static bool UseMultiHal() { const std::string& name = MULTI_HAL_CONFIG_FILE_PATH; struct stat buffer; - return (stat (name.c_str(), &buffer) == 0); + return (stat(name.c_str(), &buffer) == 0); } static Result ResultFromStatus(status_t err) { @@ -53,28 +53,20 @@ static Result ResultFromStatus(status_t err) { } } -Sensors::Sensors() - : mInitCheck(NO_INIT), - mSensorModule(nullptr), - mSensorDevice(nullptr) { +Sensors::Sensors() : mInitCheck(NO_INIT), mSensorModule(nullptr), mSensorDevice(nullptr) { status_t err = OK; if (UseMultiHal()) { mSensorModule = ::get_multi_hal_module_info(); } else { - err = hw_get_module( - SENSORS_HARDWARE_MODULE_ID, - (hw_module_t const **)&mSensorModule); + err = hw_get_module(SENSORS_HARDWARE_MODULE_ID, (hw_module_t const**)&mSensorModule); } if (mSensorModule == NULL) { err = UNKNOWN_ERROR; } if (err != OK) { - LOG(ERROR) << "Couldn't load " - << SENSORS_HARDWARE_MODULE_ID - << " module (" - << strerror(-err) - << ")"; + LOG(ERROR) << "Couldn't load " << SENSORS_HARDWARE_MODULE_ID << " module (" + << strerror(-err) << ")"; mInitCheck = err; return; @@ -83,11 +75,8 @@ Sensors::Sensors() err = sensors_open_1(&mSensorModule->common, &mSensorDevice); if (err != OK) { - LOG(ERROR) << "Couldn't open device for module " - << SENSORS_HARDWARE_MODULE_ID - << " (" - << strerror(-err) - << ")"; + LOG(ERROR) << "Couldn't open device for module " << SENSORS_HARDWARE_MODULE_ID << " (" + << strerror(-err) << ")"; mInitCheck = err; return; @@ -114,15 +103,15 @@ status_t Sensors::initCheck() const { } Return Sensors::getSensorsList(getSensorsList_cb _hidl_cb) { - sensor_t const *list; + sensor_t const* list; size_t count = mSensorModule->get_sensors_list(mSensorModule, &list); hidl_vec out; out.resize(count); for (size_t i = 0; i < count; ++i) { - const sensor_t *src = &list[i]; - SensorInfo *dst = &out[i]; + const sensor_t* src = &list[i]; + SensorInfo* dst = &out[i]; convertFromSensor(*src, dst); } @@ -141,31 +130,26 @@ int Sensors::getHalDeviceVersion() const { } Return Sensors::setOperationMode(OperationMode mode) { - if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 - || mSensorModule->set_operation_mode == nullptr) { + 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)); } -Return Sensors::activate( - int32_t sensor_handle, bool enabled) { - return ResultFromStatus( - mSensorDevice->activate( - reinterpret_cast(mSensorDevice), - sensor_handle, - enabled)); +Return Sensors::activate(int32_t sensor_handle, bool enabled) { + return ResultFromStatus(mSensorDevice->activate( + reinterpret_cast(mSensorDevice), sensor_handle, enabled)); } Return Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { - hidl_vec out; hidl_vec dynamicSensorsAdded; std::unique_ptr data; int err = android::NO_ERROR; - { // scope of reentry lock + { // scope of reentry lock // This enforces a single client, meaning that a maximum of one client can call poll(). // If this function is re-entred, it means that we are stuck in a state that may prevent @@ -175,11 +159,11 @@ Return Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { // // This function must not call _hidl_cb(...) or return until there is no risk of blocking. std::unique_lock lock(mPollLock, std::try_to_lock); - if(!lock.owns_lock()){ + if (!lock.owns_lock()) { // cannot get the lock, hidl service will go into deadlock if it is not restarted. // This is guaranteed to not trigger in passthrough mode. - LOG(ERROR) << - "ISensors::poll() re-entry. I do not know what to do except killing myself."; + LOG(ERROR) + << "ISensors::poll() re-entry. I do not know what to do except killing myself."; ::exit(-1); } @@ -188,9 +172,8 @@ Return Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { } else { int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize; data.reset(new sensors_event_t[bufferSize]); - err = mSensorDevice->poll( - reinterpret_cast(mSensorDevice), - data.get(), bufferSize); + err = mSensorDevice->poll(reinterpret_cast(mSensorDevice), + data.get(), bufferSize); } } @@ -206,7 +189,7 @@ Return Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { continue; } - const dynamic_sensor_meta_event_t *dyn = &data[i].dynamic_sensor_meta; + const dynamic_sensor_meta_event_t* dyn = &data[i].dynamic_sensor_meta; if (!dyn->connected) { continue; @@ -231,17 +214,10 @@ Return Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) { return Void(); } -Return Sensors::batch( - int32_t sensor_handle, - int64_t sampling_period_ns, - int64_t max_report_latency_ns) { - return ResultFromStatus( - mSensorDevice->batch( - mSensorDevice, - sensor_handle, - 0, /*flags*/ - sampling_period_ns, - max_report_latency_ns)); +Return Sensors::batch(int32_t sensor_handle, int64_t sampling_period_ns, + int64_t max_report_latency_ns) { + return ResultFromStatus(mSensorDevice->batch(mSensorDevice, sensor_handle, 0, /*flags*/ + sampling_period_ns, max_report_latency_ns)); } Return Sensors::flush(int32_t sensor_handle) { @@ -249,22 +225,21 @@ Return Sensors::flush(int32_t sensor_handle) { } Return Sensors::injectSensorData(const Event& event) { - if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 - || mSensorDevice->inject_sensor_data == nullptr) { + if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 || + mSensorDevice->inject_sensor_data == nullptr) { return Result::INVALID_OPERATION; } sensors_event_t out; convertToSensorEvent(event, &out); - return ResultFromStatus( - mSensorDevice->inject_sensor_data(mSensorDevice, &out)); + return ResultFromStatus(mSensorDevice->inject_sensor_data(mSensorDevice, &out)); } -Return Sensors::registerDirectChannel( - const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) { - if (mSensorDevice->register_direct_channel == nullptr - || mSensorDevice->config_direct_report == nullptr) { +Return Sensors::registerDirectChannel(const SharedMemInfo& mem, + registerDirectChannel_cb _hidl_cb) { + if (mSensorDevice->register_direct_channel == nullptr || + mSensorDevice->config_direct_report == nullptr) { // HAL does not support _hidl_cb(Result::INVALID_OPERATION, -1); return Void(); @@ -272,8 +247,8 @@ Return Sensors::registerDirectChannel( sensors_direct_mem_t m; if (!convertFromSharedMemInfo(mem, &m)) { - _hidl_cb(Result::BAD_VALUE, -1); - return Void(); + _hidl_cb(Result::BAD_VALUE, -1); + return Void(); } int err = mSensorDevice->register_direct_channel(mSensorDevice, &m, -1); @@ -288,8 +263,8 @@ Return Sensors::registerDirectChannel( } Return Sensors::unregisterDirectChannel(int32_t channelHandle) { - if (mSensorDevice->register_direct_channel == nullptr - || mSensorDevice->config_direct_report == nullptr) { + if (mSensorDevice->register_direct_channel == nullptr || + mSensorDevice->config_direct_report == nullptr) { // HAL does not support return Result::INVALID_OPERATION; } @@ -299,26 +274,22 @@ Return Sensors::unregisterDirectChannel(int32_t channelHandle) { return Result::OK; } -Return Sensors::configDirectReport( - int32_t sensorHandle, int32_t channelHandle, RateLevel rate, - configDirectReport_cb _hidl_cb) { - if (mSensorDevice->register_direct_channel == nullptr - || mSensorDevice->config_direct_report == nullptr) { +Return Sensors::configDirectReport(int32_t sensorHandle, int32_t channelHandle, + RateLevel rate, configDirectReport_cb _hidl_cb) { + if (mSensorDevice->register_direct_channel == nullptr || + mSensorDevice->config_direct_report == nullptr) { // HAL does not support _hidl_cb(Result::INVALID_OPERATION, -1); return Void(); } - sensors_direct_cfg_t cfg = { - .rate_level = convertFromRateLevel(rate) - }; + sensors_direct_cfg_t cfg = {.rate_level = convertFromRateLevel(rate)}; if (cfg.rate_level < 0) { _hidl_cb(Result::BAD_VALUE, -1); return Void(); } - int err = mSensorDevice->config_direct_report(mSensorDevice, - sensorHandle, channelHandle, &cfg); + int err = mSensorDevice->config_direct_report(mSensorDevice, sensorHandle, channelHandle, &cfg); if (rate == RateLevel::STOP) { _hidl_cb(ResultFromStatus(err), -1); @@ -329,20 +300,18 @@ Return Sensors::configDirectReport( } // static -void Sensors::convertFromSensorEvents( - size_t count, - const sensors_event_t *srcArray, - hidl_vec *dstVec) { +void Sensors::convertFromSensorEvents(size_t count, const sensors_event_t* srcArray, + hidl_vec* dstVec) { for (size_t i = 0; i < count; ++i) { - const sensors_event_t &src = srcArray[i]; - Event *dst = &(*dstVec)[i]; + const sensors_event_t& src = srcArray[i]; + Event* dst = &(*dstVec)[i]; convertFromSensorEvent(src, dst); } } -ISensors *HIDL_FETCH_ISensors(const char * /* hal */) { - Sensors *sensors = new Sensors; +ISensors* HIDL_FETCH_ISensors(const char* /* hal */) { + Sensors* sensors = new Sensors; if (sensors->initCheck() != OK) { delete sensors; sensors = nullptr; diff --git a/hidl/sensors/1.0/Sensors.h b/hidl/sensors/1.0/Sensors.h index be00a96..8a24f86 100644 --- a/hidl/sensors/1.0/Sensors.h +++ b/hidl/sensors/1.0/Sensors.h @@ -29,7 +29,6 @@ namespace sensors { namespace V1_0 { namespace implementation { - struct Sensors : public ::android::hardware::sensors::V1_0::ISensors { Sensors(); @@ -39,45 +38,41 @@ struct Sensors : public ::android::hardware::sensors::V1_0::ISensors { Return setOperationMode(OperationMode mode) override; - Return activate( - int32_t sensor_handle, bool enabled) override; + Return activate(int32_t sensor_handle, bool enabled) override; Return poll(int32_t maxCount, poll_cb _hidl_cb) override; - Return batch( - int32_t sensor_handle, - int64_t sampling_period_ns, - int64_t max_report_latency_ns) override; + Return batch(int32_t sensor_handle, int64_t sampling_period_ns, + int64_t max_report_latency_ns) override; Return flush(int32_t sensor_handle) override; Return injectSensorData(const Event& event) override; - Return registerDirectChannel( - const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override; + Return registerDirectChannel(const SharedMemInfo& mem, + registerDirectChannel_cb _hidl_cb) override; Return unregisterDirectChannel(int32_t channelHandle) override; - Return configDirectReport( - int32_t sensorHandle, int32_t channelHandle, RateLevel rate, - configDirectReport_cb _hidl_cb) override; + Return configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate, + configDirectReport_cb _hidl_cb) override; -private: + private: static constexpr int32_t kPollMaxBufferSize = 128; status_t mInitCheck; - sensors_module_t *mSensorModule; - sensors_poll_device_1_t *mSensorDevice; + sensors_module_t* mSensorModule; + sensors_poll_device_1_t* mSensorDevice; std::mutex mPollLock; int getHalDeviceVersion() const; - static void convertFromSensorEvents( - size_t count, const sensors_event_t *src, hidl_vec *dst); + static void convertFromSensorEvents(size_t count, const sensors_event_t* src, + hidl_vec* dst); DISALLOW_COPY_AND_ASSIGN(Sensors); }; -extern "C" ISensors *HIDL_FETCH_ISensors(const char *name); +extern "C" ISensors* HIDL_FETCH_ISensors(const char* name); } // namespace implementation } // namespace V1_0 diff --git a/hidl/sensors/1.0/convert.cpp b/hidl/sensors/1.0/convert.cpp index 43ee327..6b1be27 100644 --- a/hidl/sensors/1.0/convert.cpp +++ b/hidl/sensors/1.0/convert.cpp @@ -24,7 +24,7 @@ namespace sensors { namespace V1_0 { namespace implementation { -void convertFromSensor(const sensor_t &src, SensorInfo *dst) { +void convertFromSensor(const sensor_t& src, SensorInfo* dst) { dst->name = src.name; dst->vendor = src.vendor; dst->version = src.version; @@ -42,9 +42,7 @@ void convertFromSensor(const sensor_t &src, SensorInfo *dst) { dst->flags = src.flags; } -void convertToSensor( - const ::android::hardware::sensors::V1_0::SensorInfo &src, - sensor_t *dst) { +void convertToSensor(const ::android::hardware::sensors::V1_0::SensorInfo& src, sensor_t* dst) { dst->name = strdup(src.name.c_str()); dst->vendor = strdup(src.vendor.c_str()); dst->version = src.version; @@ -63,7 +61,7 @@ void convertToSensor( dst->reserved[0] = dst->reserved[1] = 0; } -void convertFromSensorEvent(const sensors_event_t &src, Event *dst) { +void convertFromSensorEvent(const sensors_event_t& src, Event* dst) { typedef ::android::hardware::sensors::V1_0::SensorType SensorType; typedef ::android::hardware::sensors::V1_0::MetaDataEventType MetaDataEventType; @@ -196,7 +194,7 @@ void convertFromSensorEvent(const sensors_event_t &src, Event *dst) { } } -void convertToSensorEvent(const Event &src, sensors_event_t *dst) { +void convertToSensorEvent(const Event& src, sensors_event_t* dst) { *dst = {.version = sizeof(sensors_event_t), .sensor = src.sensorHandle, .type = (int32_t)src.sensorType, @@ -247,8 +245,7 @@ void convertToSensorEvent(const Event &src, sensors_event_t *dst) { case SensorType::MAGNETIC_FIELD_UNCALIBRATED: case SensorType::GYROSCOPE_UNCALIBRATED: - case SensorType::ACCELEROMETER_UNCALIBRATED: - { + case SensorType::ACCELEROMETER_UNCALIBRATED: { dst->uncalibrated_gyro.x_uncalib = src.u.uncal.x; dst->uncalibrated_gyro.y_uncalib = src.u.uncal.y; dst->uncalibrated_gyro.z_uncalib = src.u.uncal.z; @@ -303,26 +300,21 @@ void convertToSensorEvent(const Event &src, sensors_event_t *dst) { dst->dynamic_sensor_meta.handle = src.u.dynamic.sensorHandle; dst->dynamic_sensor_meta.sensor = NULL; // to be filled in later - memcpy(dst->dynamic_sensor_meta.uuid, - src.u.dynamic.uuid.data(), - 16); + memcpy(dst->dynamic_sensor_meta.uuid, src.u.dynamic.uuid.data(), 16); break; } case SensorType::ADDITIONAL_INFO: { - const ::android::hardware::sensors::V1_0::AdditionalInfo &srcInfo = - src.u.additional; + const ::android::hardware::sensors::V1_0::AdditionalInfo& srcInfo = src.u.additional; - additional_info_event_t *dstInfo = &dst->additional_info; + additional_info_event_t* dstInfo = &dst->additional_info; dstInfo->type = (int32_t)srcInfo.type; dstInfo->serial = srcInfo.serial; CHECK_EQ(sizeof(srcInfo.u), sizeof(dstInfo->data_int32)); - memcpy(dstInfo->data_int32, - &srcInfo.u, - sizeof(dstInfo->data_int32)); + memcpy(dstInfo->data_int32, &srcInfo.u, sizeof(dstInfo->data_int32)); break; } @@ -334,12 +326,12 @@ void convertToSensorEvent(const Event &src, sensors_event_t *dst) { } } -bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t *memOut) { +bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t* memOut) { if (memOut == nullptr) { return false; } - switch(memIn.type) { + switch (memIn.type) { case SharedMemType::ASHMEM: memOut->type = SENSOR_DIRECT_MEM_TYPE_ASHMEM; break; @@ -350,7 +342,7 @@ bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t * return false; } - switch(memIn.format) { + switch (memIn.format) { case SharedMemFormat::SENSORS_EVENT: memOut->format = SENSOR_DIRECT_FMT_SENSORS_EVENT; break; @@ -368,7 +360,7 @@ bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t * } int convertFromRateLevel(RateLevel rate) { - switch(rate) { + switch (rate) { case RateLevel::STOP: return SENSOR_DIRECT_RATE_STOP; case RateLevel::NORMAL: @@ -387,4 +379,3 @@ int convertFromRateLevel(RateLevel rate) { } // namespace sensors } // namespace hardware } // namespace android - diff --git a/hidl/sensors/1.0/include/sensors/convert.h b/hidl/sensors/1.0/include/sensors/convert.h index c3a0125..25758a4 100644 --- a/hidl/sensors/1.0/include/sensors/convert.h +++ b/hidl/sensors/1.0/include/sensors/convert.h @@ -27,13 +27,13 @@ namespace sensors { namespace V1_0 { namespace implementation { -void convertFromSensor(const sensor_t &src, SensorInfo *dst); -void convertToSensor(const SensorInfo &src, sensor_t *dst); +void convertFromSensor(const sensor_t& src, SensorInfo* dst); +void convertToSensor(const SensorInfo& src, sensor_t* dst); -void convertFromSensorEvent(const sensors_event_t &src, Event *dst); -void convertToSensorEvent(const Event &src, sensors_event_t *dst); +void convertFromSensorEvent(const sensors_event_t& src, Event* dst); +void convertToSensorEvent(const Event& src, sensors_event_t* dst); -bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t *memOut); +bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t* memOut); int convertFromRateLevel(RateLevel rate); } // namespace implementation