use of android.hardware.SensorEvent in project android_frameworks_base by DirtyUnicorns.
the class PowerManagerService method runPostProximityCheck.
private void runPostProximityCheck(final Runnable r) {
if (mSensorManager == null) {
r.run();
return;
}
synchronized (mProximityWakeLock) {
mProximityWakeLock.acquire();
mProximityListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
cleanupProximityLocked();
if (!mHandler.hasMessages(MSG_WAKE_UP)) {
Slog.w(TAG, "Proximity sensor took too long, wake event already triggered!");
return;
}
mHandler.removeMessages(MSG_WAKE_UP);
final float distance = event.values[0];
if (distance >= PROXIMITY_NEAR_THRESHOLD || distance >= mProximitySensor.getMaximumRange()) {
r.run();
} else {
Slog.w(TAG, "Not waking up. Proximity sensor is blocked.");
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// Do nothing
}
};
mSensorManager.registerListener(mProximityListener, mProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);
}
}
Aggregations