1414 * limitations under the License.
1515 */
1616
17- // #define VERBOSE
17+ // #define VERBOSE
1818
1919#include " Sensors.h"
2020#include < sensors/convert.h>
@@ -37,7 +37,7 @@ namespace implementation {
3737static bool UseMultiHal () {
3838 const std::string& name = MULTI_HAL_CONFIG_FILE_PATH ;
3939 struct stat buffer;
40- return (stat (name.c_str (), &buffer) == 0 );
40+ return (stat (name.c_str (), &buffer) == 0 );
4141}
4242
4343static Result ResultFromStatus (status_t err) {
@@ -55,28 +55,20 @@ static Result ResultFromStatus(status_t err) {
5555 }
5656}
5757
58- Sensors::Sensors ()
59- : mInitCheck (NO_INIT ),
60- mSensorModule (nullptr ),
61- mSensorDevice(nullptr ) {
58+ Sensors::Sensors () : mInitCheck (NO_INIT ), mSensorModule (nullptr ), mSensorDevice (nullptr ) {
6259 status_t err = OK ;
6360 if (UseMultiHal ()) {
6461 mSensorModule = ::get_multi_hal_module_info ();
6562 } else {
66- err = hw_get_module (
67- SENSORS_HARDWARE_MODULE_ID ,
68- (hw_module_t const **)&mSensorModule );
63+ err = hw_get_module (SENSORS_HARDWARE_MODULE_ID , (hw_module_t const **)&mSensorModule );
6964 }
7065 if (mSensorModule == NULL ) {
7166 err = UNKNOWN_ERROR ;
7267 }
7368
7469 if (err != OK ) {
75- LOG (ERROR ) << " Couldn't load "
76- << SENSORS_HARDWARE_MODULE_ID
77- << " module ("
78- << strerror (-err)
79- << " )" ;
70+ LOG (ERROR ) << " Couldn't load " << SENSORS_HARDWARE_MODULE_ID << " module ("
71+ << strerror (-err) << " )" ;
8072
8173 mInitCheck = err;
8274 return ;
@@ -85,11 +77,8 @@ Sensors::Sensors()
8577 err = sensors_open_1 (&mSensorModule ->common , &mSensorDevice );
8678
8779 if (err != OK ) {
88- LOG (ERROR ) << " Couldn't open device for module "
89- << SENSORS_HARDWARE_MODULE_ID
90- << " ("
91- << strerror (-err)
92- << " )" ;
80+ LOG (ERROR ) << " Couldn't open device for module " << SENSORS_HARDWARE_MODULE_ID << " ("
81+ << strerror (-err) << " )" ;
9382
9483 mInitCheck = err;
9584 return ;
@@ -119,15 +108,15 @@ status_t Sensors::initCheck() const {
119108}
120109
121110Return<void > Sensors::getSensorsList (getSensorsList_cb _hidl_cb) {
122- sensor_t const * list;
111+ sensor_t const * list;
123112 size_t count = mSensorModule ->get_sensors_list (mSensorModule , &list);
124113
125114 hidl_vec<SensorInfo> out;
126115 out.resize (count);
127116
128117 for (size_t i = 0 ; i < count; ++i) {
129- const sensor_t * src = &list[i];
130- SensorInfo * dst = &out[i];
118+ const sensor_t * src = &list[i];
119+ SensorInfo* dst = &out[i];
131120
132121 convertFromSensor (*src, dst);
133122
@@ -166,31 +155,26 @@ int Sensors::getHalDeviceVersion() const {
166155}
167156
168157Return<Result> Sensors::setOperationMode (OperationMode mode) {
169- if (getHalDeviceVersion () < SENSORS_DEVICE_API_VERSION_1_4
170- || mSensorModule ->set_operation_mode == nullptr ) {
158+ if (getHalDeviceVersion () < SENSORS_DEVICE_API_VERSION_1_4 ||
159+ mSensorModule ->set_operation_mode == nullptr ) {
171160 return Result::INVALID_OPERATION ;
172161 }
173162 return ResultFromStatus (mSensorModule ->set_operation_mode ((uint32_t )mode));
174163}
175164
176- Return<Result> Sensors::activate (
177- int32_t sensor_handle, bool enabled) {
178- return ResultFromStatus (
179- mSensorDevice ->activate (
180- reinterpret_cast <sensors_poll_device_t *>(mSensorDevice ),
181- sensor_handle,
182- enabled));
165+ Return<Result> Sensors::activate (int32_t sensor_handle, bool enabled) {
166+ return ResultFromStatus (mSensorDevice ->activate (
167+ reinterpret_cast <sensors_poll_device_t *>(mSensorDevice ), sensor_handle, enabled));
183168}
184169
185170Return<void > Sensors::poll (int32_t maxCount, poll_cb _hidl_cb) {
186-
187171 hidl_vec<Event> out;
188172 hidl_vec<SensorInfo> dynamicSensorsAdded;
189173
190174 std::unique_ptr<sensors_event_t []> data;
191175 int err = android::NO_ERROR ;
192176
193- { // scope of reentry lock
177+ { // scope of reentry lock
194178
195179 // This enforces a single client, meaning that a maximum of one client can call poll().
196180 // If this function is re-entred, it means that we are stuck in a state that may prevent
@@ -200,11 +184,11 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
200184 //
201185 // This function must not call _hidl_cb(...) or return until there is no risk of blocking.
202186 std::unique_lock<std::mutex> lock (mPollLock , std::try_to_lock);
203- if (!lock.owns_lock ()){
187+ if (!lock.owns_lock ()) {
204188 // cannot get the lock, hidl service will go into deadlock if it is not restarted.
205189 // This is guaranteed to not trigger in passthrough mode.
206- LOG (ERROR ) <<
207- " ISensors::poll() re-entry. I do not know what to do except killing myself." ;
190+ LOG (ERROR )
191+ << " ISensors::poll() re-entry. I do not know what to do except killing myself." ;
208192 ::exit (-1 );
209193 }
210194
@@ -213,9 +197,8 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
213197 } else {
214198 int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize ;
215199 data.reset (new sensors_event_t [bufferSize]);
216- err = mSensorDevice ->poll (
217- reinterpret_cast <sensors_poll_device_t *>(mSensorDevice ),
218- data.get (), bufferSize);
200+ err = mSensorDevice ->poll (reinterpret_cast <sensors_poll_device_t *>(mSensorDevice ),
201+ data.get (), bufferSize);
219202 }
220203 }
221204
@@ -231,7 +214,7 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
231214 continue ;
232215 }
233216
234- const dynamic_sensor_meta_event_t * dyn = &data[i].dynamic_sensor_meta ;
217+ const dynamic_sensor_meta_event_t * dyn = &data[i].dynamic_sensor_meta ;
235218
236219 if (!dyn->connected ) {
237220 continue ;
@@ -256,49 +239,41 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
256239 return Void ();
257240}
258241
259- Return<Result> Sensors::batch (
260- int32_t sensor_handle,
261- int64_t sampling_period_ns,
262- int64_t max_report_latency_ns) {
263- return ResultFromStatus (
264- mSensorDevice ->batch (
265- mSensorDevice ,
266- sensor_handle,
267- 0 , /* flags*/
268- sampling_period_ns,
269- max_report_latency_ns));
242+ Return<Result> Sensors::batch (int32_t sensor_handle, int64_t sampling_period_ns,
243+ int64_t max_report_latency_ns) {
244+ return ResultFromStatus (mSensorDevice ->batch (mSensorDevice , sensor_handle, 0 , /* flags*/
245+ sampling_period_ns, max_report_latency_ns));
270246}
271247
272248Return<Result> Sensors::flush (int32_t sensor_handle) {
273249 return ResultFromStatus (mSensorDevice ->flush (mSensorDevice , sensor_handle));
274250}
275251
276252Return<Result> Sensors::injectSensorData (const Event& event) {
277- if (getHalDeviceVersion () < SENSORS_DEVICE_API_VERSION_1_4
278- || mSensorDevice ->inject_sensor_data == nullptr ) {
253+ if (getHalDeviceVersion () < SENSORS_DEVICE_API_VERSION_1_4 ||
254+ mSensorDevice ->inject_sensor_data == nullptr ) {
279255 return Result::INVALID_OPERATION ;
280256 }
281257
282258 sensors_event_t out;
283259 convertToSensorEvent (event, &out);
284260
285- return ResultFromStatus (
286- mSensorDevice ->inject_sensor_data (mSensorDevice , &out));
261+ return ResultFromStatus (mSensorDevice ->inject_sensor_data (mSensorDevice , &out));
287262}
288263
289- Return<void > Sensors::registerDirectChannel (
290- const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) {
291- if (mSensorDevice ->register_direct_channel == nullptr
292- || mSensorDevice ->config_direct_report == nullptr ) {
264+ Return<void > Sensors::registerDirectChannel (const SharedMemInfo& mem,
265+ registerDirectChannel_cb _hidl_cb) {
266+ if (mSensorDevice ->register_direct_channel == nullptr ||
267+ mSensorDevice ->config_direct_report == nullptr ) {
293268 // HAL does not support
294269 _hidl_cb (Result::INVALID_OPERATION , -1 );
295270 return Void ();
296271 }
297272
298273 sensors_direct_mem_t m;
299274 if (!convertFromSharedMemInfo (mem, &m)) {
300- _hidl_cb (Result::BAD_VALUE , -1 );
301- return Void ();
275+ _hidl_cb (Result::BAD_VALUE , -1 );
276+ return Void ();
302277 }
303278
304279 int err = mSensorDevice ->register_direct_channel (mSensorDevice , &m, -1 );
@@ -313,8 +288,8 @@ Return<void> Sensors::registerDirectChannel(
313288}
314289
315290Return<Result> Sensors::unregisterDirectChannel (int32_t channelHandle) {
316- if (mSensorDevice ->register_direct_channel == nullptr
317- || mSensorDevice ->config_direct_report == nullptr ) {
291+ if (mSensorDevice ->register_direct_channel == nullptr ||
292+ mSensorDevice ->config_direct_report == nullptr ) {
318293 // HAL does not support
319294 return Result::INVALID_OPERATION ;
320295 }
@@ -324,26 +299,22 @@ Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
324299 return Result::OK ;
325300}
326301
327- Return<void > Sensors::configDirectReport (
328- int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
329- configDirectReport_cb _hidl_cb) {
330- if (mSensorDevice ->register_direct_channel == nullptr
331- || mSensorDevice ->config_direct_report == nullptr ) {
302+ Return<void > Sensors::configDirectReport (int32_t sensorHandle, int32_t channelHandle,
303+ RateLevel rate, configDirectReport_cb _hidl_cb) {
304+ if (mSensorDevice ->register_direct_channel == nullptr ||
305+ mSensorDevice ->config_direct_report == nullptr ) {
332306 // HAL does not support
333307 _hidl_cb (Result::INVALID_OPERATION , -1 );
334308 return Void ();
335309 }
336310
337- sensors_direct_cfg_t cfg = {
338- .rate_level = convertFromRateLevel (rate)
339- };
311+ sensors_direct_cfg_t cfg = {.rate_level = convertFromRateLevel (rate)};
340312 if (cfg.rate_level < 0 ) {
341313 _hidl_cb (Result::BAD_VALUE , -1 );
342314 return Void ();
343315 }
344316
345- int err = mSensorDevice ->config_direct_report (mSensorDevice ,
346- sensorHandle, channelHandle, &cfg);
317+ int err = mSensorDevice ->config_direct_report (mSensorDevice , sensorHandle, channelHandle, &cfg);
347318
348319 if (rate == RateLevel::STOP ) {
349320 _hidl_cb (ResultFromStatus (err), -1 );
@@ -354,20 +325,18 @@ Return<void> Sensors::configDirectReport(
354325}
355326
356327// static
357- void Sensors::convertFromSensorEvents (
358- size_t count,
359- const sensors_event_t *srcArray,
360- hidl_vec<Event> *dstVec) {
328+ void Sensors::convertFromSensorEvents (size_t count, const sensors_event_t * srcArray,
329+ hidl_vec<Event>* dstVec) {
361330 for (size_t i = 0 ; i < count; ++i) {
362- const sensors_event_t & src = srcArray[i];
363- Event * dst = &(*dstVec)[i];
331+ const sensors_event_t & src = srcArray[i];
332+ Event* dst = &(*dstVec)[i];
364333
365334 convertFromSensorEvent (src, dst);
366335 }
367336}
368337
369- ISensors * HIDL_FETCH_ISensors (const char * /* hal */ ) {
370- Sensors * sensors = new Sensors;
338+ ISensors* HIDL_FETCH_ISensors (const char * /* hal */ ) {
339+ Sensors* sensors = new Sensors;
371340 if (sensors->initCheck () != OK ) {
372341 delete sensors;
373342 sensors = nullptr ;
0 commit comments