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

Commit 9a29824c authored by Shawn Lee's avatar Shawn Lee
Browse files

Stay registered to proximity sensor while activities are occluding keyguard

When a phone call is received while the device's prox sensor is covered (such as when it's face down on a table or in a pocket), we run falsing on all gestures while in the activity as if the sensor is still covered, because we unregister from further updates from the prox sensor once StatusBarState changes from KEYGUARD. This change keeps us subscribed to the prox sensor so we aren't left with stale state in this scenario.

Bug: 297497511
Test: added a unit test, passes existing tests for sensor
Test: manually checked we still unregister from proximity sensor updates when unlocked, in AOD, in lockscreen shade/QS, in bouncer
Flag: NONE
Change-Id: I55f1472593d37f47574d4bf3c40ca7d69f86bad8
parent 0104e414
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);