Skip to content

Commit

Permalink
sdm660-common: folio_daemon: update from wahoo android11-release
Browse files Browse the repository at this point in the history
Co-Authored-By: Albert Xu <[email protected]>
Signed-off-by: pix106 <[email protected]>
  • Loading branch information
2 people authored and pix106 committed Mar 23, 2024
1 parent d576bc6 commit 6c19805
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions folio_daemon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ int main(void) {
ASensorRef hallSensor;
ALooper *looper;
ASensorEventQueue *eventQueue = nullptr;
int32_t hallMinDelay = 0;
time_t lastWarn = 0;
int attemptCount = 0;

Expand Down Expand Up @@ -87,6 +88,14 @@ int main(void) {

// Get Hall-effect sensor events from the NDK
sensorManager = ASensorManager_getInstanceForPackage(nullptr);
looper = ALooper_forThread();
if (looper == nullptr) {
looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
}

eventQueue = ASensorManager_createEventQueue(sensorManager, looper, 0, NULL,
NULL);

/*
* As long as we are unable to get the sensor handle, periodically retry
* and emit an error message at a low frequency to prevent high CPU usage
Expand All @@ -98,6 +107,7 @@ int main(void) {
hallSensor = ASensorManager_getDefaultSensor(sensorManager,
SENSOR_TYPE);
if (hallSensor != nullptr) {
hallMinDelay = ASensor_getMinDelay(hallSensor);
break;
}

Expand All @@ -112,16 +122,8 @@ int main(void) {
sleep(RETRY_PERIOD);
}

looper = ALooper_forThread();
if (looper == nullptr) {
looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
}

eventQueue = ASensorManager_createEventQueue(sensorManager, looper, 0, NULL,
NULL);
err = ASensorEventQueue_registerSensor(eventQueue, hallSensor,
ASensor_getMinDelay(hallSensor),
10000);
hallMinDelay, 10000);
if (err < 0) {
ALOGE("Unable to register for Hall-effect sensor events");
goto out;
Expand Down

0 comments on commit 6c19805

Please sign in to comment.