Search in sources :

Example 6 with SensorEvent

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);
    }
}
Also used : SensorEventListener(android.hardware.SensorEventListener) SensorEvent(android.hardware.SensorEvent) Sensor(android.hardware.Sensor)

Aggregations

SensorEvent (android.hardware.SensorEvent)6 Sensor (android.hardware.Sensor)4 SensorEventListener (android.hardware.SensorEventListener)4 OnProximityListener (com.example.android.recipe071.ProximityManager.OnProximityListener)1 Field (java.lang.reflect.Field)1