Thursday, June 28, 2012

Android | Linux LED control from shell

Recently while playing around with my phone [Xperia X10] . I found a lib in /sys/hw named lights.es209ra.so ,  its a proprietary library for the lights on the phone, that includes camera flash light, notification led and the led below the home|return keys. I wanted to disassemble the file, I thought there might be someway i can control LED's from the shell. Maybe there is a function to control the LED's and I could write a program that could be linked to run, But things turned out to be more simpler. I ran objdump on the file and was pretty much disappointed at the code it generated. I thought maybe strings will hold something for me

$ strings lights.es209ra.so > lights.es209ra_so_str.txt


and voila, the last few lines of the line read


h|D"
H)FxD
h|D@4%
xD@0
backlight
buttons
battery
notifications
attention
lights
write_int failed to open %s
/sys/class/leds/lv5219lg:rgb1:red/blink_on
/sys/class/leds/lv5219lg:rgb1:green/blink_on
/sys/class/leds/lv5219lg:rgb1:blue/blink_on
/sys/class/leds/lv5219lg:rgb1:red/blink_off
/sys/class/leds/lv5219lg:rgb1:green/blink_off
/sys/class/leds/lv5219lg:rgb1:blue/blink_off
/sys/class/leds/lv5219lg:rgb1:red/brightness
/sys/class/leds/lv5219lg:rgb1:green/brightness
/sys/class/leds/lv5219lg:rgb1:blue/brightness
/sys/class/leds/lv5219lg:sled/brightness
/sys/class/leds/lv5219lg:mled/brightness
Rachael lights module
Sony Ericsson Mobile Communications
TMWH

Then I realized that in linux everything must be implemented as file so I quickly checked into /sys/class/leds  and there was exactly what I wanted


Googled the linux led handling then I came across this file
www.kernel.org/doc/Documentation/leds/leds-class.txt

Linux really did have a plan for handling the led signals. Coming back, I just typed in 1 into the brightness file and voila there it was my camera flash was glowing



Apparently lv5219lg:fled turns out to be the camera flash LED



Mostly all the android phones handle their LED's the similar way. Check yours out, play around, have a nice time... and ya the rest of the LED's work similar way only didn't have time to check the notification ones from terminal emulator ( they seem to be locked when connected to computer or there is a delay setting !!! ).