[Samsung Galaxy S (4G Model)] jeffsf:
A long, long time ago, in a land far far away...

...there was a king of an empire on a peninsula near what we today call China. He had great scientists that made devices that let you magically talk with people in other places.

However, one of those devices annoyed the king. The king brought in his chief scientist and said, "How dare you make a magic box like this! Whenever I turn it on, the screen flashes bright when it is dim, or dim when it is bright. What do you have to say about this grave mistake of yours?" The chief scientist began, "Your honor, it is an issue with the start up of the GP2A sensor. You see, during the first 50,000 nanoseconds..." The king grew furious and interrupted him, "I don't want to hear about stinkin' nano-whatevers." He waved the chief scientist off and looked at the court jester. The jester smiled and said, "You could always just turn off auto-brightness." The king laughed and proclaimed, "Bring in my best consultants!"

In came the butcher, the baker, and the candlestick maker.

The king explained the problem to them and each thought carefully before responding.

The butcher said, "I'd just modify the kernel and only have it send out an event when the light level was very stable for 20 seconds."

The baker said, "I'd look at six samples, throw out the high, throw out the low, and return the average of the other four."

The candlestick maker said, "I know a little about light, you see. I'd throw out the first four samples, then just use wide bands so the light doesn't bounce around much."

The king listened to all three and looked at the jester. The jester said, "Don't look at me, it's all gobbledegook, but it all sounds good!"

The king proclaimed, "You heard the jester. Make it so!"

So the butcher hacked the kernel driver, as did the baker, and the candlestick maker hacked libsensors and the framework.

The jester laughed to himself, "What a hack job! Put in all three, that is going to be a mess and a half." Thankfully for the jester, the king didn't hear him.

The people awaited something from the king that would compete with the iPhone (yes, they had Apple Stores back then) and it came forth, named for the stars, the Galaxy S4G. And the people flocked to it. They were frustrated as its auto-brightness didn't work very well. It didn't flash bright and dim, but it took 20 seconds or more to adjust, and sometimes never did. So they took the advice of the jester, they turned auto-brightness off.

Then came the excitement. The pastry chefs were cooking up ice cream sandwiches. But their first results had the same problem as the gingerbread and the frozen yogurt. The people were disappointed. Again, they turned off the auto-brightness.

Thankfully, a magician from another court sent them a message that he had solved their problems. He had a phone that the auto-brightness worked well for him, to the point he forgot that auto-brightness was even on. He checked it for several days and tweaked it a bit for his personal preference.

This is that message.

Source has been committed to the TeamAcid repository that should resolve the auto-brightness issues with the SGS4G. New builds of CM9 and AOKP (and ROMs that use the TeamAcid code base) should soon see these changes after a repo sync is done.

For those assembling ROMs rather than building from scratch, you are likely to need:

Kernel with updated GP2A driver

Updated libsensors

Changes to framework to use the new values to set brightness

I can't say if one of the libsensor objects from one ROM can safely be used in another.

If you want to change the light levels and brightness, CM9 (and perhaps other ROMs) let a user select System settings > Display > Automatic Backlight and adjust the settings by checking "Use custom" and then clicking "Edit other levels..." I did not turn on the "Light Sensor Filter," but did select "Allow light decrease" and set "Decrease hysteresis" to 0%.

View attachment 1326939

Edit -- I have since added an intermediate step at 180 brightness starting at 1750 lux to better handle overcast mornings/evenings.

If you're not familiar with lux and perceived brightness, the eye sees a doubling of light level as "one step" in brightness. The difference between "50% gray" and "white" is a doubling of light level. You'll see in the framework that for one of the steps the screen brightness varies by 0.7 -- half a "doubling" step -- to reduce big "jumps" at low brightness levels.

Here are some typical light levels in lux:

9 lux -- lower limit of output of sensor to Android code

50-150 lux -- typical home "living room" illumination

300-500 lux -- typical office illumination, sunrise or sunset

1,000 lux -- overcast day

10,000 lux -- indirect light on a sunny day

100,000 lux -- direct sun

These changes do not, unfortunately, resolve the soft-key light issues, nor do they seem to allow auto-brightness to set the brightness lower than the "20" that seems to be the "dim" level.