Merge change I2c6e54e4 into eclair
* changes: Throttle proximity sensor values so we do not process more than one change a second.
This commit is contained in:
@@ -93,6 +93,9 @@ class PowerManagerService extends IPowerManager.Stub
|
|||||||
// How long to wait to debounce light sensor changes.
|
// How long to wait to debounce light sensor changes.
|
||||||
private static final int LIGHT_SENSOR_DELAY = 1000;
|
private static final int LIGHT_SENSOR_DELAY = 1000;
|
||||||
|
|
||||||
|
// For debouncing the proximity sensor.
|
||||||
|
private static final int PROXIMITY_SENSOR_DELAY = 1000;
|
||||||
|
|
||||||
// trigger proximity if distance is less than 5 cm
|
// trigger proximity if distance is less than 5 cm
|
||||||
private static final float PROXIMITY_THRESHOLD = 5.0f;
|
private static final float PROXIMITY_THRESHOLD = 5.0f;
|
||||||
|
|
||||||
@@ -162,6 +165,8 @@ class PowerManagerService extends IPowerManager.Stub
|
|||||||
private boolean mKeyboardVisible = false;
|
private boolean mKeyboardVisible = false;
|
||||||
private boolean mUserActivityAllowed = true;
|
private boolean mUserActivityAllowed = true;
|
||||||
private boolean mProximitySensorActive = false;
|
private boolean mProximitySensorActive = false;
|
||||||
|
private int mProximityPendingValue = -1; // -1 == nothing, 0 == inactive, 1 == active
|
||||||
|
private long mLastProximityEventTime;
|
||||||
private int mTotalDelaySetting;
|
private int mTotalDelaySetting;
|
||||||
private int mKeylightDelay;
|
private int mKeylightDelay;
|
||||||
private int mDimDelay;
|
private int mDimDelay;
|
||||||
@@ -886,6 +891,8 @@ class PowerManagerService extends IPowerManager.Stub
|
|||||||
pw.println(" mStayOnWhilePluggedInPartialLock=" + mStayOnWhilePluggedInPartialLock);
|
pw.println(" mStayOnWhilePluggedInPartialLock=" + mStayOnWhilePluggedInPartialLock);
|
||||||
pw.println(" mPreventScreenOnPartialLock=" + mPreventScreenOnPartialLock);
|
pw.println(" mPreventScreenOnPartialLock=" + mPreventScreenOnPartialLock);
|
||||||
pw.println(" mProximitySensorActive=" + mProximitySensorActive);
|
pw.println(" mProximitySensorActive=" + mProximitySensorActive);
|
||||||
|
pw.println(" mProximityPendingValue=" + mProximityPendingValue);
|
||||||
|
pw.println(" mLastProximityEventTime=" + mLastProximityEventTime);
|
||||||
pw.println(" mLightSensorEnabled=" + mLightSensorEnabled);
|
pw.println(" mLightSensorEnabled=" + mLightSensorEnabled);
|
||||||
pw.println(" mLightSensorValue=" + mLightSensorValue);
|
pw.println(" mLightSensorValue=" + mLightSensorValue);
|
||||||
pw.println(" mLightSensorPendingValue=" + mLightSensorPendingValue);
|
pw.println(" mLightSensorPendingValue=" + mLightSensorPendingValue);
|
||||||
@@ -1895,6 +1902,17 @@ class PowerManagerService extends IPowerManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Runnable mProximityTask = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
synchronized (mLocks) {
|
||||||
|
if (mProximityPendingValue != -1) {
|
||||||
|
proximityChangedLocked(mProximityPendingValue == 1);
|
||||||
|
mProximityPendingValue = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private Runnable mAutoBrightnessTask = new Runnable() {
|
private Runnable mAutoBrightnessTask = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
synchronized (mLocks) {
|
synchronized (mLocks) {
|
||||||
@@ -2327,6 +2345,7 @@ class PowerManagerService extends IPowerManager.Stub
|
|||||||
long identity = Binder.clearCallingIdentity();
|
long identity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
mSensorManager.unregisterListener(mProximityListener);
|
mSensorManager.unregisterListener(mProximityListener);
|
||||||
|
mHandler.removeCallbacks(mProximityTask);
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(identity);
|
Binder.restoreCallingIdentity(identity);
|
||||||
}
|
}
|
||||||
@@ -2338,6 +2357,22 @@ class PowerManagerService extends IPowerManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void proximityChangedLocked(boolean active) {
|
||||||
|
if (mSpew) {
|
||||||
|
Log.d(TAG, "proximityChangedLocked, active: " + active);
|
||||||
|
}
|
||||||
|
if (active) {
|
||||||
|
goToSleepLocked(SystemClock.uptimeMillis());
|
||||||
|
mProximitySensorActive = true;
|
||||||
|
} else {
|
||||||
|
// proximity sensor negative events trigger as user activity.
|
||||||
|
// temporarily set mUserActivityAllowed to true so this will work
|
||||||
|
// even when the keyguard is on.
|
||||||
|
mProximitySensorActive = false;
|
||||||
|
forceUserActivityLocked();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void enableLightSensor(boolean enable) {
|
private void enableLightSensor(boolean enable) {
|
||||||
if (mDebugLightSensor) {
|
if (mDebugLightSensor) {
|
||||||
Log.d(TAG, "enableLightSensor " + enable);
|
Log.d(TAG, "enableLightSensor " + enable);
|
||||||
@@ -2365,23 +2400,22 @@ class PowerManagerService extends IPowerManager.Stub
|
|||||||
long milliseconds = event.timestamp / 1000000;
|
long milliseconds = event.timestamp / 1000000;
|
||||||
synchronized (mLocks) {
|
synchronized (mLocks) {
|
||||||
float distance = event.values[0];
|
float distance = event.values[0];
|
||||||
|
long timeSinceLastEvent = milliseconds - mLastProximityEventTime;
|
||||||
|
mLastProximityEventTime = milliseconds;
|
||||||
|
mHandler.removeCallbacks(mProximityTask);
|
||||||
|
|
||||||
// compare against getMaximumRange to support sensors that only return 0 or 1
|
// compare against getMaximumRange to support sensors that only return 0 or 1
|
||||||
if (distance >= 0.0 && distance < PROXIMITY_THRESHOLD &&
|
boolean active = (distance >= 0.0 && distance < PROXIMITY_THRESHOLD &&
|
||||||
distance < mProximitySensor.getMaximumRange()) {
|
distance < mProximitySensor.getMaximumRange());
|
||||||
if (mSpew) {
|
|
||||||
Log.d(TAG, "onSensorChanged: proximity active, distance: " + distance);
|
if (timeSinceLastEvent < PROXIMITY_SENSOR_DELAY) {
|
||||||
}
|
// enforce delaying atleast PROXIMITY_SENSOR_DELAY before processing
|
||||||
goToSleepLocked(milliseconds);
|
mProximityPendingValue = (active ? 1 : 0);
|
||||||
mProximitySensorActive = true;
|
mHandler.postDelayed(mProximityTask, PROXIMITY_SENSOR_DELAY - timeSinceLastEvent);
|
||||||
} else {
|
} else {
|
||||||
// proximity sensor negative events trigger as user activity.
|
// process the value immediately
|
||||||
// temporarily set mUserActivityAllowed to true so this will work
|
mProximityPendingValue = -1;
|
||||||
// even when the keyguard is on.
|
proximityChangedLocked(active);
|
||||||
if (mSpew) {
|
|
||||||
Log.d(TAG, "onSensorChanged: proximity inactive, distance: " + distance);
|
|
||||||
}
|
|
||||||
mProximitySensorActive = false;
|
|
||||||
forceUserActivityLocked();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user