clover: folio_daemon: retry slowly on failure
Bug: 38001818 Test: loaded on taimen Change-Id: I3f5a8cbf0faca3b5d027dcd74f1b16de80fdbee2 Signed-off-by: pix106 <sbordenave@gmail.com>
This commit is contained in:
parent
ec8ad1a695
commit
543cbeebc9
1 changed files with 28 additions and 6 deletions
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
#include <linux/uinput.h>
|
#include <linux/uinput.h>
|
||||||
|
@ -25,8 +26,9 @@
|
||||||
// Hall-effect sensor type
|
// Hall-effect sensor type
|
||||||
#define SENSOR_TYPE 33171016
|
#define SENSOR_TYPE 33171016
|
||||||
|
|
||||||
// Warn if the polling loop yields zero events at most once every five seconds.
|
#define RETRY_LIMIT 120
|
||||||
#define WARN_PERIOD (time_t)5
|
#define RETRY_PERIOD 30 // 30 seconds
|
||||||
|
#define WARN_PERIOD (time_t)300 // 5 minutes
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This simple daemon listens for events from the Hall-effect sensor and writes
|
* This simple daemon listens for events from the Hall-effect sensor and writes
|
||||||
|
@ -42,6 +44,7 @@ int main(void) {
|
||||||
ALooper *looper;
|
ALooper *looper;
|
||||||
ASensorEventQueue *eventQueue = nullptr;
|
ASensorEventQueue *eventQueue = nullptr;
|
||||||
time_t lastWarn = 0;
|
time_t lastWarn = 0;
|
||||||
|
int attemptCount = 0;
|
||||||
|
|
||||||
ALOGI("Started");
|
ALOGI("Started");
|
||||||
|
|
||||||
|
@ -82,10 +85,29 @@ int main(void) {
|
||||||
|
|
||||||
// Get Hall-effect sensor events from the NDK
|
// Get Hall-effect sensor events from the NDK
|
||||||
sensorManager = ASensorManager_getInstanceForPackage(nullptr);
|
sensorManager = ASensorManager_getInstanceForPackage(nullptr);
|
||||||
hallSensor = ASensorManager_getDefaultSensor(sensorManager, SENSOR_TYPE);
|
/*
|
||||||
if (hallSensor == nullptr) {
|
* As long as we are unable to get the sensor handle, periodically retry
|
||||||
ALOGE("Unable to get Hall-effect sensor");
|
* and emit an error message at a low frequency to prevent high CPU usage
|
||||||
|
* and log spam. If we simply exited with an error here, we would be
|
||||||
|
* immediately restarted and fail in the same way indefinitely.
|
||||||
|
*/
|
||||||
|
while (true) {
|
||||||
|
time_t now = time(NULL);
|
||||||
|
hallSensor = ASensorManager_getDefaultSensor(sensorManager,
|
||||||
|
SENSOR_TYPE);
|
||||||
|
if (hallSensor != nullptr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (++attemptCount >= RETRY_LIMIT) {
|
||||||
|
ALOGE("Retries exhausted; exiting");
|
||||||
goto out;
|
goto out;
|
||||||
|
} else if (now > lastWarn + WARN_PERIOD) {
|
||||||
|
ALOGE("Unable to get Hall-effect sensor");
|
||||||
|
lastWarn = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(RETRY_PERIOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
looper = ALooper_forThread();
|
looper = ALooper_forThread();
|
||||||
|
|
Loading…
Reference in a new issue