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

Commit 2ff3babf authored by Alex Medina's avatar Alex Medina Committed by Gerrit Code Review
Browse files

Merge "Cherry pick the cl to aosp to unblock partner. Check light sensor is...

Merge "Cherry pick the cl to aosp to unblock partner. Check light sensor is null for biometric logging" into main
parents a2e44448 5eda411d
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -179,15 +179,18 @@ final class ALSProbe implements Probe {
            nextConsumer.consume(current);
        } else if (mNextConsumer != null) {
            mNextConsumer.add(nextConsumer);
        } else {
        } else if (mLightSensor != null) {
            mDestroyed = false;
            mNextConsumer = nextConsumer;
            enableLightSensorLoggingLocked();
        } else {
            Slog.w(TAG, "No light sensor - use current to consume");
            nextConsumer.consume(current);
        }
    }

    private void enableLightSensorLoggingLocked() {
        if (!mEnabled) {
        if (!mEnabled && mLightSensor != null) {
            mEnabled = true;
            mLastAmbientLux = -1;
            mSensorManager.registerListener(mLightSensorListener, mLightSensor,
@@ -201,7 +204,7 @@ final class ALSProbe implements Probe {
    private void disableLightSensorLoggingLocked(boolean destroying) {
        resetTimerLocked(false /* start */);

        if (mEnabled) {
        if (mEnabled && mLightSensor != null) {
            mEnabled = false;
            if (!destroying) {
                mLastAmbientLux = -1;
+15 −0
Original line number Diff line number Diff line
@@ -344,6 +344,21 @@ public class ALSProbeTest {
        verifyNoMoreInteractions(mSensorManager);
    }

    @Test
    public void testAwaitLuxWhenNoLightSensor() {
        when(mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT)).thenReturn(null);
        mProbe = new ALSProbe(mSensorManager, new Handler(mLooper.getLooper()), TIMEOUT_MS - 1);

        AtomicInteger lux = new AtomicInteger(-5);
        mProbe.awaitNextLux((v) -> lux.set(Math.round(v)), null /* handler */);

        // Verify that no light sensor will be registered.
        verify(mSensorManager, times(0)).registerListener(
                mSensorEventListenerCaptor.capture(), any(), anyInt());

        assertThat(lux.get()).isEqualTo(-1);
    }

    private void moveTimeBy(long millis) {
        mLooper.moveTimeForward(millis);
        mLooper.processAllMessages();