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

Commit f9bbea5f authored by Shawn Lee's avatar Shawn Lee Committed by Android (Google) Code Review
Browse files

Merge "Stay registered to proximity sensor while activities are occluding keyguard" into main

parents ba1178b1 9a29824c
Loading
Loading
Loading
Loading
+28 −2
Original line number Diff line number Diff line
@@ -97,6 +97,14 @@ class FalsingCollectorImpl implements FalsingCollector {
                }
            };

    private final KeyguardStateController.Callback mKeyguardStateControllerCallback =
            new KeyguardStateController.Callback() {
                @Override
                public void onKeyguardShowingChanged() {
                    updateSensorRegistration();
                }
            };


    private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback =
            new KeyguardUpdateMonitorCallback() {
@@ -176,6 +184,8 @@ class FalsingCollectorImpl implements FalsingCollector {
        mStatusBarStateController.addCallback(mStatusBarStateListener);
        mState = mStatusBarStateController.getState();

        mKeyguardStateController.addCallback(mKeyguardStateControllerCallback);

        mKeyguardUpdateMonitor.registerCallback(mKeyguardUpdateCallback);

        mJavaAdapter.alwaysCollectFlow(
@@ -364,6 +374,24 @@ class FalsingCollectorImpl implements FalsingCollector {
        } else {
            sessionEnd();
        }
        updateSensorRegistration();
    }

    private boolean shouldBeRegisteredToSensors() {
        return mScreenOn
                && (mState == StatusBarState.KEYGUARD
                || (mState == StatusBarState.SHADE
                && mKeyguardStateController.isOccluded()
                && mKeyguardStateController.isShowing()))
                && !mShowingAod;
    }

    private void updateSensorRegistration() {
        if (shouldBeRegisteredToSensors()) {
            registerSensors();
        } else {
            unregisterSensors();
        }
    }

    private void sessionStart() {
@@ -371,7 +399,6 @@ class FalsingCollectorImpl implements FalsingCollector {
            logDebug("Starting Session");
            mSessionStarted = true;
            mFalsingDataProvider.setJustUnlockedWithFace(false);
            registerSensors();
            mFalsingDataProvider.onSessionStarted();
        }
    }
@@ -380,7 +407,6 @@ class FalsingCollectorImpl implements FalsingCollector {
        if (mSessionStarted) {
            logDebug("Ending Session");
            mSessionStarted = false;
            unregisterSensors();
            mFalsingDataProvider.onSessionEnd();
        }
    }
+14 −0
Original line number Diff line number Diff line
@@ -187,6 +187,20 @@ public class FalsingCollectorImplTest extends SysuiTestCase {
        verify(mProximitySensor).unregister(any(ThresholdSensor.Listener.class));
    }

    @Test
    public void testRegisterSensor_OccludingActivity() {
        when(mKeyguardStateController.isOccluded()).thenReturn(true);

        ArgumentCaptor<StatusBarStateController.StateListener> stateListenerArgumentCaptor =
                ArgumentCaptor.forClass(StatusBarStateController.StateListener.class);
        verify(mStatusBarStateController).addCallback(stateListenerArgumentCaptor.capture());

        mFalsingCollector.onScreenTurningOn();
        reset(mProximitySensor);
        stateListenerArgumentCaptor.getValue().onStateChanged(StatusBarState.SHADE);
        verify(mProximitySensor).register(any(ThresholdSensor.Listener.class));
    }

    @Test
    public void testPassThroughGesture() {
        MotionEvent down = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0);