From 4f8dbef6bdb5fa3dfdf9c6a268c3f742af366cf6 Mon Sep 17 00:00:00 2001 From: Beverly Date: Wed, 7 Dec 2022 22:02:39 +0000 Subject: [PATCH] Allow UDFPS to be triggerd from AOD_PAUSED state And from the AOD_PAUSING state. So if users immediately attempt UDFPS right after the prox sensor has become unblocked, the authentication will still go through rather than being dropped. The UDFPS longpress gesture is also prox gated (by the sensor), so this is a safe change. Test: programmatically set DOZE_AOD_PAUSED and see that UDFPS longpress can still be triggered when prox isn't blocked Test: atest DozeTriggersTest Fixes: 244011650 Change-Id: Ic4f7956cb6082bec5c55d5177c8546e12b969378 --- .../com/android/systemui/doze/DozeLog.java | 13 ++++++ .../com/android/systemui/doze/DozeLogger.kt | 8 ++++ .../android/systemui/doze/DozeTriggers.java | 44 ++++++++++--------- .../systemui/doze/DozeTriggersTest.java | 38 ++++++++++++++++ 4 files changed, 82 insertions(+), 21 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java b/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java index 0c14ed5c21641..5d21349fce114 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java @@ -28,6 +28,8 @@ import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dump.DumpManager; import com.android.systemui.statusbar.policy.DevicePostureController; +import com.google.errorprone.annotations.CompileTimeConstant; + import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -79,6 +81,13 @@ public class DozeLog implements Dumpable { dumpManager.registerDumpable("DumpStats", this); } + /** + * Log debug message to LogBuffer. + */ + public void d(@CompileTimeConstant String msg) { + mLogger.log(msg); + } + /** * Appends pickup wakeup event to the logs */ @@ -88,6 +97,10 @@ public class DozeLog implements Dumpable { : mPickupPulseNotNearVibrationStats).append(); } + public void traceSetIgnoreTouchWhilePulsing(boolean ignoreTouch) { + mLogger.logSetIgnoreTouchWhilePulsing(ignoreTouch); + } + /** * Appends pulse started event to the logs. * @param reason why the pulse started diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt b/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt index b5dbe21a2cf7f..d19c6ec011092 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeLogger.kt @@ -364,6 +364,14 @@ class DozeLogger @Inject constructor( }) } + fun logSetIgnoreTouchWhilePulsing(ignoreTouchWhilePulsing: Boolean) { + buffer.log(TAG, DEBUG, { + bool1 = ignoreTouchWhilePulsing + }, { + "Prox changed while pulsing. setIgnoreTouchWhilePulsing=$bool1" + }) + } + fun log(@CompileTimeConstant msg: String) { buffer.log(TAG, DEBUG, msg) } diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java index 5daf1ceaf5925..3f9f14c620b5f 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java @@ -333,15 +333,18 @@ public class DozeTriggers implements DozeMachine.Part { } gentleWakeUp(pulseReason); } else if (isUdfpsLongPress) { - final State state = mMachine.getState(); - if (state == State.DOZE_AOD || state == State.DOZE) { + if (canPulse(mMachine.getState(), true)) { + mDozeLog.d("updfsLongPress - setting aodInterruptRunnable to run when " + + "the display is on"); // Since the gesture won't be received by the UDFPS view, we need to // manually inject an event once the display is ON mAodInterruptRunnable = () -> - mAuthController.onAodInterrupt((int) screenX, (int) screenY, - rawValues[3] /* major */, rawValues[4] /* minor */); + mAuthController.onAodInterrupt((int) screenX, (int) screenY, + rawValues[3] /* major */, rawValues[4] /* minor */); + } else { + mDozeLog.d("udfpsLongPress - Not sending aodInterrupt. " + + "Unsupported doze state."); } - requestPulse(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, true, null); } else { mDozeHost.extendPulse(pulseReason); @@ -380,7 +383,7 @@ public class DozeTriggers implements DozeMachine.Part { // when a new event is arriving. This means that a state transition might have happened // and the proximity check is now obsolete. if (mMachine.isExecutingTransition()) { - Log.w(TAG, "onProximityFar called during transition. Ignoring sensor response."); + mDozeLog.d("onProximityFar called during transition. Ignoring sensor response."); return; } @@ -392,21 +395,15 @@ public class DozeTriggers implements DozeMachine.Part { if (state == DozeMachine.State.DOZE_PULSING || state == DozeMachine.State.DOZE_PULSING_BRIGHT) { - if (DEBUG) { - Log.i(TAG, "Prox changed, ignore touch = " + near); - } + mDozeLog.traceSetIgnoreTouchWhilePulsing(near); mDozeHost.onIgnoreTouchWhilePulsing(near); } if (far && (paused || pausing)) { - if (DEBUG) { - Log.i(TAG, "Prox FAR, unpausing AOD"); - } + mDozeLog.d("Prox FAR, unpausing AOD"); mMachine.requestState(DozeMachine.State.DOZE_AOD); } else if (near && aod) { - if (DEBUG) { - Log.i(TAG, "Prox NEAR, pausing AOD"); - } + mDozeLog.d("Prox NEAR, starting pausing AOD countdown"); mMachine.requestState(DozeMachine.State.DOZE_AOD_PAUSING); } } @@ -551,12 +548,13 @@ public class DozeTriggers implements DozeMachine.Part { return; } - if (!mAllowPulseTriggers || mDozeHost.isPulsePending() || !canPulse(dozeState)) { + if (!mAllowPulseTriggers || mDozeHost.isPulsePending() + || !canPulse(dozeState, performedProxCheck)) { if (!mAllowPulseTriggers) { mDozeLog.tracePulseDropped("requestPulse - !mAllowPulseTriggers"); } else if (mDozeHost.isPulsePending()) { mDozeLog.tracePulseDropped("requestPulse - pulsePending"); - } else if (!canPulse(dozeState)) { + } else if (!canPulse(dozeState, performedProxCheck)) { mDozeLog.tracePulseDropped("requestPulse - dozeState cannot pulse", dozeState); } runIfNotNull(onPulseSuppressedListener); @@ -574,14 +572,15 @@ public class DozeTriggers implements DozeMachine.Part { // not in pocket, continue pulsing final boolean isPulsePending = mDozeHost.isPulsePending(); mDozeHost.setPulsePending(false); - if (!isPulsePending || mDozeHost.isPulsingBlocked() || !canPulse(dozeState)) { + if (!isPulsePending || mDozeHost.isPulsingBlocked() + || !canPulse(dozeState, performedProxCheck)) { if (!isPulsePending) { mDozeLog.tracePulseDropped("continuePulseRequest - pulse no longer" + " pending, pulse was cancelled before it could start" + " transitioning to pulsing state."); } else if (mDozeHost.isPulsingBlocked()) { mDozeLog.tracePulseDropped("continuePulseRequest - pulsingBlocked"); - } else if (!canPulse(dozeState)) { + } else if (!canPulse(dozeState, performedProxCheck)) { mDozeLog.tracePulseDropped("continuePulseRequest" + " - doze state cannot pulse", dozeState); } @@ -598,10 +597,13 @@ public class DozeTriggers implements DozeMachine.Part { .ifPresent(uiEventEnum -> mUiEventLogger.log(uiEventEnum, getKeyguardSessionId())); } - private boolean canPulse(DozeMachine.State dozeState) { + private boolean canPulse(DozeMachine.State dozeState, boolean pulsePerformedProximityCheck) { + final boolean dozePausedOrPausing = dozeState == State.DOZE_AOD_PAUSED + || dozeState == State.DOZE_AOD_PAUSING; return dozeState == DozeMachine.State.DOZE || dozeState == DozeMachine.State.DOZE_AOD - || dozeState == DozeMachine.State.DOZE_AOD_DOCKED; + || dozeState == DozeMachine.State.DOZE_AOD_DOCKED + || (dozePausedOrPausing && pulsePerformedProximityCheck); } @Nullable diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java index 82432ce31fa24..b66a454638ac9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java @@ -357,6 +357,44 @@ public class DozeTriggersTest extends SysuiTestCase { verify(mDozeLog).tracePulseDropped(anyString(), eq(null)); } + @Test + public void udfpsLongPress_triggeredWhenAodPaused() { + // GIVEN device is DOZE_AOD_PAUSED + when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_AOD_PAUSED); + + // WHEN udfps long-press is triggered + mTriggers.onSensor(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, 100, 100, + new float[]{0, 1, 2, 3, 4}); + + // THEN the pulse is NOT dropped + verify(mDozeLog, never()).tracePulseDropped(anyString(), any()); + + // WHEN the screen state is ON + mTriggers.onScreenState(Display.STATE_ON); + + // THEN aod interrupt is sent + verify(mAuthController).onAodInterrupt(anyInt(), anyInt(), anyFloat(), anyFloat()); + } + + @Test + public void udfpsLongPress_triggeredWhenAodPausing() { + // GIVEN device is DOZE_AOD_PAUSED + when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_AOD_PAUSING); + + // WHEN udfps long-press is triggered + mTriggers.onSensor(DozeLog.REASON_SENSOR_UDFPS_LONG_PRESS, 100, 100, + new float[]{0, 1, 2, 3, 4}); + + // THEN the pulse is NOT dropped + verify(mDozeLog, never()).tracePulseDropped(anyString(), any()); + + // WHEN the screen state is ON + mTriggers.onScreenState(Display.STATE_ON); + + // THEN aod interrupt is sent + verify(mAuthController).onAodInterrupt(anyInt(), anyInt(), anyFloat(), anyFloat()); + } + private void waitForSensorManager() { mExecutor.runAllReady(); }