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

Commit d9deb875 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit Committed by Android (Google) Code Review
Browse files

Merge "Fix how HapticScrollFeedbackProvider resets input/motion states" into main

parents fc0f763f 7fdb8fd0
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -135,15 +135,16 @@ public class HapticScrollFeedbackProvider implements ScrollFeedbackProvider {

    private void maybeUpdateCurrentConfig(int deviceId, int source, int axis) {
        if (mAxis != axis || mSource != source || mDeviceId != deviceId) {
            mSource = source;
            mAxis = axis;
            mDeviceId = deviceId;

            if (mDisabledIfViewPlaysScrollHaptics
                    && (source == InputDevice.SOURCE_ROTARY_ENCODER)
                    && mViewConfig.isViewBasedRotaryEncoderHapticScrollFeedbackEnabled()) {
                mHapticScrollFeedbackEnabled = false;
                return;
            }
            mSource = source;
            mAxis = axis;
            mDeviceId = deviceId;

            mHapticScrollFeedbackEnabled =
                    mViewConfig.isHapticScrollFeedbackEnabled(deviceId, axis, source);
+29 −0
Original line number Diff line number Diff line
@@ -428,6 +428,35 @@ public final class HapticScrollFeedbackProviderTest {
        assertFeedbackCount(mView, HapticFeedbackConstants.SCROLL_LIMIT, 1);
    }

    @Test
    public void testNonRotaryInputFeedbackNotBlockedByRotaryUnavailability() {
        when(mMockViewConfig.isViewBasedRotaryEncoderHapticScrollFeedbackEnabled())
                .thenReturn(true);
        setHapticScrollFeedbackEnabled(true);
        setHapticScrollTickInterval(5);
        mProvider = new HapticScrollFeedbackProvider(mView, mMockViewConfig,
                /* disabledIfViewPlaysScrollHaptics= */ true);

        // Expect one feedback here. Touch input should provide feedback since scroll feedback has
        // been enabled via `setHapticScrollFeedbackEnabled(true)`.
        mProvider.onScrollProgress(
                INPUT_DEVICE_1, InputDevice.SOURCE_TOUCHSCREEN, MotionEvent.AXIS_Y,
                /* deltaInPixels= */ 10);
        // Because `isViewBasedRotaryEncoderHapticScrollFeedbackEnabled()` is false and
        // `disabledIfViewPlaysScrollHaptics` is true, the scroll progress from rotary encoders will
        // produce no feedback.
        mProvider.onScrollProgress(
                INPUT_DEVICE_2, InputDevice.SOURCE_ROTARY_ENCODER, MotionEvent.AXIS_SCROLL,
                /* deltaInPixels= */ 20);
        // This event from the touch screen should produce feedback. The rotary encoder event's
        // inability to not play scroll feedback should not impact this touch input.
        mProvider.onScrollProgress(
                INPUT_DEVICE_1, InputDevice.SOURCE_TOUCHSCREEN, MotionEvent.AXIS_Y,
                /* deltaInPixels= */ 30);

        assertFeedbackCount(mView, HapticFeedbackConstants.SCROLL_TICK, 2);
    }


    private void assertNoFeedback(TestView view) {
        for (int feedback : new int[] {SCROLL_ITEM_FOCUS, SCROLL_LIMIT, SCROLL_TICK}) {