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

Commit 59e94845 authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Skipping volume slider haptics on ringer mode activation.

We can now skip the lower bookend haptics on the ring and notification
sliders if the ring slider reaches the lower end. This allows the
vibrate-only mode haptics to play without confounding with lower bookend
haptics.

Test: manual. Verified haptics only play due to changing the ringer mode
  vibrate-only.
Test: manual. Verified the above via the dumpsys logs of the MSDL
  player.
Flag: com.android.systemui.haptics_for_compose_sliders
Bug: 382082376
Change-Id: Ide7e2ac69aa01ba4b74b52b3e3f6899ee883d35f
parent 5a836187
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.systemui.Flags
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.ui.compose.Icon
import com.android.systemui.compose.modifiers.sysuiResTag
import com.android.systemui.haptics.slider.SliderHapticFeedbackFilter
import com.android.systemui.haptics.slider.compose.ui.SliderHapticsViewModel
import com.android.systemui.lifecycle.rememberViewModel
import com.android.systemui.res.R
@@ -104,7 +105,13 @@ fun VolumeSlider(
    val value by valueState(state)
    val interactionSource = remember { MutableInteractionSource() }
    val hapticsViewModel: SliderHapticsViewModel? =
        setUpHapticsViewModel(value, state.valueRange, interactionSource, hapticsViewModelFactory)
        setUpHapticsViewModel(
            value,
            state.valueRange,
            state.hapticFilter,
            interactionSource,
            hapticsViewModelFactory,
        )

    Column(modifier = modifier.animateContentSize(), verticalArrangement = Arrangement.Top) {
        Row(
@@ -220,7 +227,13 @@ private fun LegacyVolumeSlider(
    val value by valueState(state)
    val interactionSource = remember { MutableInteractionSource() }
    val hapticsViewModel: SliderHapticsViewModel? =
        setUpHapticsViewModel(value, state.valueRange, interactionSource, hapticsViewModelFactory)
        setUpHapticsViewModel(
            value,
            state.valueRange,
            state.hapticFilter,
            interactionSource,
            hapticsViewModelFactory,
        )

    PlatformSlider(
        modifier =
@@ -338,6 +351,7 @@ private fun SliderIcon(
fun setUpHapticsViewModel(
    value: Float,
    valueRange: ClosedFloatingPointRange<Float>,
    hapticFilter: SliderHapticFeedbackFilter,
    interactionSource: MutableInteractionSource,
    hapticsViewModelFactory: SliderHapticsViewModel.Factory?,
): SliderHapticsViewModel? {
@@ -347,7 +361,10 @@ fun setUpHapticsViewModel(
                    interactionSource,
                    valueRange,
                    Orientation.Horizontal,
                    VolumeHapticsConfigsProvider.sliderHapticFeedbackConfig(valueRange),
                    VolumeHapticsConfigsProvider.sliderHapticFeedbackConfig(
                        valueRange,
                        hapticFilter,
                    ),
                    VolumeHapticsConfigsProvider.seekableSliderTrackerConfig,
                )
            }
+2 −0
Original line number Diff line number Diff line
@@ -49,4 +49,6 @@ data class SliderHapticFeedbackConfig(
    @FloatRange(from = 0.0, fromInclusive = false) val exponent: Float = 1f / 0.89f,
    /** The step-size that defines the slider quantization. Zero represents a continuous slider */
    @FloatRange(from = 0.0) val sliderStepSize: Float = 0f,
    /** A filter that determines values for which haptics are triggered */
    val filter: SliderHapticFeedbackFilter = SliderHapticFeedbackFilter(),
)
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.haptics.slider

/**
 * This filter is used by the [SliderHapticFeedbackProvider] to filter-out haptics if the slider
 * state logic needs to avoid certain vibrations.
 *
 * @param[vibrateOnUpperBookend] Tell the provider if we should vibrate on the upper bookend.
 * @param[vibrateOnLowerBookend] Tell the provider if we should vibrate on the lower bookend.
 */
data class SliderHapticFeedbackFilter(
    var vibrateOnUpperBookend: Boolean = true,
    var vibrateOnLowerBookend: Boolean = true,
)
+2 −2
Original line number Diff line number Diff line
@@ -218,14 +218,14 @@ class SliderHapticFeedbackProvider(
    }

    override fun onLowerBookend() {
        if (!hasVibratedAtLowerBookend) {
        if (!hasVibratedAtLowerBookend && config.filter.vibrateOnLowerBookend) {
            vibrateOnEdgeCollision(abs(velocityProvider.getTrackedVelocity()))
            hasVibratedAtLowerBookend = true
        }
    }

    override fun onUpperBookend() {
        if (!hasVibratedAtUpperBookend) {
        if (!hasVibratedAtUpperBookend && config.filter.vibrateOnUpperBookend) {
            vibrateOnEdgeCollision(abs(velocityProvider.getTrackedVelocity()))
            hasVibratedAtUpperBookend = true
        }
+3 −1
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ import com.android.systemui.haptics.slider.HapticSliderPlugin;
import com.android.systemui.haptics.slider.HapticSliderViewBinder;
import com.android.systemui.haptics.slider.SeekableSliderTrackerConfig;
import com.android.systemui.haptics.slider.SliderHapticFeedbackConfig;
import com.android.systemui.haptics.slider.SliderHapticFeedbackFilter;
import com.android.systemui.media.dialog.MediaOutputDialogManager;
import com.android.systemui.plugins.VolumeDialog;
import com.android.systemui.plugins.VolumeDialogController;
@@ -2700,7 +2701,8 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
                /* upperBookendScale= */ 1f,
                /* lowerBookendScale= */ 0.05f,
                /* exponent= */ 1f / 0.89f,
                /* sliderStepSize = */ 0f);
                /* sliderStepSize = */ 0f,
                /* filter =*/new SliderHapticFeedbackFilter());
        private static final SeekableSliderTrackerConfig sSliderTrackerConfig =
                new SeekableSliderTrackerConfig(
                        /* waitTimeMillis= */100,
Loading