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

Commit 9f47a681 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

sensors: Add dummy light sensor for p990/p999

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
parent 5d4bc4e0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2803,6 +2803,7 @@ class PowerManagerService extends IPowerManager.Stub
        boolean enabled = (mode == SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
        if (mUseSoftwareAutoBrightness && mAutoBrightessEnabled != enabled) {
            mAutoBrightessEnabled = enabled;
            enableLightSensor(mAutoBrightessEnabled);
            if (isScreenOn()) {
                // force recompute of backlight values
                if (mLightSensorValue >= 0) {
+4 −0
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@ ifeq ($(TARGET_HAS_FOXCONN_SENSORS),true)
    LOCAL_CFLAGS += -DFOXCONN_SENSORS
endif

ifneq ($(filter p990 p999, $(TARGET_BOOTLOADER_BOARD_NAME)),)
    LOCAL_CFLAGS += -DUSE_LGE_ALS_DUMMY
endif

# need "-lrt" on Linux simulator to pick up clock_gettime
ifeq ($(TARGET_SIMULATOR),true)
	ifeq ($(HOST_OS),linux)
+69 −6
Original line number Diff line number Diff line
@@ -30,6 +30,10 @@

#include "SensorDevice.h"

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

namespace android {
// ---------------------------------------------------------------------------
class BatteryService : public Singleton<BatteryService> {
@@ -97,6 +101,27 @@ ANDROID_SINGLETON_STATIC_INSTANCE(BatteryService)

ANDROID_SINGLETON_STATIC_INSTANCE(SensorDevice)

#ifdef USE_LGE_ALS_DUMMY
static ssize_t addDummyLGESensor(sensor_t const **list, ssize_t count) {
    struct sensor_t dummy_light =     {
                  name            : "Dummy LGE-Star light sensor",
                  vendor          : "CyanogenMod",
                  version         : 1,
                  handle          : SENSOR_TYPE_LIGHT,
                  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),
       mOldSensorsEnabled(0),
@@ -139,15 +164,23 @@ SensorDevice::SensorDevice()
        if (mSensorDevice || mOldSensorsCompatMode) {
            sensor_t const* list;
            ssize_t count = mSensorModule->get_sensors_list(mSensorModule, &list);
            mActivationCount.setCapacity(count);
            Info model;
            for (size_t i=0 ; i<size_t(count) ; i++) {
                mActivationCount.add(list[i].handle, model);

#ifdef USE_LGE_ALS_DUMMY
            count = addDummyLGESensor(&list, count);
#endif

            if (mOldSensorsCompatMode) {
                mOldSensorsList = list;
                mOldSensorsCount = count;
                mSensorDataDevice->data_open(mSensorDataDevice,
                            mSensorControlDevice->open_data_source(mSensorControlDevice));
            }

            mActivationCount.setCapacity(count);
            Info model;
            for (size_t i=0 ; i<size_t(count) ; i++) {
                mActivationCount.add(list[i].handle, model);
                if (mOldSensorsCompatMode) {
                    mSensorControlDevice->activate(mSensorControlDevice, list[i].handle, 0);
                } else {
                    mSensorDevice->activate(mSensorDevice, list[i].handle, 0);
@@ -178,6 +211,10 @@ void SensorDevice::dump(String8& result, char* buffer, size_t SIZE)
ssize_t SensorDevice::getSensorList(sensor_t const** list) {
    if (!mSensorModule) return NO_INIT;
    ssize_t count = mSensorModule->get_sensors_list(mSensorModule, list);

#ifdef USE_LGE_ALS_DUMMY
    return addDummyLGESensor(list, count);
#endif
    return count;
}

@@ -258,6 +295,32 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled)
    status_t err(NO_ERROR);
    bool actuateHardware = false;

#ifdef USE_LGE_ALS_DUMMY

    if (handle == SENSOR_TYPE_LIGHT) {
        int nwr, ret, fd;
        char value[2];


        fd = open("/sys/devices/platform/star_aat2870.0/lsensor_onoff", O_RDWR);
        if(fd < 0)
            return -ENODEV;

        nwr = sprintf(value, "%s\n", enabled ? "1" : "0");
        write(fd, value, nwr);
        close(fd);
        fd = open("/sys/devices/platform/star_aat2870.0/alc", O_RDWR);
        if(fd < 0)
            return -ENODEV;

        nwr = sprintf(value, "%s\n", enabled ? "2" : "0");
        write(fd, value, nwr);
        close(fd);

        return 0;

    }
#endif
    Info& info( mActivationCount.editValueFor(handle) );
    if (enabled) {
        Mutex::Autolock _l(mLock);