Keep consistency between sound and accessibility settings.

Bug: 130741987
Test: Tested on device
Change-Id: Id6dd485c73f9453970b8d79929ffc04acb2c76c8
(cherry picked from commit 494071463b)
This commit is contained in:
Yiwen Chen
2019-05-01 12:13:56 -07:00
parent b731f4d5b9
commit 85580fbc88
7 changed files with 150 additions and 13 deletions

View File

@@ -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) {
Settings.System.putInt(getContext().getContentResolver(),
getVibrationEnabledSetting(), vibrationEnabled ? 1 : 0);
if (vibrationEnabledSetting.equals(Settings.Global.APPLY_RAMPING_RINGER)) {
Settings.Global.putInt(getContext().getContentResolver(),
vibrationEnabledSetting, 0);
} else {
Settings.System.putInt(getContext().getContentResolver(),
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;
}