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

Commit 76b2cd60 authored by Lais Andrade's avatar Lais Andrade
Browse files

Disable ring, notification and touch vibration in silent mode

Disable haptic settings for ring, notification and touch feedback when
the phone ringer mode is set to silent.

Preserve the setting values and display message explaining why those
settings are disabled.

Bug: 203188852
Test: *Vibration[Intensity|Toggle]PreferenceControllerTest
Change-Id: I6c24079ece9d637f2feb487f756937888a92caa7
parent 56a62d74
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5457,6 +5457,8 @@
    <string name="accessibility_vibration_settings_title">Vibration &amp; haptics</string>
    <!-- Summary for preference screen for configuring vibrations. [CHAR LIMIT=NONE] -->
    <string name="accessibility_vibration_settings_summary">Control the vibration strength for different usages</string>
    <!-- Summary for vibration preference shown when it is disabled because the device is in silent mode. [CHAR LIMIT=NONE] -->
    <string name="accessibility_vibration_setting_disabled_for_silent_mode_summary">Setting disabled because device is set to silent</string>
    <!-- Title for the category of preferences to configure device vibrations related to calls. [CHAR LIMIT=NONE] -->
    <string name="accessibility_call_vibration_category_title">Calls</string>
    <!-- Title for the category of preferences to configure device vibrations related to notifications and alarms. [CHAR LIMIT=NONE] -->
+6 −0
Original line number Diff line number Diff line
@@ -37,6 +37,12 @@ public class HapticFeedbackIntensityPreferenceController
                    VibrationAttributes.USAGE_TOUCH);
        }

        @Override
        public boolean isRestrictedByRingerModeSilent() {
            // Touch feedback is disabled when the phone is in silent mode.
            return true;
        }

        @Override
        public int readIntensity() {
            final int hapticFeedbackEnabled = Settings.System.getInt(mContentResolver,
+6 −0
Original line number Diff line number Diff line
@@ -32,6 +32,12 @@ public class NotificationVibrationIntensityPreferenceController
            super(context, Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
                    VibrationAttributes.USAGE_NOTIFICATION);
        }

        @Override
        public boolean isRestrictedByRingerModeSilent() {
            // Notifications never vibrate when the phone is in silent mode.
            return true;
        }
    }

    public NotificationVibrationIntensityPreferenceController(Context context,
+6 −0
Original line number Diff line number Diff line
@@ -35,6 +35,12 @@ public class RingVibrationPreferenceConfig extends VibrationPreferenceConfig {
        mAudioManager = context.getSystemService(AudioManager.class);
    }

    @Override
    public boolean isRestrictedByRingerModeSilent() {
        // Incoming calls never vibrate when the phone is in silent mode.
        return true;
    }

    @Override
    public int readIntensity() {
        final int vibrateWhenRinging = Settings.System.getInt(mContentResolver,
+3 −2
Original line number Diff line number Diff line
@@ -58,12 +58,12 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe

    @Override
    public void onStart() {
        mSettingsContentObserver.register(mContext.getContentResolver());
        mSettingsContentObserver.register(mContext);
    }

    @Override
    public void onStop() {
        mSettingsContentObserver.unregister(mContext.getContentResolver());
        mSettingsContentObserver.unregister(mContext);
    }

    @Override
@@ -72,6 +72,7 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe
        final SeekBarPreference preference = screen.findPreference(getPreferenceKey());
        mSettingsContentObserver.onDisplayPreference(this, preference);
        preference.setEnabled(mPreferenceConfig.isPreferenceEnabled());
        preference.setSummaryProvider(unused -> mPreferenceConfig.getSummary());
        // TODO: remove setContinuousUpdates and replace with a different way to play the haptic
        // preview without relying on the setting being propagated to the service.
        preference.setContinuousUpdates(true);
Loading