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
This commit is contained in:
Lais Andrade
2022-03-29 19:20:07 +01:00
parent 03ecb4f4a6
commit 7ee344ab54
3 changed files with 10 additions and 23 deletions

View File

@@ -41,21 +41,6 @@ public class RingVibrationPreferenceConfig extends VibrationPreferenceConfig {
return true; 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 @Override
public boolean updateIntensity(int intensity) { public boolean updateIntensity(int intensity) {
final boolean success = super.updateIntensity(intensity); final boolean success = super.updateIntensity(intensity);

View File

@@ -121,22 +121,22 @@ public class RingVibrationIntensityPreferenceControllerTest {
} }
@Test @Test
public void updateState_vibrateWhenRingingAndRampingRingerOff_shouldDisplayAlwaysOff() { public void updateState_vibrateWhenRingingAndRampingRingerOff_shouldDisplayRingIntensity() {
when(mAudioManager.isRampingRingerEnabled()).thenReturn(false); when(mAudioManager.isRampingRingerEnabled()).thenReturn(false);
updateSetting(Settings.System.VIBRATE_WHEN_RINGING, OFF); updateSetting(Settings.System.VIBRATE_WHEN_RINGING, OFF);
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference); 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, updateSetting(Settings.System.RING_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM); Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference); 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); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference); 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); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference); mController.updateState(mPreference);

View File

@@ -116,22 +116,24 @@ public class RingVibrationTogglePreferenceControllerTest {
} }
@Test @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); when(mAudioManager.isRampingRingerEnabled()).thenReturn(false);
updateSetting(Settings.System.VIBRATE_WHEN_RINGING, OFF); updateSetting(Settings.System.VIBRATE_WHEN_RINGING, OFF);
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse(); assertThat(mPreference.isChecked()).isTrue();
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, updateSetting(Settings.System.RING_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM); Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse(); assertThat(mPreference.isChecked()).isTrue();
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse(); assertThat(mPreference.isChecked()).isTrue();
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference); mController.updateState(mPreference);