Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf06e42c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 4ed510e4 95993a7c
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -355,10 +355,12 @@ final class VibrationSettings {
                }
            }

            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.
+12 −2
Original line number Diff line number Diff line
@@ -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);