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

Commit 7ee344ab authored by Lais Andrade's avatar Lais Andrade
Browse files

Apply only RING_VIBRATION_INTENSITY to ringtone vibrations

Ignore the VIBRATE_WHEN_RINGING deprecated settings for ring vibrations.
Old behavior applied this settings only to ringer-mode normal, but never
to vibrate-only ringer mode.

This is being deprecated in favor of the INTENSITY_OFF value in
RING_VIBRATION_INTENSITY.

Fix: 222697191
Test: RingVibrationIntensityPreferenceControllerTest
Change-Id: Ic05f06c6a1df392ced1bf91f67380c0c65257aea
parent 03ecb4f4
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
@@ -41,21 +41,6 @@ public class RingVibrationPreferenceConfig extends VibrationPreferenceConfig {
        return true;
    }

    @Override
    public int readIntensity() {
        final int vibrateWhenRinging = Settings.System.getInt(mContentResolver,
                Settings.System.VIBRATE_WHEN_RINGING, ON);

        if ((vibrateWhenRinging == OFF)
                && !mAudioManager.isRampingRingerEnabled()) {
            // VIBRATE_WHEN_RINGING is deprecated but should still be applied if the user has
            // turned it off and has not enabled the ramping ringer (old three-state setting).
            return Vibrator.VIBRATION_INTENSITY_OFF;
        }

        return super.readIntensity();
    }

    @Override
    public boolean updateIntensity(int intensity) {
        final boolean success = super.updateIntensity(intensity);
+4 −4
Original line number Diff line number Diff line
@@ -121,22 +121,22 @@ public class RingVibrationIntensityPreferenceControllerTest {
    }

    @Test
    public void updateState_vibrateWhenRingingAndRampingRingerOff_shouldDisplayAlwaysOff() {
    public void updateState_vibrateWhenRingingAndRampingRingerOff_shouldDisplayRingIntensity() {
        when(mAudioManager.isRampingRingerEnabled()).thenReturn(false);
        updateSetting(Settings.System.VIBRATE_WHEN_RINGING, OFF);

        updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
        mController.updateState(mPreference);
        assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
        assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);

        updateSetting(Settings.System.RING_VIBRATION_INTENSITY,
                Vibrator.VIBRATION_INTENSITY_MEDIUM);
        mController.updateState(mPreference);
        assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
        assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);

        updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
        mController.updateState(mPreference);
        assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
        assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);

        updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
        mController.updateState(mPreference);
+6 −4
Original line number Diff line number Diff line
@@ -116,22 +116,24 @@ public class RingVibrationTogglePreferenceControllerTest {
    }

    @Test
    public void updateState_vibrateWhenRingingAndRampingRingerOff_shouldDisplayAlwaysOff() {
    public void updateState_vibrateWhenRingingAndRampingRingerOff_shouldIgnoreAndUseIntensity() {
        // VIBRATE_WHEN_RINGING is deprecated and should have no effect on the ring vibration
        // setting. The ramping ringer is also independent now, instead of a 3-state setting.
        when(mAudioManager.isRampingRingerEnabled()).thenReturn(false);
        updateSetting(Settings.System.VIBRATE_WHEN_RINGING, OFF);

        updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
        mController.updateState(mPreference);
        assertThat(mPreference.isChecked()).isFalse();
        assertThat(mPreference.isChecked()).isTrue();

        updateSetting(Settings.System.RING_VIBRATION_INTENSITY,
                Vibrator.VIBRATION_INTENSITY_MEDIUM);
        mController.updateState(mPreference);
        assertThat(mPreference.isChecked()).isFalse();
        assertThat(mPreference.isChecked()).isTrue();

        updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
        mController.updateState(mPreference);
        assertThat(mPreference.isChecked()).isFalse();
        assertThat(mPreference.isChecked()).isTrue();

        updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
        mController.updateState(mPreference);