Merge "Responsiveness improvement for BrightnessObserver" into qt-r1-dev am: 6348d1e923
am: 6e023c8d61
Change-Id: Iecd43d1979d42c5fb026b6047bd0f114c0197866
This commit is contained in:
@@ -728,6 +728,7 @@ public class DisplayModeDirector {
|
|||||||
|
|
||||||
private SensorManager mSensorManager;
|
private SensorManager mSensorManager;
|
||||||
private Sensor mLightSensor;
|
private Sensor mLightSensor;
|
||||||
|
private LightSensorEventListener mLightSensorListener = new LightSensorEventListener();
|
||||||
// Take it as low brightness before valid sensor data comes
|
// Take it as low brightness before valid sensor data comes
|
||||||
private float mAmbientLux = -1.0f;
|
private float mAmbientLux = -1.0f;
|
||||||
private AmbientFilter mAmbientFilter;
|
private AmbientFilter mAmbientFilter;
|
||||||
@@ -907,19 +908,40 @@ public class DisplayModeDirector {
|
|||||||
mSensorManager.registerListener(mLightSensorListener,
|
mSensorManager.registerListener(mLightSensorListener,
|
||||||
mLightSensor, LIGHT_SENSOR_RATE_MS * 1000, mHandler);
|
mLightSensor, LIGHT_SENSOR_RATE_MS * 1000, mHandler);
|
||||||
} else {
|
} else {
|
||||||
|
mLightSensorListener.removeCallbacks();
|
||||||
mSensorManager.unregisterListener(mLightSensorListener);
|
mSensorManager.unregisterListener(mLightSensorListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final SensorEventListener mLightSensorListener = new SensorEventListener() {
|
private final class LightSensorEventListener implements SensorEventListener {
|
||||||
|
final private static int INJECT_EVENTS_INTERVAL_MS = LIGHT_SENSOR_RATE_MS;
|
||||||
|
private float mLastSensorData;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSensorChanged(SensorEvent event) {
|
public void onSensorChanged(SensorEvent event) {
|
||||||
long now = SystemClock.uptimeMillis();
|
mLastSensorData = event.values[0];
|
||||||
mAmbientFilter.addValue(now, event.values[0]);
|
if (DEBUG) {
|
||||||
mAmbientLux = mAmbientFilter.getEstimate(now);
|
Slog.d(TAG, "On sensor changed: " + mLastSensorData);
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (mLock) {
|
boolean zoneChanged = isDifferentZone(mLastSensorData, mAmbientLux);
|
||||||
onBrightnessChangedLocked();
|
if (zoneChanged && mLastSensorData < mAmbientLux) {
|
||||||
|
// Easier to see flicker at lower brightness environment. Forget the history to
|
||||||
|
// get immediate response.
|
||||||
|
mAmbientFilter.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
long now = SystemClock.uptimeMillis();
|
||||||
|
mAmbientFilter.addValue(now, mLastSensorData);
|
||||||
|
|
||||||
|
mHandler.removeCallbacks(mInjectSensorEventRunnable);
|
||||||
|
processSensorData(now);
|
||||||
|
|
||||||
|
if (zoneChanged && mLastSensorData > mAmbientLux) {
|
||||||
|
// Sensor may not report new event if there is no brightness change.
|
||||||
|
// Need to keep querying the temporal filter for the latest estimation,
|
||||||
|
// until enter in higher lux zone or is interrupted by a new sensor event.
|
||||||
|
mHandler.postDelayed(mInjectSensorEventRunnable, INJECT_EVENTS_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -927,6 +949,47 @@ public class DisplayModeDirector {
|
|||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||||
// Not used.
|
// Not used.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeCallbacks() {
|
||||||
|
mHandler.removeCallbacks(mInjectSensorEventRunnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processSensorData(long now) {
|
||||||
|
mAmbientLux = mAmbientFilter.getEstimate(now);
|
||||||
|
|
||||||
|
synchronized (mLock) {
|
||||||
|
onBrightnessChangedLocked();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDifferentZone(float lux1, float lux2) {
|
||||||
|
for (int z = 0; z < mAmbientBrightnessThresholds.length; z++) {
|
||||||
|
final float boundary = mAmbientBrightnessThresholds[z];
|
||||||
|
|
||||||
|
// Test each boundary. See if the current value and the new value are at
|
||||||
|
// different sides.
|
||||||
|
if ((lux1 <= boundary && lux2 > boundary)
|
||||||
|
|| (lux1 > boundary && lux2 <= boundary)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Runnable mInjectSensorEventRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
long now = SystemClock.uptimeMillis();
|
||||||
|
// No need to really inject the last event into a temporal filter.
|
||||||
|
processSensorData(now);
|
||||||
|
|
||||||
|
// Inject next event if there is a possible zone change.
|
||||||
|
if (isDifferentZone(mLastSensorData, mAmbientLux)) {
|
||||||
|
mHandler.postDelayed(mInjectSensorEventRunnable, INJECT_EVENTS_INTERVAL_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
private final class ScreenStateReceiver extends BroadcastReceiver {
|
private final class ScreenStateReceiver extends BroadcastReceiver {
|
||||||
|
|||||||
Reference in New Issue
Block a user