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

Commit 6843e024 authored by Yiwen Chen's avatar Yiwen Chen Committed by Android (Google) Code Review
Browse files

Merge "Keep consistency between sound and accessibility settings." into qt-dev

parents d5daa47b 85580fbc
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle;
import android.os.Vibrator;
import android.provider.DeviceConfig;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.text.TextUtils;
@@ -168,6 +169,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
    private static final String ANIMATION_ON_VALUE = "1";
    private static final String ANIMATION_OFF_VALUE = "0";

    static final String RAMPING_RINGER_ENABLED = "ramping_ringer_enabled";

    private final Map<String, String> mLongPressTimeoutValueToTitleMap = new HashMap<>();

    private final Handler mHandler = new Handler();
@@ -389,6 +392,15 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
                : stateSummaryCombo;
    }

    @VisibleForTesting
    static boolean isRampingRingerEnabled(final Context context) {
        return (Settings.Global.getInt(
                        context.getContentResolver(),
                        Settings.Global.APPLY_RAMPING_RINGER, 0) == 1)
                && DeviceConfig.getBoolean(
                        DeviceConfig.NAMESPACE_TELEPHONY, RAMPING_RINGER_ENABLED, false);
    }

    private void handleToggleTextContrastPreferenceClick() {
        Settings.Secure.putInt(getContentResolver(),
                Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED,
@@ -866,7 +878,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
                Settings.System.RING_VIBRATION_INTENSITY,
                vibrator.getDefaultRingVibrationIntensity());
        if (Settings.System.getInt(context.getContentResolver(),
                Settings.System.VIBRATE_WHEN_RINGING, 0) == 0) {
                Settings.System.VIBRATE_WHEN_RINGING, 0) == 0 && !isRampingRingerEnabled(context)) {
            ringIntensity = Vibrator.VIBRATION_INTENSITY_OFF;
        }
        CharSequence ringIntensityString =
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ public class RingVibrationIntensityPreferenceController

    public RingVibrationIntensityPreferenceController(Context context) {
        super(context, PREF_KEY, Settings.System.RING_VIBRATION_INTENSITY,
                Settings.System.VIBRATE_WHEN_RINGING);
                Settings.System.VIBRATE_WHEN_RINGING, /* supportRampingRinger= */ true);
    }

    @Override
+5 −1
Original line number Diff line number Diff line
@@ -46,8 +46,12 @@ public class RingVibrationPreferenceFragment extends VibrationPreferenceFragment

    @Override
    protected String getVibrationEnabledSetting() {
        if (AccessibilitySettings.isRampingRingerEnabled(getContext())) {
            return Settings.Global.APPLY_RAMPING_RINGER;
        } else {
            return Settings.System.VIBRATE_WHEN_RINGING;
        }
    }

    @Override
    protected int getPreviewVibrationAudioAttributesUsage() {
+12 −4
Original line number Diff line number Diff line
@@ -40,15 +40,17 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
    private final SettingObserver mSettingsContentObserver;
    private final String mSettingKey;
    private final String mEnabledKey;
    private final boolean mSupportRampingRinger;

    private Preference mPreference;

    public VibrationIntensityPreferenceController(Context context, String prefkey,
            String settingKey, String enabledKey) {
            String settingKey, String enabledKey, boolean supportRampingRinger) {
        super(context, prefkey);
        mVibrator = mContext.getSystemService(Vibrator.class);
        mSettingKey = settingKey;
        mEnabledKey = enabledKey;
        mSupportRampingRinger= supportRampingRinger;
        mSettingsContentObserver = new SettingObserver(settingKey) {
            @Override
            public void onChange(boolean selfChange, Uri uri) {
@@ -57,6 +59,11 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
        };
    }

    public VibrationIntensityPreferenceController(Context context, String prefkey,
            String settingKey, String enabledKey) {
        this(context, prefkey, settingKey, enabledKey, /* supportRampingRinger= */ false);
    }

    @Override
    public void onStart() {
        mContext.getContentResolver().registerContentObserver(
@@ -80,8 +87,9 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
    public CharSequence getSummary() {
        final int intensity = Settings.System.getInt(mContext.getContentResolver(),
                mSettingKey, getDefaultIntensity());
        final boolean enabled = Settings.System.getInt(mContext.getContentResolver(),
                mEnabledKey, 1) == 1;
        final boolean enabled = (Settings.System.getInt(mContext.getContentResolver(),
                mEnabledKey, 1) == 1) ||
                (mSupportRampingRinger && AccessibilitySettings.isRampingRingerEnabled(mContext));
        return getIntensityString(mContext, enabled ? intensity : Vibrator.VIBRATION_INTENSITY_OFF);
    }

+19 −6
Original line number Diff line number Diff line
@@ -114,11 +114,20 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
        boolean vibrationEnabled = candidate.getIntensity() != Vibrator.VIBRATION_INTENSITY_OFF;
        if (hasVibrationEnabledSetting()) {
            // Update vibration enabled setting
            boolean wasEnabled = Settings.System.getInt(getContext().getContentResolver(),
                    getVibrationEnabledSetting(), 1) == 1;
            final String vibrationEnabledSetting = getVibrationEnabledSetting();
            final boolean wasEnabled = TextUtils.equals(
                        vibrationEnabledSetting, Settings.Global.APPLY_RAMPING_RINGER)
                    ? true
                    : (Settings.System.getInt(
                            getContext().getContentResolver(), vibrationEnabledSetting, 1) == 1);
            if (vibrationEnabled != wasEnabled) {
                if (vibrationEnabledSetting.equals(Settings.Global.APPLY_RAMPING_RINGER)) {
                    Settings.Global.putInt(getContext().getContentResolver(),
                            vibrationEnabledSetting, 0);
                } else {
                    Settings.System.putInt(getContext().getContentResolver(),
                    getVibrationEnabledSetting(), vibrationEnabled ? 1 : 0);
                            vibrationEnabledSetting, vibrationEnabled ? 1 : 0);
                }
            }
        }
        // There are two conditions that need to change the intensity.
@@ -196,8 +205,12 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
    protected String getDefaultKey() {
        int vibrationIntensity = Settings.System.getInt(getContext().getContentResolver(),
                getVibrationIntensitySetting(), getDefaultVibrationIntensity());
        final boolean vibrationEnabled = Settings.System.getInt(getContext().getContentResolver(),
                getVibrationEnabledSetting(), 1) == 1;
        final String vibrationEnabledSetting = getVibrationEnabledSetting();
        final boolean vibrationEnabled = TextUtils.equals(
                        vibrationEnabledSetting, Settings.Global.APPLY_RAMPING_RINGER)
                    ? true
                    : (Settings.System.getInt(
                            getContext().getContentResolver(), vibrationEnabledSetting, 1) == 1);
        if (!vibrationEnabled) {
            vibrationIntensity = Vibrator.VIBRATION_INTENSITY_OFF;
        }
Loading