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

Commit 42dd8adf authored by Lais Andrade's avatar Lais Andrade
Browse files

Enable touch feedback vibrations on silent mode.

Keep behavior from Android S to allow touch vibrations while phone is on
silent or DnD modes. Users will now be able to toggle this user settings
if they want to disable them, which was not available in S.

Fix: 165478128
Test: VibrationSettingsTest
Change-Id: I48c24493b1db53c9b7a99d7b8a916bbbc8ad2d88
parent 5960382a
Loading
Loading
Loading
Loading
+6 −11
Original line number Original line Diff line number Diff line
@@ -347,24 +347,19 @@ final class VibrationSettings {
     * Return {@code true} if the device should vibrate for current ringer mode.
     * Return {@code true} if the device should vibrate for current ringer mode.
     *
     *
     * <p>This checks the current {@link AudioManager#getRingerModeInternal()} against user settings
     * <p>This checks the current {@link AudioManager#getRingerModeInternal()} against user settings
     * for touch and ringtone usages only. All other usages are allowed by this method.
     * for ringtone usage only. All other usages are allowed by this method.
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private boolean shouldVibrateForRingerModeLocked(@VibrationAttributes.Usage int usageHint) {
    private boolean shouldVibrateForRingerModeLocked(@VibrationAttributes.Usage int usageHint) {
        if (usageHint != USAGE_RINGTONE) {
            // Only ringtone vibrations are disabled when phone is on silent mode.
            return true;
        }
        // If audio manager was not loaded yet then assume most restrictive mode.
        // If audio manager was not loaded yet then assume most restrictive mode.
        int ringerMode = (mAudioManager == null)
        int ringerMode = (mAudioManager == null)
                ? AudioManager.RINGER_MODE_SILENT
                ? AudioManager.RINGER_MODE_SILENT
                : mAudioManager.getRingerModeInternal();
                : mAudioManager.getRingerModeInternal();

        switch (usageHint) {
            case USAGE_TOUCH:
            case USAGE_RINGTONE:
                // Touch feedback and ringtone disabled when phone is on silent mode.
        return ringerMode != AudioManager.RINGER_MODE_SILENT;
        return ringerMode != AudioManager.RINGER_MODE_SILENT;
            default:
                // All other usages ignore ringer mode settings.
                return true;
        }
    }
    }


    /** Updates all vibration settings and triggers registered listeners. */
    /** Updates all vibration settings and triggers registered listeners. */
+2 −2
Original line number Original line Diff line number Diff line
@@ -285,7 +285,7 @@ public class VibrationSettingsTest {
    }
    }


    @Test
    @Test
    public void shouldIgnoreVibration_withRingerModeSilent_ignoresRingtoneAndTouch() {
    public void shouldIgnoreVibration_withRingerModeSilent_ignoresRingtoneOnly() {
        // 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.VIBRATE_WHEN_RINGING, 1);
@@ -293,7 +293,7 @@ public class VibrationSettingsTest {
        setRingerMode(AudioManager.RINGER_MODE_SILENT);
        setRingerMode(AudioManager.RINGER_MODE_SILENT);


        for (int usage : ALL_USAGES) {
        for (int usage : ALL_USAGES) {
            if (usage == USAGE_RINGTONE || usage == USAGE_TOUCH) {
            if (usage == USAGE_RINGTONE) {
                assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_FOR_RINGER_MODE);
                assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_FOR_RINGER_MODE);
            } else {
            } else {
                assertVibrationNotIgnoredForUsage(usage);
                assertVibrationNotIgnoredForUsage(usage);