hidl: sensors: 1.0: Add (and run) clang-format file
Change-Id: I88beb777f386cdfadc1d39be3a36a1c3ebdee06a
This commit is contained in:
parent
61c7f9360d
commit
eed8c0648b
1
hidl/sensors/1.0/.clang-format
Symbolic link
1
hidl/sensors/1.0/.clang-format
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../../../../build/soong/scripts/system-clang-format
|
@ -53,28 +53,20 @@ static Result ResultFromStatus(status_t err) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sensors::Sensors()
|
Sensors::Sensors() : mInitCheck(NO_INIT), mSensorModule(nullptr), mSensorDevice(nullptr) {
|
||||||
: mInitCheck(NO_INIT),
|
|
||||||
mSensorModule(nullptr),
|
|
||||||
mSensorDevice(nullptr) {
|
|
||||||
status_t err = OK;
|
status_t err = OK;
|
||||||
if (UseMultiHal()) {
|
if (UseMultiHal()) {
|
||||||
mSensorModule = ::get_multi_hal_module_info();
|
mSensorModule = ::get_multi_hal_module_info();
|
||||||
} else {
|
} else {
|
||||||
err = hw_get_module(
|
err = hw_get_module(SENSORS_HARDWARE_MODULE_ID, (hw_module_t const**)&mSensorModule);
|
||||||
SENSORS_HARDWARE_MODULE_ID,
|
|
||||||
(hw_module_t const **)&mSensorModule);
|
|
||||||
}
|
}
|
||||||
if (mSensorModule == NULL) {
|
if (mSensorModule == NULL) {
|
||||||
err = UNKNOWN_ERROR;
|
err = UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
LOG(ERROR) << "Couldn't load "
|
LOG(ERROR) << "Couldn't load " << SENSORS_HARDWARE_MODULE_ID << " module ("
|
||||||
<< SENSORS_HARDWARE_MODULE_ID
|
<< strerror(-err) << ")";
|
||||||
<< " module ("
|
|
||||||
<< strerror(-err)
|
|
||||||
<< ")";
|
|
||||||
|
|
||||||
mInitCheck = err;
|
mInitCheck = err;
|
||||||
return;
|
return;
|
||||||
@ -83,11 +75,8 @@ Sensors::Sensors()
|
|||||||
err = sensors_open_1(&mSensorModule->common, &mSensorDevice);
|
err = sensors_open_1(&mSensorModule->common, &mSensorDevice);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
LOG(ERROR) << "Couldn't open device for module "
|
LOG(ERROR) << "Couldn't open device for module " << SENSORS_HARDWARE_MODULE_ID << " ("
|
||||||
<< SENSORS_HARDWARE_MODULE_ID
|
<< strerror(-err) << ")";
|
||||||
<< " ("
|
|
||||||
<< strerror(-err)
|
|
||||||
<< ")";
|
|
||||||
|
|
||||||
mInitCheck = err;
|
mInitCheck = err;
|
||||||
return;
|
return;
|
||||||
@ -141,24 +130,19 @@ int Sensors::getHalDeviceVersion() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::setOperationMode(OperationMode mode) {
|
Return<Result> Sensors::setOperationMode(OperationMode mode) {
|
||||||
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4
|
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4 ||
|
||||||
|| mSensorModule->set_operation_mode == nullptr) {
|
mSensorModule->set_operation_mode == nullptr) {
|
||||||
return Result::INVALID_OPERATION;
|
return Result::INVALID_OPERATION;
|
||||||
}
|
}
|
||||||
return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode));
|
return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::activate(
|
Return<Result> Sensors::activate(int32_t sensor_handle, bool enabled) {
|
||||||
int32_t sensor_handle, bool enabled) {
|
return ResultFromStatus(mSensorDevice->activate(
|
||||||
return ResultFromStatus(
|
reinterpret_cast<sensors_poll_device_t*>(mSensorDevice), sensor_handle, enabled));
|
||||||
mSensorDevice->activate(
|
|
||||||
reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
|
|
||||||
sensor_handle,
|
|
||||||
enabled));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
||||||
|
|
||||||
hidl_vec<Event> out;
|
hidl_vec<Event> out;
|
||||||
hidl_vec<SensorInfo> dynamicSensorsAdded;
|
hidl_vec<SensorInfo> dynamicSensorsAdded;
|
||||||
|
|
||||||
@ -178,8 +162,8 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||||||
if (!lock.owns_lock()) {
|
if (!lock.owns_lock()) {
|
||||||
// cannot get the lock, hidl service will go into deadlock if it is not restarted.
|
// cannot get the lock, hidl service will go into deadlock if it is not restarted.
|
||||||
// This is guaranteed to not trigger in passthrough mode.
|
// This is guaranteed to not trigger in passthrough mode.
|
||||||
LOG(ERROR) <<
|
LOG(ERROR)
|
||||||
"ISensors::poll() re-entry. I do not know what to do except killing myself.";
|
<< "ISensors::poll() re-entry. I do not know what to do except killing myself.";
|
||||||
::exit(-1);
|
::exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,8 +172,7 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||||||
} else {
|
} else {
|
||||||
int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize;
|
int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize;
|
||||||
data.reset(new sensors_event_t[bufferSize]);
|
data.reset(new sensors_event_t[bufferSize]);
|
||||||
err = mSensorDevice->poll(
|
err = mSensorDevice->poll(reinterpret_cast<sensors_poll_device_t*>(mSensorDevice),
|
||||||
reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
|
|
||||||
data.get(), bufferSize);
|
data.get(), bufferSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,17 +214,10 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
|||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::batch(
|
Return<Result> Sensors::batch(int32_t sensor_handle, int64_t sampling_period_ns,
|
||||||
int32_t sensor_handle,
|
|
||||||
int64_t sampling_period_ns,
|
|
||||||
int64_t max_report_latency_ns) {
|
int64_t max_report_latency_ns) {
|
||||||
return ResultFromStatus(
|
return ResultFromStatus(mSensorDevice->batch(mSensorDevice, sensor_handle, 0, /*flags*/
|
||||||
mSensorDevice->batch(
|
sampling_period_ns, max_report_latency_ns));
|
||||||
mSensorDevice,
|
|
||||||
sensor_handle,
|
|
||||||
0, /*flags*/
|
|
||||||
sampling_period_ns,
|
|
||||||
max_report_latency_ns));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::flush(int32_t sensor_handle) {
|
Return<Result> Sensors::flush(int32_t sensor_handle) {
|
||||||
@ -249,22 +225,21 @@ Return<Result> Sensors::flush(int32_t sensor_handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::injectSensorData(const Event& event) {
|
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) {
|
mSensorDevice->inject_sensor_data == nullptr) {
|
||||||
return Result::INVALID_OPERATION;
|
return Result::INVALID_OPERATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
sensors_event_t out;
|
sensors_event_t out;
|
||||||
convertToSensorEvent(event, &out);
|
convertToSensorEvent(event, &out);
|
||||||
|
|
||||||
return ResultFromStatus(
|
return ResultFromStatus(mSensorDevice->inject_sensor_data(mSensorDevice, &out));
|
||||||
mSensorDevice->inject_sensor_data(mSensorDevice, &out));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> Sensors::registerDirectChannel(
|
Return<void> Sensors::registerDirectChannel(const SharedMemInfo& mem,
|
||||||
const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) {
|
registerDirectChannel_cb _hidl_cb) {
|
||||||
if (mSensorDevice->register_direct_channel == nullptr
|
if (mSensorDevice->register_direct_channel == nullptr ||
|
||||||
|| mSensorDevice->config_direct_report == nullptr) {
|
mSensorDevice->config_direct_report == nullptr) {
|
||||||
// HAL does not support
|
// HAL does not support
|
||||||
_hidl_cb(Result::INVALID_OPERATION, -1);
|
_hidl_cb(Result::INVALID_OPERATION, -1);
|
||||||
return Void();
|
return Void();
|
||||||
@ -288,8 +263,8 @@ Return<void> Sensors::registerDirectChannel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
|
Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
|
||||||
if (mSensorDevice->register_direct_channel == nullptr
|
if (mSensorDevice->register_direct_channel == nullptr ||
|
||||||
|| mSensorDevice->config_direct_report == nullptr) {
|
mSensorDevice->config_direct_report == nullptr) {
|
||||||
// HAL does not support
|
// HAL does not support
|
||||||
return Result::INVALID_OPERATION;
|
return Result::INVALID_OPERATION;
|
||||||
}
|
}
|
||||||
@ -299,26 +274,22 @@ Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
|
|||||||
return Result::OK;
|
return Result::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> Sensors::configDirectReport(
|
Return<void> Sensors::configDirectReport(int32_t sensorHandle, int32_t channelHandle,
|
||||||
int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
RateLevel rate, configDirectReport_cb _hidl_cb) {
|
||||||
configDirectReport_cb _hidl_cb) {
|
if (mSensorDevice->register_direct_channel == nullptr ||
|
||||||
if (mSensorDevice->register_direct_channel == nullptr
|
mSensorDevice->config_direct_report == nullptr) {
|
||||||
|| mSensorDevice->config_direct_report == nullptr) {
|
|
||||||
// HAL does not support
|
// HAL does not support
|
||||||
_hidl_cb(Result::INVALID_OPERATION, -1);
|
_hidl_cb(Result::INVALID_OPERATION, -1);
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
sensors_direct_cfg_t cfg = {
|
sensors_direct_cfg_t cfg = {.rate_level = convertFromRateLevel(rate)};
|
||||||
.rate_level = convertFromRateLevel(rate)
|
|
||||||
};
|
|
||||||
if (cfg.rate_level < 0) {
|
if (cfg.rate_level < 0) {
|
||||||
_hidl_cb(Result::BAD_VALUE, -1);
|
_hidl_cb(Result::BAD_VALUE, -1);
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
int err = mSensorDevice->config_direct_report(mSensorDevice,
|
int err = mSensorDevice->config_direct_report(mSensorDevice, sensorHandle, channelHandle, &cfg);
|
||||||
sensorHandle, channelHandle, &cfg);
|
|
||||||
|
|
||||||
if (rate == RateLevel::STOP) {
|
if (rate == RateLevel::STOP) {
|
||||||
_hidl_cb(ResultFromStatus(err), -1);
|
_hidl_cb(ResultFromStatus(err), -1);
|
||||||
@ -329,9 +300,7 @@ Return<void> Sensors::configDirectReport(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Sensors::convertFromSensorEvents(
|
void Sensors::convertFromSensorEvents(size_t count, const sensors_event_t* srcArray,
|
||||||
size_t count,
|
|
||||||
const sensors_event_t *srcArray,
|
|
||||||
hidl_vec<Event>* dstVec) {
|
hidl_vec<Event>* dstVec) {
|
||||||
for (size_t i = 0; i < count; ++i) {
|
for (size_t i = 0; i < count; ++i) {
|
||||||
const sensors_event_t& src = srcArray[i];
|
const sensors_event_t& src = srcArray[i];
|
||||||
|
@ -29,7 +29,6 @@ namespace sensors {
|
|||||||
namespace V1_0 {
|
namespace V1_0 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
|
|
||||||
struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
|
struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
|
||||||
Sensors();
|
Sensors();
|
||||||
|
|
||||||
@ -39,27 +38,23 @@ struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
|
|||||||
|
|
||||||
Return<Result> setOperationMode(OperationMode mode) override;
|
Return<Result> setOperationMode(OperationMode mode) override;
|
||||||
|
|
||||||
Return<Result> activate(
|
Return<Result> activate(int32_t sensor_handle, bool enabled) override;
|
||||||
int32_t sensor_handle, bool enabled) override;
|
|
||||||
|
|
||||||
Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override;
|
Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override;
|
||||||
|
|
||||||
Return<Result> batch(
|
Return<Result> batch(int32_t sensor_handle, int64_t sampling_period_ns,
|
||||||
int32_t sensor_handle,
|
|
||||||
int64_t sampling_period_ns,
|
|
||||||
int64_t max_report_latency_ns) override;
|
int64_t max_report_latency_ns) override;
|
||||||
|
|
||||||
Return<Result> flush(int32_t sensor_handle) override;
|
Return<Result> flush(int32_t sensor_handle) override;
|
||||||
|
|
||||||
Return<Result> injectSensorData(const Event& event) override;
|
Return<Result> injectSensorData(const Event& event) override;
|
||||||
|
|
||||||
Return<void> registerDirectChannel(
|
Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
||||||
const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override;
|
registerDirectChannel_cb _hidl_cb) override;
|
||||||
|
|
||||||
Return<Result> unregisterDirectChannel(int32_t channelHandle) override;
|
Return<Result> unregisterDirectChannel(int32_t channelHandle) override;
|
||||||
|
|
||||||
Return<void> configDirectReport(
|
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||||
int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
|
||||||
configDirectReport_cb _hidl_cb) override;
|
configDirectReport_cb _hidl_cb) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -71,8 +66,8 @@ private:
|
|||||||
|
|
||||||
int getHalDeviceVersion() const;
|
int getHalDeviceVersion() const;
|
||||||
|
|
||||||
static void convertFromSensorEvents(
|
static void convertFromSensorEvents(size_t count, const sensors_event_t* src,
|
||||||
size_t count, const sensors_event_t *src, hidl_vec<Event> *dst);
|
hidl_vec<Event>* dst);
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Sensors);
|
DISALLOW_COPY_AND_ASSIGN(Sensors);
|
||||||
};
|
};
|
||||||
|
@ -42,9 +42,7 @@ void convertFromSensor(const sensor_t &src, SensorInfo *dst) {
|
|||||||
dst->flags = src.flags;
|
dst->flags = src.flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void convertToSensor(
|
void convertToSensor(const ::android::hardware::sensors::V1_0::SensorInfo& src, sensor_t* dst) {
|
||||||
const ::android::hardware::sensors::V1_0::SensorInfo &src,
|
|
||||||
sensor_t *dst) {
|
|
||||||
dst->name = strdup(src.name.c_str());
|
dst->name = strdup(src.name.c_str());
|
||||||
dst->vendor = strdup(src.vendor.c_str());
|
dst->vendor = strdup(src.vendor.c_str());
|
||||||
dst->version = src.version;
|
dst->version = src.version;
|
||||||
@ -247,8 +245,7 @@ void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
|
|||||||
|
|
||||||
case SensorType::MAGNETIC_FIELD_UNCALIBRATED:
|
case SensorType::MAGNETIC_FIELD_UNCALIBRATED:
|
||||||
case SensorType::GYROSCOPE_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.x_uncalib = src.u.uncal.x;
|
||||||
dst->uncalibrated_gyro.y_uncalib = src.u.uncal.y;
|
dst->uncalibrated_gyro.y_uncalib = src.u.uncal.y;
|
||||||
dst->uncalibrated_gyro.z_uncalib = src.u.uncal.z;
|
dst->uncalibrated_gyro.z_uncalib = src.u.uncal.z;
|
||||||
@ -303,16 +300,13 @@ void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
|
|||||||
dst->dynamic_sensor_meta.handle = src.u.dynamic.sensorHandle;
|
dst->dynamic_sensor_meta.handle = src.u.dynamic.sensorHandle;
|
||||||
dst->dynamic_sensor_meta.sensor = NULL; // to be filled in later
|
dst->dynamic_sensor_meta.sensor = NULL; // to be filled in later
|
||||||
|
|
||||||
memcpy(dst->dynamic_sensor_meta.uuid,
|
memcpy(dst->dynamic_sensor_meta.uuid, src.u.dynamic.uuid.data(), 16);
|
||||||
src.u.dynamic.uuid.data(),
|
|
||||||
16);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SensorType::ADDITIONAL_INFO: {
|
case SensorType::ADDITIONAL_INFO: {
|
||||||
const ::android::hardware::sensors::V1_0::AdditionalInfo &srcInfo =
|
const ::android::hardware::sensors::V1_0::AdditionalInfo& srcInfo = src.u.additional;
|
||||||
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->type = (int32_t)srcInfo.type;
|
||||||
@ -320,9 +314,7 @@ void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
|
|||||||
|
|
||||||
CHECK_EQ(sizeof(srcInfo.u), sizeof(dstInfo->data_int32));
|
CHECK_EQ(sizeof(srcInfo.u), sizeof(dstInfo->data_int32));
|
||||||
|
|
||||||
memcpy(dstInfo->data_int32,
|
memcpy(dstInfo->data_int32, &srcInfo.u, sizeof(dstInfo->data_int32));
|
||||||
&srcInfo.u,
|
|
||||||
sizeof(dstInfo->data_int32));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -387,4 +379,3 @@ int convertFromRateLevel(RateLevel rate) {
|
|||||||
} // namespace sensors
|
} // namespace sensors
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user