Merge branch 'MotoICS' of github.com:teamgummy/frameworks_base into MotoICS
reverted back to stock powermanagerservice in order to properly port CM's
Pimp automatic backlight.

Moving average filter for light sensor, support for custom levels, battery stats fix and dim fix.

Optimization: Don't compute the sum of all samples in filter window every run. Instead, keep track of the sum, subtract phased out sample, add new sample and divide new sum by number of valid samples. Massive CPU cycle savings.
Thanks to Jonathan (zenpoy on gmail dot com) for pointing me in the right direction!

Fix: The code for stopping the filter if the sensor has been stable the entire filter window time was only enabled if debug logging was enabled. Oops. CPU cycle savings in steady ambient light.

Tweak light sensor filter

1. Only allow decrease if user permitted it
2. Only perform filter reset on sensor increase and current average is below 1500 ("indoors")
3. Filter reset in 2. means pushing the filter half way towards new sample
4. Filter reset is disabled by default

This change requires commits from CMParts:

5f4026702b67b5d23c9a992f408e3861c90566db
f9238a01e4a4a64cb414dbdada36c97ae2a37db9
0a4b490035c333b3d77e6e59fcc0f7d16d78ebda
5036cc8217daf59aa9f2800bc3fa40e4dd4b3117
b43caaab217848668241681613ce8d54ceda69e9
cc0682a4cc43d0058db8b5195d4d329336f2d3fd

Change-Id: I9c88704484f4a23b3d643597f35b55d74cf36b56
Fix automatic brightness when filtering is disabled

(Broke in I9c88704484f4a23b3d643597f35b55d74cf36b56)

- Do not mHandler.removeCallbacks(mAutoBrightnessTask) every time
  a value is received from the sensor because that will ensure that
  the task ever get ran! (We schedule it 2 seconds into the future
  but receives a value from the sensor every second.)
- Replace the algorithm for brightness change (non-filtering) with
  the original algorithm before the patch. (Not sure why the patch
  changed it.)

Change-Id: I71f6f23c53974fbb763d46ea4023623d2bbeb250
Corrected error in screen backlight level
This allows for backlight to decrease when changing to dimmer location
when phone is not connected to a dock.  Previouos setting had reversed.

Change-Id: I3f9e44dec8e3deb9ecb2aeb0f775383bbd7b3d57
LCD Brightness - continued change to allow lcd dimming in both docked
and undocked modes.  It does not make sence to not allow screen to dim
in either instance.
Better options are welcome.

Change-Id: I501ec96fce64b9629a198ab713858eabee602600
Bring back LCD disable brightness decrease

This reverts commit 5a63233c9ca4f7aa2e57c776fb275e5c3d78d2ff
and b1b664a242ea311c7a96d7e614cc95799aa0b8b3

Patch Set 2: Do not change default LIGHT_DECREASE setting

Change-Id: I17616d17c86a2954d5c530c356b0541af5664ad5
Separate configuration of auto-brightness for button/keyboard backlights.

Presently, light-sensor based automatic brightness
(config_autoBrightnessLevels) controls both button and keyboard backlights
in addition to the screen backlight.  Unfortunately auto-brightness for
button/keyboard backlights doesn't work well on devices (e.g., epicmtd)
with neither (i) dimmable button/keyboard backlights (so when they're on,
they're very bright even if the screen backlight is relatively dark) nor
(ii) identifiable surface features on capacitive buttons (so they can't be
found if the backlights are permanently turned off).

For these devices, the non-auto-brightness behavior of button/keyboard
backlights, whereby they turn on during screen-on events and user activity
and timeout-to-off shortly thereafter, is preferable.  Thus, this commit
adds a config option, config_autoBrightnessButtonKeyboard (defaults to
true), that when disabled allows for automatic brightness control of the
screen backlight, but retains the timeout-based behavior for button and
keyboard backlights.

Also addressed is a bug that disables the button and keyboard backlights on
screen unlock, and reenables the backlights on touch events so that
capacitive keys may be located.
Don't enable the light sensor if it's not being used

We want to fully disable the lightsensor when it's not used, for two reasons:
1 - Power savings
2 - Sensors that control the backlight directly need to be disabled when
brightness control is set to manual. Forcibly enabling the sensor when
the screen turns on makes these devices incapable of using manual
brightness.

Change-Id: I64c1114348ff096e0a72b265f6f141d1ecef249c

Fix button backlights that depend on ALS

On a few devices, lighting the buttons when the screen turns on
depends on the lightsensor, regardless of the user preference.
So go back to enabling the sensor whenever the screen turns on, and
enforce the user preference after running through the light settings
once.

Change-Id: I6f036a32315eb7688a9cd11d4bd70dbca1b2fa8b