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

Commit 57a73fc2 authored by Piotr Wilczyński's avatar Piotr Wilczyński
Browse files

Stop the screen off brightness sensor controller

Bug: 264343121
Test: atest ScreenOffBrightnessSensorControllerTest
Change-Id: Ib51e1812acdd503f348b2034514c97d5acbe7e4e
parent f1f50ee2
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -860,6 +860,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                mAutomaticBrightnessController.stop();
                mAutomaticBrightnessController.stop();
            }
            }


            if (mScreenOffBrightnessSensorController != null) {
                mScreenOffBrightnessSensorController.stop();
            }

            if (mBrightnessSetting != null) {
            if (mBrightnessSetting != null) {
                mBrightnessSetting.unregisterListener(mBrightnessSettingListener);
                mBrightnessSetting.unregisterListener(mBrightnessSettingListener);
            }
            }
@@ -1104,6 +1108,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            mBrightnessEventRingBuffer =
            mBrightnessEventRingBuffer =
                    new RingBuffer<>(BrightnessEvent.class, RINGBUFFER_MAX);
                    new RingBuffer<>(BrightnessEvent.class, RINGBUFFER_MAX);


            if (mScreenOffBrightnessSensorController != null) {
                mScreenOffBrightnessSensorController.stop();
            }
            loadScreenOffBrightnessSensor();
            loadScreenOffBrightnessSensor();
            int[] sensorValueToLux = mDisplayDeviceConfig.getScreenOffBrightnessSensorValueToLux();
            int[] sensorValueToLux = mDisplayDeviceConfig.getScreenOffBrightnessSensorValueToLux();
            if (mScreenOffBrightnessSensor != null && sensorValueToLux != null) {
            if (mScreenOffBrightnessSensor != null && sensorValueToLux != null) {
+4 −0
Original line number Original line Diff line number Diff line
@@ -92,6 +92,10 @@ public class ScreenOffBrightnessSensorController implements SensorEventListener
        }
        }
    }
    }


    void stop() {
        setLightSensorEnabled(false);
    }

    float getAutomaticScreenBrightness() {
    float getAutomaticScreenBrightness() {
        if (mLastSensorValue < 0 || mLastSensorValue >= mSensorValueToLux.length
        if (mLastSensorValue < 0 || mLastSensorValue >= mSensorValueToLux.length
                || (!mRegistered
                || (!mRegistered
+10 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ import androidx.test.runner.AndroidJUnit4;


import com.android.server.testutils.OffsettableClock;
import com.android.server.testutils.OffsettableClock;


import org.junit.After;
import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
@@ -73,6 +74,15 @@ public class ScreenOffBrightnessSensorControllerTest {
        );
        );
    }
    }


    @After
    public void tearDown() {
        if (mController != null) {
            // Stop the update Brightness loop.
            mController.stop();
            mController = null;
        }
    }

    @Test
    @Test
    public void testBrightness() throws Exception {
    public void testBrightness() throws Exception {
        when(mSensorManager.registerListener(any(SensorEventListener.class), eq(mLightSensor),
        when(mSensorManager.registerListener(any(SensorEventListener.class), eq(mLightSensor),