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

Commit be573449 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit
Browse files

Default to hardware vibration attribute for SCROLL_* feedback

In ag/29002964, we changed the default vibration attribute used for the SCROLL_* constants from hardware to touch. Although this is our goal in the long term, it's causing a bug (b/372380778), because there are older usages of the View.performHapticFeedback API that directly play the SCROLL_* constant without providing the input source. We will fix this in the long term via b/372820923.

Bug: 372380778
Change-Id: I34c1b08bba1a0752ee190dd904b2d60395f98335
Test: atest HapticFeedbackVibrationProviderTest
Flag: android.os.vibrator.haptic_feedback_input_source_customization_enabled
parent c5ebf7b1
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -148,8 +148,8 @@ public final class HapticFeedbackVibrationProvider {
            case HapticFeedbackConstants.SCROLL_TICK:
            case HapticFeedbackConstants.SCROLL_ITEM_FOCUS:
            case HapticFeedbackConstants.SCROLL_LIMIT:
                attrs = hapticFeedbackInputSourceCustomizationEnabled() ? TOUCH_VIBRATION_ATTRIBUTES
                        : HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES;
                // TODO(b/372820923): use touch attributes by default.
                attrs = HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES;
                break;
            case HapticFeedbackConstants.KEYBOARD_TAP:
            case HapticFeedbackConstants.KEYBOARD_RELEASE:
@@ -176,14 +176,15 @@ public final class HapticFeedbackVibrationProvider {
            int inputSource,
            @HapticFeedbackConstants.Flags int flags,
            @HapticFeedbackConstants.PrivateFlags int privFlags) {
        if (hapticFeedbackInputSourceCustomizationEnabled()
                && inputSource == InputDevice.SOURCE_ROTARY_ENCODER) {
        if (hapticFeedbackInputSourceCustomizationEnabled()) {
            switch (effectId) {
                case HapticFeedbackConstants.SCROLL_TICK,
                        HapticFeedbackConstants.SCROLL_ITEM_FOCUS,
                        HapticFeedbackConstants.SCROLL_LIMIT -> {
                    return getVibrationAttributesWithFlags(HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES,
                            effectId, flags);
                    VibrationAttributes attrs = inputSource == InputDevice.SOURCE_ROTARY_ENCODER
                            ? HARDWARE_FEEDBACK_VIBRATION_ATTRIBUTES
                            : TOUCH_VIBRATION_ATTRIBUTES;
                    return getVibrationAttributesWithFlags(attrs, effectId, flags);
                }
            }
        }
+1 −14
Original line number Diff line number Diff line
@@ -453,20 +453,7 @@ public class HapticFeedbackVibrationProviderTest {
    }

    @Test
    public void testVibrationAttribute_scrollFeedback_inputCustomizedFlag_useTouchUsage() {
        mSetFlagsRule.enableFlags(FLAG_HAPTIC_FEEDBACK_INPUT_SOURCE_CUSTOMIZATION_ENABLED);
        HapticFeedbackVibrationProvider provider = createProviderWithoutCustomizations();

        for (int effectId : SCROLL_FEEDBACK_CONSTANTS) {
            VibrationAttributes attrs = provider.getVibrationAttributes(effectId, /* flags */
                    0, /* privFlags */ 0);
            assertWithMessage("Expected USAGE_TOUCH for scroll effect " + effectId
                    + ", if no input customization").that(attrs.getUsage()).isEqualTo(USAGE_TOUCH);
        }
    }

    @Test
    public void testVibrationAttribute_scrollFeedback_noInputCustomizedFlag_useHardwareFeedback() {
    public void testVibrationAttribute_scrollFeedback_useHardwareFeedback() {
        HapticFeedbackVibrationProvider provider = createProviderWithoutCustomizations();

        for (int effectId : SCROLL_FEEDBACK_CONSTANTS) {