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

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

Merge "Enable touch feedback vibrations on silent mode." into tm-dev

parents 83a91c85 42dd8adf
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);