OSDN Git Service

libsensors: save sensor presence from first boot
authorMatt Gumbel <matthew.k.gumbel@linux.intel.com>
Mon, 8 Oct 2012 20:33:56 +0000 (13:33 -0700)
committerMattias Pettersson <mattias.pettersson@intel.com>
Wed, 4 Dec 2013 14:13:12 +0000 (15:13 +0100)
Because of delayed module loading and USB enumeration time, IIO sensors
sysfs nodes may not yet be created by the time libsensors is asked to
initialize by the frameworks. This patch will wait up to 10 sec for the
sysfs nodes to appear before reporting "no sensors" to the framework on
the first boot of the device and set a system property based on whether
or not the iio sensors were found.

On subsequent boots, it will only consult this system property and thus
no delay in system services startup.

Change-Id: Ibb7b6d69ce1c1dcadd0ddaa361a4297489a044c7
Signed-off-by: Matt Gumbel <matthew.k.gumbel@linux.intel.com>
bigcore/libsensors/BoardConfig.cpp

index d5bbeb8..e110b5f 100644 (file)
@@ -17,6 +17,8 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <cutils/log.h>
+#include <unistd.h>
+#include <cutils/properties.h>
 
 #include "common.h"
 
@@ -44,22 +46,46 @@ int BoardConfig::sensorListSize()
     int num_files(0);
     DIR *dp(0);
     struct dirent *dirp(0);
+    char *key = "persist.sys.sensors.iio.present";
+    char value[PROPERTY_VALUE_MAX];
 
-    if ((dp = opendir("/sys/bus/iio/devices")) == NULL){
-        ALOGI("/sys/bus/iio/devices doesn't exist. Reporting no sensors.");
-        return 0;
+    if (property_get(key, value, "")) {
+        if (strncmp(value, "1", 1) == 0) {
+            ALOGI("IIO sensor hub detected previously; assuming it is still attached.");
+            return ARRAY_SIZE(sSensorList);
+        } else {
+            ALOGI("IIO sensor hub not detected previously; assuming it still is not attached.");
+            return 0;
+        }
     }
-    while ((dirp = readdir(dp)) != NULL){
-        num_files++;
-    }
-    closedir(dp);
 
-    if (num_files <= 2) {
-        ALOGI("No entries found in /sys/bus/iio/devices. Reporting no sensors.");
-        return 0;
+    for (int i=0; i<50; i++) {
+        num_files = 0;
+        if ((dp = opendir("/sys/bus/iio/devices")) == NULL){
+            usleep(20000);
+            continue;
+        }
+        while ((dirp = readdir(dp)) != NULL){
+            num_files++;
+        }
+        closedir(dp);
+
+        if (num_files <= 2) {
+            usleep(20000);
+            continue;
+        }
+        ALOGI("Found IIO sensor hub.");
+        if (property_set(key, "1") != 0) {
+            ALOGE("Failed to set %s", key);
+        }
+        return ARRAY_SIZE(sSensorList);
     }
 
-    return ARRAY_SIZE(sSensorList);
+    ALOGI("Didn't find IIO sensor hub.");
+    if (property_set(key, "0") != 0) {
+        ALOGE("Failed to set %s", key);
+    }
+    return 0;
 }
 
 void BoardConfig::initSensors(SensorBase* sensors[])