Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96a2c341 authored by Steve Kondik's avatar Steve Kondik
Browse files

power: Fix locking for wakeup proximity check

 * Often I'm noticing high power consumption due to the proximity sensor
   never turning off. Add synchronization around this code to ensure
   ordering.

Change-Id: I8ccf3152166cd896e0ce2551c01b8ac8f501d782
parent b055ea85
Loading
Loading
Loading
Loading
+28 −20
Original line number Diff line number Diff line
@@ -3004,6 +3004,12 @@ public final class PowerManagerService extends SystemService
    }

    private void cleanupProximity() {
        synchronized (mProximityWakeLock) {
            cleanupProximityLocked();
        }
    }

    private void cleanupProximityLocked() {
        if (mProximityWakeLock.isHeld()) {
            mProximityWakeLock.release();
        }
@@ -3277,11 +3283,12 @@ public final class PowerManagerService extends SystemService
                r.run();
                return;
            }
            synchronized (mProximityWakeLock) {
                mProximityWakeLock.acquire();
                mProximityListener = new SensorEventListener() {
                    @Override
                    public void onSensorChanged(SensorEvent event) {
                    cleanupProximity();
                        cleanupProximityLocked();
                        if (!mHandler.hasMessages(MSG_WAKE_UP)) {
                            Slog.w(TAG, "The proximity sensor took too long, wake event already triggered!");
                            return;
@@ -3300,6 +3307,7 @@ public final class PowerManagerService extends SystemService
                mSensorManager.registerListener(mProximityListener,
                       mProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);
            }
        }

        @Override // Binder call
        public void wakeUpWithProximityCheck(long eventTime) {