Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce4876a9 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

sensors: Add dummy light sensor

Some devices have a sysfs toggle for the lightsensor instead of
passing the LUX values for userspace processing; for those,
use BOARD_SYSFS_LIGHT_SENSOR:=<sysfs path>

This is necessary for the rest of userspace to recognize its existence
and toggle it for auto-brightness. It doesn't generate actual light
values, though; all backlight adjustments are made in-kernel.

Change-Id: I0e546b4740720bd34d1e1d85a96b295fcc697106

sensors: dummy ls: set unique handle

handles and types are usually the same, but it's not mandatory.
Sony DASH use custom handles, and the previous assumption broke
Proximity sensor on Sony devices.

Change-Id: I954e13765f42341e6b5393a12556f6a007c4e494

Conflicts:
	services/sensorservice/Android.mk
	services/sensorservice/SensorDevice.cpp
parent 64b604bd
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -29,6 +29,10 @@ LOCAL_SHARED_LIBRARIES := \
	libui \
	libgui

ifneq ($(BOARD_SYSFS_LIGHT_SENSOR),)
    LOCAL_CFLAGS += -DSYSFS_LIGHT_SENSOR=\"$(BOARD_SYSFS_LIGHT_SENSOR)\"
endif

LOCAL_MODULE:= libsensorservice

include $(BUILD_SHARED_LIBRARY)
+48 −0
Original line number Diff line number Diff line
@@ -31,11 +31,37 @@
#include "SensorDevice.h"
#include "SensorService.h"

#ifdef SYSFS_LIGHT_SENSOR
#include <fcntl.h>
#endif

namespace android {
// ---------------------------------------------------------------------------

ANDROID_SINGLETON_STATIC_INSTANCE(SensorDevice)

#ifdef SYSFS_LIGHT_SENSOR
#define DUMMY_ALS_HANDLE 0xdeadbeef
static ssize_t addDummyLightSensor(sensor_t const **list, ssize_t count) {
    struct sensor_t dummy_light =     {
                  name            : "CyanogenMod dummy light sensor",
                  vendor          : "CyanogenMod",
                  version         : 1,
                  handle          : DUMMY_ALS_HANDLE,
                  type            : SENSOR_TYPE_LIGHT,
                  maxRange        : 20,
                  resolution      : 0.1,
                  power           : 20,
    };
    void * new_list = malloc((count+1)*sizeof(sensor_t));
    new_list = memcpy(new_list, *list, count*sizeof(sensor_t));
    ((sensor_t *)new_list)[count] = dummy_light;
    *list = (sensor_t const *)new_list;
    count++;
    return count;
}
#endif

SensorDevice::SensorDevice()
    :  mSensorDevice(0),
       mSensorModule(0)
@@ -55,6 +81,9 @@ SensorDevice::SensorDevice()
        if (mSensorDevice) {
            sensor_t const* list;
            ssize_t count = mSensorModule->get_sensors_list(mSensorModule, &list);
#ifdef SYSFS_LIGHT_SENSOR
            count = addDummyLightSensor(&list, count);
#endif
            mActivationCount.setCapacity(count);
            Info model;
            for (size_t i=0 ; i<size_t(count) ; i++) {
@@ -101,7 +130,11 @@ void SensorDevice::dump(String8& result)
ssize_t SensorDevice::getSensorList(sensor_t const** list) {
    if (!mSensorModule) return NO_INIT;
    ssize_t count = mSensorModule->get_sensors_list(mSensorModule, list);
#ifdef SYSFS_LIGHT_SENSOR
    return addDummyLightSensor(list, count);
#else
    return count;
#endif
}

status_t SensorDevice::initCheck() const {
@@ -129,6 +162,21 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled)
    if (!mSensorDevice) return NO_INIT;
    status_t err(NO_ERROR);
    bool actuateHardware = false;
#ifdef SYSFS_LIGHT_SENSOR
    if (handle == DUMMY_ALS_HANDLE) {
        int nwr, ret, fd;
        char value[2];

        fd = open(SYSFS_LIGHT_SENSOR, O_RDWR);
        if(fd < 0)
            return -ENODEV;

        nwr = sprintf(value, "%s\n", enabled ? "1" : "0");
        write(fd, value, nwr);
        close(fd);
        return 0;
    }
#endif

    Mutex::Autolock _l(mLock);
    Info& info( mActivationCount.editValueFor(handle) );