Apply ringer mode user settings to notification vibrations

The vibrator service is only applying the ringer mode settings to
ringtone vibrations, forcing them to be disabled when ringer mode is
silent.

This is applied to notification vibrations by the notification manager,
but some other paths (including 3p apps) might apply this usage and the
ringer mode settings would not be applied to them (e.g. Dialer and
Telecom app/service, Car services, etc).

This also applies the flag FLAG_BYPASS_INTERRUPTION_POLICY on ringer
mode, since the CellBroadcastAlert can trigger alerts with the
notification usage and those need to bypass user settings and vibrate
all the time.

Bug: 198794501
Test: VibrationSettingsTest
Change-Id: Ic00fbd32d859b0c77830450add24826e0dd13366
This commit is contained in:
Lais Andrade
2022-03-04 16:09:07 +00:00
parent cc9e167538
commit 95993a7c38
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);