Loading services/java/com/android/server/PowerManagerService.java +1 −0 Original line number Diff line number Diff line Loading @@ -3186,6 +3186,7 @@ public class PowerManagerService extends IPowerManager.Stub boolean enabled = (mode == SCREEN_BRIGHTNESS_MODE_AUTOMATIC); if (mUseSoftwareAutoBrightness && mAutoBrightessEnabled != enabled) { mAutoBrightessEnabled = enabled; enableLightSensorLocked(mAutoBrightessEnabled); if (isScreenOn()) { // force recompute of backlight values if (mLightSensorValue >= 0) { Loading services/sensorservice/Android.mk +3 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,9 @@ LOCAL_SHARED_LIBRARIES := \ libui \ libgui ifneq ($(BOARD_SYSFS_LIGHT_SENSOR),) LOCAL_CFLAGS += -DSYSFS_LIGHT_SENSOR=\"$(BOARD_SYSFS_LIGHT_SENSOR)\" endif LOCAL_MODULE:= libsensorservice Loading services/sensorservice/SensorDevice.cpp +49 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,10 @@ #include "SensorDevice.h" #include "SensorService.h" #ifdef SYSFS_LIGHT_SENSOR #include <fcntl.h> #endif namespace android { // --------------------------------------------------------------------------- class BatteryService : public Singleton<BatteryService> { Loading Loading @@ -98,6 +102,27 @@ ANDROID_SINGLETON_STATIC_INSTANCE(BatteryService) ANDROID_SINGLETON_STATIC_INSTANCE(SensorDevice) #ifdef SYSFS_LIGHT_SENSOR 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 : 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), mSensorModule(0) Loading @@ -117,6 +142,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++) { Loading Loading @@ -157,7 +185,11 @@ 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 SYSFS_LIGHT_SENSOR return addDummyLightSensor(list, count); #else return count; #endif } status_t SensorDevice::initCheck() const { Loading @@ -179,6 +211,23 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled) status_t err(NO_ERROR); bool actuateHardware = false; #ifdef SYSFS_LIGHT_SENSOR if (handle == SENSOR_TYPE_LIGHT) { 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 Info& info( mActivationCount.editValueFor(handle) ); Loading Loading
services/java/com/android/server/PowerManagerService.java +1 −0 Original line number Diff line number Diff line Loading @@ -3186,6 +3186,7 @@ public class PowerManagerService extends IPowerManager.Stub boolean enabled = (mode == SCREEN_BRIGHTNESS_MODE_AUTOMATIC); if (mUseSoftwareAutoBrightness && mAutoBrightessEnabled != enabled) { mAutoBrightessEnabled = enabled; enableLightSensorLocked(mAutoBrightessEnabled); if (isScreenOn()) { // force recompute of backlight values if (mLightSensorValue >= 0) { Loading
services/sensorservice/Android.mk +3 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,9 @@ LOCAL_SHARED_LIBRARIES := \ libui \ libgui ifneq ($(BOARD_SYSFS_LIGHT_SENSOR),) LOCAL_CFLAGS += -DSYSFS_LIGHT_SENSOR=\"$(BOARD_SYSFS_LIGHT_SENSOR)\" endif LOCAL_MODULE:= libsensorservice Loading
services/sensorservice/SensorDevice.cpp +49 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,10 @@ #include "SensorDevice.h" #include "SensorService.h" #ifdef SYSFS_LIGHT_SENSOR #include <fcntl.h> #endif namespace android { // --------------------------------------------------------------------------- class BatteryService : public Singleton<BatteryService> { Loading Loading @@ -98,6 +102,27 @@ ANDROID_SINGLETON_STATIC_INSTANCE(BatteryService) ANDROID_SINGLETON_STATIC_INSTANCE(SensorDevice) #ifdef SYSFS_LIGHT_SENSOR 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 : 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), mSensorModule(0) Loading @@ -117,6 +142,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++) { Loading Loading @@ -157,7 +185,11 @@ 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 SYSFS_LIGHT_SENSOR return addDummyLightSensor(list, count); #else return count; #endif } status_t SensorDevice::initCheck() const { Loading @@ -179,6 +211,23 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled) status_t err(NO_ERROR); bool actuateHardware = false; #ifdef SYSFS_LIGHT_SENSOR if (handle == SENSOR_TYPE_LIGHT) { 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 Info& info( mActivationCount.editValueFor(handle) ); Loading