Merge "Apply ringer mode user settings to notification vibrations" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-03-07 18:26:11 +00:00
committed by Android (Google) Code Review
2 changed files with 19 additions and 7 deletions

View File

@@ -355,8 +355,10 @@ final class VibrationSettings {
}
}
if (!shouldVibrateForRingerModeLocked(usage)) {
return Vibration.Status.IGNORED_FOR_RINGER_MODE;
if (!attrs.isFlagSet(VibrationAttributes.FLAG_BYPASS_INTERRUPTION_POLICY)) {
if (!shouldVibrateForRingerModeLocked(usage)) {
return Vibration.Status.IGNORED_FOR_RINGER_MODE;
}
}
}
return null;
@@ -386,12 +388,12 @@ final class VibrationSettings {
* Return {@code true} if the device should vibrate for current ringer mode.
*
* <p>This checks the current {@link AudioManager#getRingerModeInternal()} against user settings
* for ringtone usage only. All other usages are allowed by this method.
* for ringtone and notification usages. All other usages are allowed by this method.
*/
@GuardedBy("mLock")
private boolean shouldVibrateForRingerModeLocked(@VibrationAttributes.Usage int usageHint) {
if (usageHint != USAGE_RINGTONE) {
// Only ringtone vibrations are disabled when phone is on silent mode.
if ((usageHint != USAGE_RINGTONE) && (usageHint != USAGE_NOTIFICATION)) {
// Only ringtone and notification vibrations are disabled when phone is on silent mode.
return true;
}
// If audio manager was not loaded yet then assume most restrictive mode.

View File

@@ -288,7 +288,7 @@ public class VibrationSettingsTest {
}
@Test
public void shouldIgnoreVibration_withRingerModeSilent_ignoresRingtoneOnly() {
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);
@@ -296,7 +296,7 @@ public class VibrationSettingsTest {
setRingerMode(AudioManager.RINGER_MODE_SILENT);
for (int usage : ALL_USAGES) {
if (usage == USAGE_RINGTONE) {
if (usage == USAGE_RINGTONE || usage == USAGE_NOTIFICATION) {
assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_FOR_RINGER_MODE);
} else {
assertVibrationNotIgnoredForUsage(usage);
@@ -304,6 +304,16 @@ public class VibrationSettingsTest {
}
}
@Test
public void shouldIgnoreVibration_withRingerModeSilentAndBypassFlag_allowsAllVibrations() {
setRingerMode(AudioManager.RINGER_MODE_SILENT);
for (int usage : ALL_USAGES) {
assertVibrationNotIgnoredForUsageAndFlags(usage,
VibrationAttributes.FLAG_BYPASS_INTERRUPTION_POLICY);
}
}
@Test
public void shouldIgnoreVibration_withRingerModeVibrate_allowsAllVibrations() {
setRingerMode(AudioManager.RINGER_MODE_VIBRATE);