From f380fff3c32fef3cfb2f6127b227e7d611690526 Mon Sep 17 00:00:00 2001 From: Shawn Lee Date: Thu, 22 Feb 2024 12:49:23 -0800 Subject: 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 Merged-In: I55f1472593d37f47574d4bf3c40ca7d69f86bad8 --- .../systemui/classifier/FalsingCollectorImpl.java | 30 ++++++++++++++++++++-- .../classifier/FalsingCollectorImplTest.java | 14 ++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/classifier/FalsingCollectorImpl.java b/packages/SystemUI/src/com/android/systemui/classifier/FalsingCollectorImpl.java index 3819e614aca0..4f4f3d0324b3 100644 --- a/packages/SystemUI/src/com/android/systemui/classifier/FalsingCollectorImpl.java +++ b/packages/SystemUI/src/com/android/systemui/classifier/FalsingCollectorImpl.java @@ -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(); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/classifier/FalsingCollectorImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/classifier/FalsingCollectorImplTest.java index 3f13033217b3..45d20dcd9d11 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/classifier/FalsingCollectorImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/classifier/FalsingCollectorImplTest.java @@ -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 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); -- cgit v1.2.3-59-g8ed1b