Merge "Keep consistency between sound and accessibility settings."
This commit is contained in:
@@ -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 =
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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(
|
||||
|
@@ -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.
|
||||
@@ -189,8 +198,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;
|
||||
}
|
||||
|
@@ -25,12 +25,14 @@ import android.app.UiModeManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -38,6 +40,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -135,6 +138,32 @@ public class AccessibilitySettingsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public void testIsRampingRingerEnabled_bothFlagsOn_Enabled() {
|
||||
Settings.Global.putInt(
|
||||
mContext.getContentResolver(), Settings.Global.APPLY_RAMPING_RINGER, 1 /* ON */);
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_TELEPHONY,
|
||||
AccessibilitySettings.RAMPING_RINGER_ENABLED, "true", false /* makeDefault*/);
|
||||
assertThat(AccessibilitySettings.isRampingRingerEnabled(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public void testIsRampingRingerEnabled_settingsFlagOff_Disabled() {
|
||||
Settings.Global.putInt(
|
||||
mContext.getContentResolver(), Settings.Global.APPLY_RAMPING_RINGER, 0 /* OFF */);
|
||||
assertThat(AccessibilitySettings.isRampingRingerEnabled(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public void testIsRampingRingerEnabled_deviceConfigFlagOff_Disabled() {
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_TELEPHONY,
|
||||
AccessibilitySettings.RAMPING_RINGER_ENABLED, "false", false /* makeDefault*/);
|
||||
assertThat(AccessibilitySettings.isRampingRingerEnabled(mContext)).isFalse();
|
||||
}
|
||||
|
||||
private void verifyAccessibilityTimeoutSummary(String preferenceKey, int resId) {
|
||||
final Preference preference = new Preference(mContext);
|
||||
doReturn(preference).when(mSettings).findPreference(preferenceKey);
|
||||
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class RingVibrationPreferenceFragmentTest {
|
||||
|
||||
private Context mContext;
|
||||
private RingVibrationPreferenceFragment mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mFragment = spy(new RingVibrationPreferenceFragment());
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public void getVibrationEnabledSetting_rampingRingerEnabled_returnApplyRampingRinger() {
|
||||
// Turn on both flags to enable ramping ringer.
|
||||
Settings.Global.putInt(
|
||||
mContext.getContentResolver(), Settings.Global.APPLY_RAMPING_RINGER, 1 /* ON */);
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_TELEPHONY,
|
||||
AccessibilitySettings.RAMPING_RINGER_ENABLED, "true", false /* makeDefault*/);
|
||||
assertThat(mFragment.getVibrationEnabledSetting()).isEqualTo(
|
||||
Settings.Global.APPLY_RAMPING_RINGER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVibrationEnabledSetting_rampingRingerDisabled_returnVibrationWhenRinging() {
|
||||
// Turn off Settings.Global.APPLY_RAMPING_RINGER to disable ramping ringer.
|
||||
Settings.Global.putInt(
|
||||
mContext.getContentResolver(), Settings.Global.APPLY_RAMPING_RINGER, 0 /* OFF */);
|
||||
assertThat(mFragment.getVibrationEnabledSetting()).isEqualTo(
|
||||
Settings.System.VIBRATE_WHEN_RINGING);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user