Skip to content

Commit

Permalink
Fix automatic brightness
Browse files Browse the repository at this point in the history
Broken in Iddcbee98f6588bba428c4059e786d946d7ce2298

- Brightness is now handled in handleLightSensorValue instead of
  onSensorChanged, but the previous patch copied the old handling
  code into onSensorChanged in addition to calling handleLightSensorValue.
  This patch integrates the brightness filter change from
  onSensorChanged into handleLightSensorValue.
- onSensorChanged called mHandler.removeCallbacks(mAutoBrightnessTask)
  every time a value is received from the sensor ensuring that the
  task never get ran! (We schedule it 2 seconds into the future
  but receives a value from the sensor every second.)
  This patch removes the call.

(Note: similar to http://review.cyanogenmod.com/11341)

Change-Id: Id3e4f0f02f91f27c7c12cb2e274e0c13213d4774
  • Loading branch information
pawitp authored and Gerrit Code Review committed Sep 28, 2012
1 parent 9a8117c commit 5153459
Showing 1 changed file with 36 additions and 60 deletions.
96 changes: 36 additions & 60 deletions services/java/com/android/server/PowerManagerService.java
Expand Up @@ -3765,6 +3765,42 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) {

private void handleLightSensorValue(int value, boolean immediate) {
long milliseconds = SystemClock.elapsedRealtime();
mLightFilterSample = value;
if (mAutoBrightessEnabled && mLightFilterEnabled) {
if (mLightFilterRunning && mLightSensorValue != -1) {
// Large changes -> quick response
int diff = value - (int)mLightSensorValue;
if (mLightFilterReset != -1 && diff > mLightFilterReset && // Only increasing
mLightSensorValue < 1500) { // Only "indoors"
if (mDebugLightSensor) {
Slog.d(TAGF, "reset cause: " + value +
" " + mLightSensorValue + " " + diff);
}
// Push filter faster towards sensor value
lightFilterReset((int)(mLightSensorValue + diff / 2f));
}
if (mDebugLightSensor) {
Slog.d(TAGF, "sample: " + value);
}
} else {
if (mLightSensorValue == -1 ||
milliseconds < mLastScreenOnTime + mLightSensorWarmupTime) {
// process the value immediately if screen has just turned on
lightFilterReset(-1);
lightSensorChangedLocked(value, true);
}
if (!mLightFilterRunning) {
if (mDebugLightSensor) {
Slog.d(TAGF, "start: " + value);
}
mLightFilterRunning = true;
mHandler.postDelayed(mLightFilterTask, LIGHT_SENSOR_DELAY);
}
}
return;
}

// Light filter disabled
if (mLightSensorValue == -1
|| milliseconds < mLastScreenOnTime + mLightSensorWarmupTime
|| mWaitingForFirstLightSensor) {
Expand Down Expand Up @@ -3810,66 +3846,6 @@ public void onSensorChanged(SensorEvent event) {
}
mWaitingForFirstLightSensor = false;
}

int value = (int)event.values[0];
long milliseconds = SystemClock.elapsedRealtime();
if (mDebugLightSensor) {
Slog.d(TAG, "onSensorChanged: light value: " + value);
}
mHandler.removeCallbacks(mAutoBrightnessTask);
mLightFilterSample = value;
if (mAutoBrightessEnabled && mLightFilterEnabled) {
if (mLightFilterRunning && mLightSensorValue != -1) {
// Large changes -> quick response
int diff = value - (int)mLightSensorValue;
if (mLightFilterReset != -1 && diff > mLightFilterReset && // Only increasing
mLightSensorValue < 1500) { // Only "indoors"
if (mDebugLightSensor) {
Slog.d(TAGF, "reset cause: " + value +
" " + mLightSensorValue + " " + diff);
}
// Push filter faster towards sensor value
lightFilterReset((int)(mLightSensorValue + diff / 2f));
}
if (mDebugLightSensor) {
Slog.d(TAGF, "sample: " + value);
}
} else {
if (mLightSensorValue == -1 ||
milliseconds < mLastScreenOnTime + mLightSensorWarmupTime) {
// process the value immediately if screen has just turned on
lightFilterReset(-1);
lightSensorChangedLocked(value, true);
}
if (!mLightFilterRunning) {
if (mDebugLightSensor) {
Slog.d(TAGF, "start: " + value);
}
mLightFilterRunning = true;
mHandler.postDelayed(mLightFilterTask, LIGHT_SENSOR_DELAY);
}
}
return;
}

if (mLightSensorValue != value) {
if (mLightSensorValue == -1 ||
milliseconds < mLastScreenOnTime + mLightSensorWarmupTime) {
// process the value immediately if screen has just turned on
lightSensorChangedLocked(value, true);
} else {
// delay processing to debounce the sensor
mHandler.removeCallbacks(mAutoBrightnessTask);
mLightSensorPendingDecrease = (value < mLightSensorValue);
mLightSensorPendingIncrease = (value > mLightSensorValue);
if (mLightSensorPendingDecrease || mLightSensorPendingIncrease) {
mLightSensorPendingValue = value;
mHandler.postDelayed(mAutoBrightnessTask, LIGHT_SENSOR_DELAY);
}
}
} else {
mLightSensorPendingValue = value;
}
}
}

Expand Down

0 comments on commit 5153459

Please sign in to comment.