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

Commit a92e2fe9 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez Committed by Android (Google) Code Review
Browse files

Merge "Cleanup of the flag ONE_WAY_HAPTICS_API_MIGRATION on UdfpsController" into main

parents 3d7854e6 bf8833a5
Loading
Loading
Loading
Loading
+14 −34
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import static android.hardware.biometrics.BiometricOverlayConstants.REASON_ENROL

import static com.android.internal.util.Preconditions.checkNotNull;
import static com.android.systemui.classifier.Classifier.UDFPS_AUTHENTICATION;
import static com.android.systemui.flags.Flags.ONE_WAY_HAPTICS_API_MIGRATION;

import android.content.BroadcastReceiver;
import android.content.Context;
@@ -45,7 +44,6 @@ import android.hardware.input.InputManager;
import android.os.Build;
import android.os.Handler;
import android.os.PowerManager;
import android.os.Process;
import android.os.Trace;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
@@ -730,7 +728,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
    @VisibleForTesting
    public void playStartHaptic() {
        if (mAccessibilityManager.isTouchExplorationEnabled()) {
            if (mFeatureFlags.isEnabled(ONE_WAY_HAPTICS_API_MIGRATION)) {
            if (mOverlay != null && mOverlay.getOverlayView() != null) {
                mVibrator.performHapticFeedback(
                        mOverlay.getOverlayView(),
@@ -740,14 +737,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
                Log.e(TAG, "No haptics played. Could not obtain overlay view to perform"
                        + "vibration. Either the controller overlay is null or has no view");
            }
            } else {
                mVibrator.vibrate(
                        Process.myUid(),
                        mContext.getOpPackageName(),
                        EFFECT_CLICK,
                        "udfps-onStart-click",
                        UDFPS_VIBRATION_ATTRIBUTES);
            }
        }
    }

@@ -840,7 +829,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
            mKeyguardViewManager.showPrimaryBouncer(true);

            // play the same haptic as the LockIconViewController longpress
            if (mFeatureFlags.isEnabled(ONE_WAY_HAPTICS_API_MIGRATION)) {
            if (mOverlay != null && mOverlay.getOverlayView() != null) {
                mVibrator.performHapticFeedback(
                        mOverlay.getOverlayView(),
@@ -850,14 +838,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
                Log.e(TAG, "No haptics played. Could not obtain overlay view to perform"
                        + "vibration. Either the controller overlay is null or has no view");
            }
            } else {
                mVibrator.vibrate(
                        Process.myUid(),
                        mContext.getOpPackageName(),
                        UdfpsController.EFFECT_CLICK,
                        "aod-lock-icon-longpress",
                        LOCK_ICON_VIBRATION_ATTRIBUTES);
            }
            return;
        }

+1 −83
Original line number Diff line number Diff line
@@ -23,9 +23,7 @@ import static android.view.MotionEvent.ACTION_UP;

import static com.android.internal.util.FunctionalUtils.ThrowingConsumer;
import static com.android.systemui.classifier.Classifier.UDFPS_AUTHENTICATION;
import static com.android.systemui.flags.Flags.ONE_WAY_HAPTICS_API_MIGRATION;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

@@ -34,7 +32,6 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
@@ -59,7 +56,6 @@ import android.hardware.input.InputManager;
import android.os.Handler;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.VibrationAttributes;
import android.testing.TestableLooper.RunWithLooper;
import android.util.Pair;
import android.view.HapticFeedbackConstants;
@@ -1051,35 +1047,6 @@ public class UdfpsControllerTest extends SysuiTestCase {
        mHoverListenerCaptor.getValue().onHover(mUdfpsView, enterEvent);
        enterEvent.recycle();

        // THEN tick haptic is played
        verify(mVibrator).vibrate(
                anyInt(),
                anyString(),
                any(),
                eq("udfps-onStart-click"),
                eq(UdfpsController.UDFPS_VIBRATION_ATTRIBUTES));

        // THEN make sure vibration attributes has so that it always will play the haptic,
        // even in battery saver mode
        assertEquals(VibrationAttributes.USAGE_COMMUNICATION_REQUEST,
                UdfpsController.UDFPS_VIBRATION_ATTRIBUTES.getUsage());
    }

    @Test
    public void playHapticOnTouchUdfpsArea_a11yTouchExplorationEnabled_oneWayHapticsEnabled()
            throws RemoteException {
        when(mFeatureFlags.isEnabled(ONE_WAY_HAPTICS_API_MIGRATION)).thenReturn(true);

        final Pair<TouchProcessorResult, TouchProcessorResult> touchProcessorResult =
                givenFingerEvent(InteractionEvent.DOWN, InteractionEvent.UP, true);

        // WHEN ACTION_HOVER is received
        when(mSinglePointerTouchProcessor.processTouch(any(), anyInt(), any())).thenReturn(
                touchProcessorResult.first);
        MotionEvent enterEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_ENTER, 0, 0, 0);
        mHoverListenerCaptor.getValue().onHover(mUdfpsView, enterEvent);
        enterEvent.recycle();

        // THEN context click haptic is played
        verify(mVibrator).performHapticFeedback(
                any(),
@@ -1100,31 +1067,6 @@ public class UdfpsControllerTest extends SysuiTestCase {
        mBiometricExecutor.runAllReady();
        downEvent.recycle();

        // THEN NO haptic played
        verify(mVibrator, never()).vibrate(
                anyInt(),
                anyString(),
                any(),
                anyString(),
                any());
    }

    @Test
    public void noHapticOnTouchUdfpsArea_a11yTouchExplorationDisabled__oneWayHapticsEnabled()
            throws RemoteException {
        when(mFeatureFlags.isEnabled(ONE_WAY_HAPTICS_API_MIGRATION)).thenReturn(true);

        final Pair<TouchProcessorResult, TouchProcessorResult> touchProcessorResult =
                givenFingerEvent(InteractionEvent.DOWN, InteractionEvent.UP, false);

        // WHEN ACTION_DOWN is received
        when(mSinglePointerTouchProcessor.processTouch(any(), anyInt(), any())).thenReturn(
                touchProcessorResult.first);
        MotionEvent downEvent = MotionEvent.obtain(0, 0, ACTION_DOWN, 0, 0, 0);
        mTouchListenerCaptor.getValue().onTouch(mUdfpsView, downEvent);
        mBiometricExecutor.runAllReady();
        downEvent.recycle();

        // THEN NO haptic played
        verify(mVibrator, never()).performHapticFeedback(any(), anyInt());
    }
@@ -1351,32 +1293,8 @@ public class UdfpsControllerTest extends SysuiTestCase {
    }

    @Test
    public void playHaptic_onAodInterrupt_oneWayHapticsDisabled_onAcquiredBad_usesVibrate()
            throws RemoteException {
        // GIVEN UDFPS overlay is showing
        mOverlayController.showUdfpsOverlay(TEST_REQUEST_ID, mOpticalProps.sensorId,
                BiometricOverlayConstants.REASON_AUTH_KEYGUARD, mUdfpsOverlayControllerCallback);
        mFgExecutor.runAllReady();

        // GIVEN there's been an AoD interrupt
        when(mKeyguardUpdateMonitor.isFingerprintDetectionRunning()).thenReturn(false);
        mScreenObserver.onScreenTurnedOn();
        mUdfpsController.onAodInterrupt(0, 0, 0, 0);

        // THEN vibrate is used
        verify(mVibrator).vibrate(
                anyInt(),
                anyString(),
                eq(UdfpsController.EFFECT_CLICK),
                eq("aod-lock-icon-longpress"),
                eq(UdfpsController.LOCK_ICON_VIBRATION_ATTRIBUTES)
        );
    }

    @Test
    public void playHaptic_onAodInterrupt_oneWayHapticsEnabled_onAcquiredBad_performHapticFeedback()
    public void playHaptic_onAodInterrupt_onAcquiredBad_performHapticFeedback()
            throws RemoteException {
        when(mFeatureFlags.isEnabled(ONE_WAY_HAPTICS_API_MIGRATION)).thenReturn(true);
        // GIVEN UDFPS overlay is showing
        mOverlayController.showUdfpsOverlay(TEST_REQUEST_ID, mOpticalProps.sensorId,
                BiometricOverlayConstants.REASON_AUTH_KEYGUARD, mUdfpsOverlayControllerCallback);