Merge "Apply only RING_VIBRATION_INTENSITY to ringtone vibrations" into tm-dev am: 7b23f67adc

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17406377

Change-Id: Iec35bf869f34ef8cdbc180c03f11174b88c377e9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-04-12 17:28:52 +00:00
committed by Automerger Merge Worker
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.
registerSettingsObserver(Settings.System.getUriFor(Settings.System.VIBRATE_INPUT_DEVICES));
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(
Settings.System.HAPTIC_FEEDBACK_ENABLED));
registerSettingsObserver(
@@ -449,19 +447,12 @@ final class VibrationSettings {
mCurrentVibrationIntensities.put(USAGE_NOTIFICATION, notificationIntensity);
mCurrentVibrationIntensities.put(USAGE_MEDIA, mediaIntensity);
mCurrentVibrationIntensities.put(USAGE_UNKNOWN, mediaIntensity);
mCurrentVibrationIntensities.put(USAGE_RINGTONE, ringIntensity);
// Communication request is not disabled by the notification setting.
mCurrentVibrationIntensities.put(USAGE_COMMUNICATION_REQUEST,
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
// key, which is to apply HAPTIC_FEEDBACK_INTENSITY, unless it's disabled.
mCurrentVibrationIntensities.put(USAGE_HARDWARE_FEEDBACK, hardwareFeedbackIntensity);

View File

@@ -193,7 +193,7 @@ public class VibrationSettingsTest {
public void removeListener_noMoreCallbacksToListener() {
mVibrationSettings.addListener(mListenerMock);
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 0);
setUserSetting(Settings.System.RING_VIBRATION_INTENSITY, 0);
verify(mListenerMock).onChange();
mVibrationSettings.removeListener(mListenerMock);
@@ -291,8 +291,6 @@ public class VibrationSettingsTest {
public void shouldIgnoreVibration_withRingerModeSilent_ignoresRingtoneAndNotification() {
// Vibrating settings on are overruled by ringer mode.
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);
for (int usage : ALL_USAGES) {
@@ -360,44 +358,25 @@ public class VibrationSettingsTest {
assertVibrationNotIgnoredForUsage(usage);
}
}
@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.APPLY_RAMPING_RINGER, 0);
for (int usage : ALL_USAGES) {
if (usage == USAGE_RINGTONE) {
assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_FOR_SETTINGS);
} else {
assertVibrationNotIgnoredForUsage(usage);
}
assertVibrationNotIgnoredForUsage(usage);
assertVibrationNotIgnoredForUsageAndFlags(usage,
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
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);
for (int usage : ALL_USAGES) {
@@ -459,8 +438,6 @@ public class VibrationSettingsTest {
@Test
public void shouldIgnoreVibration_withRingSettingsOff_ignoresRingtoneVibrations() {
// 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);
setUserSetting(Settings.System.RING_VIBRATION_INTENSITY, VIBRATION_INTENSITY_OFF);
@@ -479,7 +456,6 @@ public class VibrationSettingsTest {
public void shouldIgnoreVibration_updateTriggeredAfterInternalRingerModeChanged() {
// Vibrating settings on are overruled by ringer mode.
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_NORMAL);

View File

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