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

Commit ebd86954 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Delivering haptic feedback on stable values of slider progress change.

The volume slider progress is changed via an ObjectAnimator when
changing volume programmatically. To avoid haptics on single
key-presses, calls to the haptic plugin are made when the volume rows
reach their target or stable progress after animations. To better
synchronize with animation timing, the haptic plugin timeout that
estimates a key-up event was reduced.

Test: press a volume key once to change the volume in a single step, then
  run adb shell dumpsys vibrator_manager and check that no vibrations
  are delivered.
Flag: ACONFIG com.android.systemui.haptic_volume_slider TEAMFOOD
Bug: 328117911
Change-Id: Ib286d4c42688afaa88ddc6e65fa6a25982ab06d3
parent 9375261e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -163,6 +163,6 @@ constructor(
    }

    companion object {
        const val KEY_UP_TIMEOUT = 100L
        const val KEY_UP_TIMEOUT = 60L
    }
}
+15 −4
Original line number Diff line number Diff line
@@ -2082,6 +2082,9 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
                } else {
                    row.anim.cancel();
                    row.anim.setIntValues(progress, newProgress);
                    // The animator can't keep up with the volume changes so haptics need to be
                    // triggered here. This happens when the volume keys are continuously pressed.
                    row.deliverOnProgressChangedHaptics(false, newProgress);
                }
                row.animTargetProgress = newProgress;
                row.anim.setDuration(UPDATE_ANIMATION_DURATION);
@@ -2486,10 +2489,10 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
            if (getActiveRow().equals(mRow)
                    && mRow.slider.getVisibility() == VISIBLE
                    && mRow.mHapticPlugin != null) {
                mRow.mHapticPlugin.onProgressChanged(seekBar, progress, fromUser);
                if (!fromUser) {
                    // Consider a change from program as the volume key being continuously pressed
                    mRow.mHapticPlugin.onKeyDown();
                if (fromUser || mRow.animTargetProgress == progress) {
                    // Deliver user-generated slider changes immediately, or when the animation
                    // completes
                    mRow.deliverOnProgressChangedHaptics(fromUser, progress);
                }
            }
            if (D.BUG) Log.d(TAG, AudioSystem.streamToString(mRow.stream)
@@ -2642,6 +2645,14 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
        void removeHaptics() {
            slider.setOnTouchListener(null);
        }

        void deliverOnProgressChangedHaptics(boolean fromUser, int progress) {
            mHapticPlugin.onProgressChanged(slider, progress, fromUser);
            if (!fromUser) {
                // Consider a change from program as the volume key being continuously pressed
                mHapticPlugin.onKeyDown();
            }
        }
    }

    /**