From 699bbe760d1f48bc47485bb790997ce00c740d85 Mon Sep 17 00:00:00 2001 From: Lais Andrade Date: Fri, 3 May 2024 14:50:07 +0100 Subject: [PATCH] Fix feedback for main haptic settings toggle The SettingsMainSwitchPreferenceController might trigger a state change twice on the page main switch when the user toggles the setting value. Make sure we only trigger haptic feedback when the state is changing between untoggled to toggled to avoid a double-click feedback. No flag for small bug fix, no UI changes. Fix: 338334977 Test: enable the "Use vibration & haptics" settings and feel a single click feedback Change-Id: I0c22b99bcb40f35ebe09c153133c354306ed1ff0 --- .../VibrationMainSwitchPreferenceController.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java b/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java index 02e89269209..db184bf9d73 100644 --- a/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java +++ b/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java @@ -83,11 +83,14 @@ public class VibrationMainSwitchPreferenceController extends SettingsMainSwitchP @Override public boolean setChecked(boolean isChecked) { + // The main switch change can be triggered by both the user click and the + // SettingsMainSwitchPreferenceController state change. Make sure we only do it once. + boolean wasChecked = isChecked(); boolean success = Settings.System.putInt(mContext.getContentResolver(), VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, isChecked ? ON : OFF); - if (success && isChecked) { + if (success && !wasChecked && isChecked) { // Play a haptic as preview for the main toggle only when touch feedback is enabled. VibrationPreferenceConfig.playVibrationPreview( mVibrator, VibrationAttributes.USAGE_TOUCH);