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

Commit 7fdb8fd0 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit Committed by Marvin Escobar Barajas
Browse files

Fix how HapticScrollFeedbackProvider resets input/motion states

The input device id, source, and axis fields were sometimes not updated
properly, since the check for the rotary encoder haptic feedback
availability preceded the update. So in cases where rotary encoder
haptic feedback was unavailable, the fields were never updated, meaning
that non-rotary scroll feedback was also blocked.

Bug: 356665746
Flag: EXEMPT trivial bug fix
Test: atest HapticScrollFeedbackProviderTest
Change-Id: I5c96c57fe70b836afda2295568a1389195ee279d
parent f80b9cda
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}) {