Merge "Apply only RING_VIBRATION_INTENSITY to ringtone vibrations" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-04-12 17:24:06 +00:00
committed by Android (Google) Code Review
3 changed files with 16 additions and 58 deletions

View File

@@ -238,8 +238,6 @@ final class VibrationSettings {
// Listen to all settings that might affect the result of Vibrator.getVibrationIntensity. // Listen to all settings that might affect the result of Vibrator.getVibrationIntensity.
registerSettingsObserver(Settings.System.getUriFor(Settings.System.VIBRATE_INPUT_DEVICES)); registerSettingsObserver(Settings.System.getUriFor(Settings.System.VIBRATE_INPUT_DEVICES));
registerSettingsObserver(Settings.System.getUriFor(Settings.System.VIBRATE_ON)); registerSettingsObserver(Settings.System.getUriFor(Settings.System.VIBRATE_ON));
registerSettingsObserver(Settings.System.getUriFor(Settings.System.VIBRATE_WHEN_RINGING));
registerSettingsObserver(Settings.System.getUriFor(Settings.System.APPLY_RAMPING_RINGER));
registerSettingsObserver(Settings.System.getUriFor( registerSettingsObserver(Settings.System.getUriFor(
Settings.System.HAPTIC_FEEDBACK_ENABLED)); Settings.System.HAPTIC_FEEDBACK_ENABLED));
registerSettingsObserver( registerSettingsObserver(
@@ -449,19 +447,12 @@ final class VibrationSettings {
mCurrentVibrationIntensities.put(USAGE_NOTIFICATION, notificationIntensity); mCurrentVibrationIntensities.put(USAGE_NOTIFICATION, notificationIntensity);
mCurrentVibrationIntensities.put(USAGE_MEDIA, mediaIntensity); mCurrentVibrationIntensities.put(USAGE_MEDIA, mediaIntensity);
mCurrentVibrationIntensities.put(USAGE_UNKNOWN, mediaIntensity); mCurrentVibrationIntensities.put(USAGE_UNKNOWN, mediaIntensity);
mCurrentVibrationIntensities.put(USAGE_RINGTONE, ringIntensity);
// Communication request is not disabled by the notification setting. // Communication request is not disabled by the notification setting.
mCurrentVibrationIntensities.put(USAGE_COMMUNICATION_REQUEST, mCurrentVibrationIntensities.put(USAGE_COMMUNICATION_REQUEST,
positiveNotificationIntensity); positiveNotificationIntensity);
if (!loadBooleanSetting(Settings.System.VIBRATE_WHEN_RINGING)
&& !loadBooleanSetting(Settings.System.APPLY_RAMPING_RINGER)) {
// Make sure deprecated boolean setting still disables ringtone vibrations.
mCurrentVibrationIntensities.put(USAGE_RINGTONE, Vibrator.VIBRATION_INTENSITY_OFF);
} else {
mCurrentVibrationIntensities.put(USAGE_RINGTONE, ringIntensity);
}
// This should adapt the behavior preceding the introduction of this new setting // This should adapt the behavior preceding the introduction of this new setting
// key, which is to apply HAPTIC_FEEDBACK_INTENSITY, unless it's disabled. // key, which is to apply HAPTIC_FEEDBACK_INTENSITY, unless it's disabled.
mCurrentVibrationIntensities.put(USAGE_HARDWARE_FEEDBACK, hardwareFeedbackIntensity); mCurrentVibrationIntensities.put(USAGE_HARDWARE_FEEDBACK, hardwareFeedbackIntensity);

View File

@@ -193,7 +193,7 @@ public class VibrationSettingsTest {
public void removeListener_noMoreCallbacksToListener() { public void removeListener_noMoreCallbacksToListener() {
mVibrationSettings.addListener(mListenerMock); mVibrationSettings.addListener(mListenerMock);
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0); setUserSetting(Settings.System.RING_VIBRATION_INTENSITY, 0);
verify(mListenerMock).onChange(); verify(mListenerMock).onChange();
mVibrationSettings.removeListener(mListenerMock); mVibrationSettings.removeListener(mListenerMock);
@@ -291,8 +291,6 @@ public class VibrationSettingsTest {
public void shouldIgnoreVibration_withRingerModeSilent_ignoresRingtoneAndNotification() { public void shouldIgnoreVibration_withRingerModeSilent_ignoresRingtoneAndNotification() {
// Vibrating settings on are overruled by ringer mode. // Vibrating settings on are overruled by ringer mode.
setUserSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED, 1); setUserSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED, 1);
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 1);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 1);
setRingerMode(AudioManager.RINGER_MODE_SILENT); setRingerMode(AudioManager.RINGER_MODE_SILENT);
for (int usage : ALL_USAGES) { for (int usage : ALL_USAGES) {
@@ -360,44 +358,25 @@ public class VibrationSettingsTest {
assertVibrationNotIgnoredForUsage(usage); assertVibrationNotIgnoredForUsage(usage);
} }
} }
@Test @Test
public void shouldIgnoreVibration_withRingSettingsOff_disableRingtoneVibrations() { public void shouldIgnoreVibration_withRingSettingsOff_allowsAllVibrations() {
// 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.
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0); setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 0); setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 0);
for (int usage : ALL_USAGES) { for (int usage : ALL_USAGES) {
if (usage == USAGE_RINGTONE) { assertVibrationNotIgnoredForUsage(usage);
assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_FOR_SETTINGS);
} else {
assertVibrationNotIgnoredForUsage(usage);
}
assertVibrationNotIgnoredForUsageAndFlags(usage, assertVibrationNotIgnoredForUsageAndFlags(usage,
VibrationAttributes.FLAG_BYPASS_USER_VIBRATION_INTENSITY_OFF); VibrationAttributes.FLAG_BYPASS_USER_VIBRATION_INTENSITY_OFF);
} }
} }
@Test
public void shouldIgnoreVibration_withRingSettingsOn_allowsAllVibrations() {
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 1);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 0);
for (int usage : ALL_USAGES) {
assertVibrationNotIgnoredForUsage(usage);
}
}
@Test
public void shouldIgnoreVibration_withRampingRingerOn_allowsAllVibrations() {
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 1);
for (int usage : ALL_USAGES) {
assertVibrationNotIgnoredForUsage(usage);
}
}
@Test @Test
public void shouldIgnoreVibration_withHapticFeedbackDisabled_ignoresTouchVibration() { public void shouldIgnoreVibration_withHapticFeedbackDisabled_ignoresTouchVibration() {
// HAPTIC_FEEDBACK_ENABLED is deprecated but it was the only setting used to disable touch
// feedback vibrations. Continue to apply this on top of the intensity setting.
setUserSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED, 0); setUserSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED, 0);
for (int usage : ALL_USAGES) { for (int usage : ALL_USAGES) {
@@ -459,8 +438,6 @@ public class VibrationSettingsTest {
@Test @Test
public void shouldIgnoreVibration_withRingSettingsOff_ignoresRingtoneVibrations() { public void shouldIgnoreVibration_withRingSettingsOff_ignoresRingtoneVibrations() {
// Vibrating settings on are overruled by ring intensity setting. // Vibrating settings on are overruled by ring intensity setting.
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 1);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 1);
setRingerMode(AudioManager.RINGER_MODE_VIBRATE); setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
setUserSetting(Settings.System.RING_VIBRATION_INTENSITY, VIBRATION_INTENSITY_OFF); setUserSetting(Settings.System.RING_VIBRATION_INTENSITY, VIBRATION_INTENSITY_OFF);
@@ -479,7 +456,6 @@ public class VibrationSettingsTest {
public void shouldIgnoreVibration_updateTriggeredAfterInternalRingerModeChanged() { public void shouldIgnoreVibration_updateTriggeredAfterInternalRingerModeChanged() {
// Vibrating settings on are overruled by ringer mode. // Vibrating settings on are overruled by ringer mode.
setUserSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED, 1); setUserSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED, 1);
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 1);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 1); setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 1);
setRingerMode(AudioManager.RINGER_MODE_NORMAL); setRingerMode(AudioManager.RINGER_MODE_NORMAL);

View File

@@ -559,30 +559,26 @@ public class VibratorManagerServiceTest {
} }
@Test @Test
public void vibrate_withRingtone_usesRingtoneSettings() throws Exception { public void vibrate_withRingtone_usesRingerModeSettings() throws Exception {
mockVibrators(1); mockVibrators(1);
FakeVibratorControllerProvider fakeVibrator = mVibratorProviders.get(1); FakeVibratorControllerProvider fakeVibrator = mVibratorProviders.get(1);
fakeVibrator.setSupportedEffects(VibrationEffect.EFFECT_CLICK, fakeVibrator.setSupportedEffects(VibrationEffect.EFFECT_CLICK,
VibrationEffect.EFFECT_HEAVY_CLICK, VibrationEffect.EFFECT_DOUBLE_CLICK); VibrationEffect.EFFECT_HEAVY_CLICK, VibrationEffect.EFFECT_DOUBLE_CLICK);
setRingerMode(AudioManager.RINGER_MODE_NORMAL); setRingerMode(AudioManager.RINGER_MODE_SILENT);
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 0);
VibratorManagerService service = createSystemReadyService(); VibratorManagerService service = createSystemReadyService();
vibrate(service, VibrationEffect.get(VibrationEffect.EFFECT_CLICK), RINGTONE_ATTRS); vibrate(service, VibrationEffect.get(VibrationEffect.EFFECT_CLICK), RINGTONE_ATTRS);
// Wait before checking it never played. // Wait before checking it never played.
assertFalse(waitUntil(s -> !fakeVibrator.getAllEffectSegments().isEmpty(), assertFalse(waitUntil(s -> !fakeVibrator.getAllEffectSegments().isEmpty(),
service, /* timeout= */ 50)); service, /* timeout= */ 50));
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0); setRingerMode(AudioManager.RINGER_MODE_NORMAL);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 1);
service = createSystemReadyService(); service = createSystemReadyService();
vibrate(service, VibrationEffect.get(VibrationEffect.EFFECT_HEAVY_CLICK), RINGTONE_ATTRS); vibrate(service, VibrationEffect.get(VibrationEffect.EFFECT_HEAVY_CLICK), RINGTONE_ATTRS);
assertTrue(waitUntil(s -> fakeVibrator.getAllEffectSegments().size() == 1, assertTrue(waitUntil(s -> fakeVibrator.getAllEffectSegments().size() == 1,
service, TEST_TIMEOUT_MILLIS)); service, TEST_TIMEOUT_MILLIS));
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 1); setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 0);
service = createSystemReadyService(); service = createSystemReadyService();
vibrate(service, VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK), RINGTONE_ATTRS); vibrate(service, VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK), RINGTONE_ATTRS);
assertTrue(waitUntil(s -> fakeVibrator.getAllEffectSegments().size() == 2, assertTrue(waitUntil(s -> fakeVibrator.getAllEffectSegments().size() == 2,
@@ -1225,7 +1221,6 @@ public class VibratorManagerServiceTest {
mockVibrators(1); mockVibrators(1);
mVibratorProviders.get(1).setCapabilities(IVibrator.CAP_EXTERNAL_CONTROL); mVibratorProviders.get(1).setCapabilities(IVibrator.CAP_EXTERNAL_CONTROL);
setRingerMode(AudioManager.RINGER_MODE_NORMAL); setRingerMode(AudioManager.RINGER_MODE_NORMAL);
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 1);
createSystemReadyService(); createSystemReadyService();
IBinder firstToken = mock(IBinder.class); IBinder firstToken = mock(IBinder.class);
@@ -1296,21 +1291,17 @@ public class VibratorManagerServiceTest {
ExternalVibration externalVibration = new ExternalVibration(UID, PACKAGE_NAME, audioAttrs, ExternalVibration externalVibration = new ExternalVibration(UID, PACKAGE_NAME, audioAttrs,
mock(IExternalVibrationController.class)); mock(IExternalVibrationController.class));
setRingerMode(AudioManager.RINGER_MODE_NORMAL); setRingerMode(AudioManager.RINGER_MODE_SILENT);
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 0);
createSystemReadyService(); createSystemReadyService();
int scale = mExternalVibratorService.onExternalVibrationStart(externalVibration); int scale = mExternalVibratorService.onExternalVibrationStart(externalVibration);
assertEquals(IExternalVibratorService.SCALE_MUTE, scale); assertEquals(IExternalVibratorService.SCALE_MUTE, scale);
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0); setRingerMode(AudioManager.RINGER_MODE_NORMAL);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 1);
createSystemReadyService(); createSystemReadyService();
scale = mExternalVibratorService.onExternalVibrationStart(externalVibration); scale = mExternalVibratorService.onExternalVibrationStart(externalVibration);
assertNotEquals(IExternalVibratorService.SCALE_MUTE, scale); assertNotEquals(IExternalVibratorService.SCALE_MUTE, scale);
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 1); setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
setUserSetting(Settings.System.APPLY_RAMPING_RINGER, 0);
createSystemReadyService(); createSystemReadyService();
scale = mExternalVibratorService.onExternalVibrationStart(externalVibration); scale = mExternalVibratorService.onExternalVibrationStart(externalVibration);
assertNotEquals(IExternalVibratorService.SCALE_MUTE, scale); assertNotEquals(IExternalVibratorService.SCALE_MUTE, scale);