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

@@ -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 =

View File

@@ -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

View File

@@ -46,7 +46,11 @@ public class RingVibrationPreferenceFragment extends VibrationPreferenceFragment
@Override
protected String getVibrationEnabledSetting() {
return Settings.System.VIBRATE_WHEN_RINGING;
if (AccessibilitySettings.isRampingRingerEnabled(getContext())) {
return Settings.Global.APPLY_RAMPING_RINGER;
} else {
return Settings.System.VIBRATE_WHEN_RINGING;
}
}
@Override

View File

@@ -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,10 +87,11 @@ 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);
}
}
public static CharSequence getIntensityString(Context context, int intensity) {
final boolean supportsMultipleIntensities = context.getResources().getBoolean(

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;
}