Migrate SeekBarPreference to SliderPreference for haptics

Bug: 349661486
Change-Id: I03d9b4973c0eea65c0394a292a43663a7f6dcd06
Flag: EXEMPT flag by System prop
Test: manually check the UI
Test: VibrationIntensityPreferenceControllerTest
This commit is contained in:
Lais Andrade
2025-01-14 09:48:34 -08:00
parent 25cd3be6e8
commit 9e74fdbf0d
9 changed files with 115 additions and 110 deletions

View File

@@ -29,7 +29,7 @@
android:key="vibration_intensity_category_call" android:key="vibration_intensity_category_call"
android:title="@string/accessibility_call_vibration_category_title"> android:title="@string/accessibility_call_vibration_category_title">
<com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference
android:key="vibration_intensity_preference_ring" android:key="vibration_intensity_preference_ring"
android:title="@string/accessibility_ring_vibration_title" android:title="@string/accessibility_ring_vibration_title"
app:keywords="@string/keywords_ring_vibration" app:keywords="@string/keywords_ring_vibration"
@@ -47,13 +47,13 @@
android:key="vibration_intensity_category_notification_alarm" android:key="vibration_intensity_category_notification_alarm"
android:title="@string/accessibility_notification_alarm_vibration_category_title"> android:title="@string/accessibility_notification_alarm_vibration_category_title">
<com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference
android:key="vibration_intensity_preference_notification" android:key="vibration_intensity_preference_notification"
android:title="@string/accessibility_notification_vibration_title" android:title="@string/accessibility_notification_vibration_title"
app:keywords="@string/keywords_notification_vibration" app:keywords="@string/keywords_notification_vibration"
app:controller="com.android.settings.accessibility.NotificationVibrationIntensityPreferenceController" /> app:controller="com.android.settings.accessibility.NotificationVibrationIntensityPreferenceController" />
<com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference
android:key="vibration_intensity_preference_alarm" android:key="vibration_intensity_preference_alarm"
android:title="@string/accessibility_alarm_vibration_title" android:title="@string/accessibility_alarm_vibration_title"
app:keywords="@string/keywords_alarm_vibration" app:keywords="@string/keywords_alarm_vibration"
@@ -65,13 +65,13 @@
android:key="vibration_intensity_category_haptics" android:key="vibration_intensity_category_haptics"
android:title="@string/accessibility_interactive_haptics_category_title"> android:title="@string/accessibility_interactive_haptics_category_title">
<com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference
android:key="vibration_intensity_preference_touch" android:key="vibration_intensity_preference_touch"
android:title="@string/accessibility_touch_vibration_title" android:title="@string/accessibility_touch_vibration_title"
app:keywords="@string/keywords_touch_vibration" app:keywords="@string/keywords_touch_vibration"
app:controller="com.android.settings.accessibility.HapticFeedbackIntensityPreferenceController" /> app:controller="com.android.settings.accessibility.HapticFeedbackIntensityPreferenceController" />
<com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference
android:key="vibration_intensity_preference_media" android:key="vibration_intensity_preference_media"
android:title="@string/accessibility_media_vibration_title" android:title="@string/accessibility_media_vibration_title"
app:keywords="@string/keywords_media_vibration" app:keywords="@string/keywords_media_vibration"

View File

@@ -24,10 +24,10 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.SliderPreferenceController; import com.android.settings.core.SliderPreferenceController;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.widget.SliderPreference;
/** /**
* Abstract preference controller for a vibration intensity setting, that displays multiple * Abstract preference controller for a vibration intensity setting, that displays multiple
@@ -69,15 +69,16 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe
@Override @Override
public void displayPreference(PreferenceScreen screen) { public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen); super.displayPreference(screen);
final SeekBarPreference preference = screen.findPreference(getPreferenceKey()); final SliderPreference preference = screen.findPreference(getPreferenceKey());
mSettingsContentObserver.onDisplayPreference(this, preference); mSettingsContentObserver.onDisplayPreference(this, preference);
preference.setEnabled(mPreferenceConfig.isPreferenceEnabled()); preference.setEnabled(mPreferenceConfig.isPreferenceEnabled());
preference.setSummaryProvider(unused -> mPreferenceConfig.getSummary()); preference.setSummaryProvider(unused -> mPreferenceConfig.getSummary());
preference.setMin(getMin()); preference.setMin(getMin());
preference.setMax(getMax()); preference.setMax(getMax());
preference.setSliderIncrement(1); // Discrete slider
// Haptics previews played by the Settings app don't bypass user settings to be played. // Haptics previews played by the Settings app don't bypass user settings to be played.
// The sliders continuously updates the intensity value so the previews can apply them. // The sliders continuously updates the intensity value so the previews can apply them.
preference.setContinuousUpdates(true); preference.setUpdatesContinuously(true);
} }
@Override @Override

View File

@@ -42,6 +42,9 @@ public abstract class SliderPreferenceController extends BasePreferenceControlle
} else if (preference instanceof androidx.preference.SeekBarPreference) { } else if (preference instanceof androidx.preference.SeekBarPreference) {
((androidx.preference.SeekBarPreference) preference) ((androidx.preference.SeekBarPreference) preference)
.setValue(getSliderPosition()); .setValue(getSliderPosition());
} else if (preference instanceof com.android.settingslib.widget.SliderPreference) {
((com.android.settingslib.widget.SliderPreference) preference)
.setValue(getSliderPosition());
} }
} }

View File

@@ -32,8 +32,8 @@ import androidx.test.core.app.ApplicationProvider;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.SliderPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -56,7 +56,7 @@ public class AlarmVibrationIntensityPreferenceControllerTest {
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
private AlarmVibrationIntensityPreferenceController mController; private AlarmVibrationIntensityPreferenceController mController;
private SeekBarPreference mPreference; private SliderPreference mPreference;
@Before @Before
public void setUp() { public void setUp() {
@@ -69,7 +69,7 @@ public class AlarmVibrationIntensityPreferenceControllerTest {
mController = new AlarmVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY, mController = new AlarmVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY,
Vibrator.VIBRATION_INTENSITY_HIGH); Vibrator.VIBRATION_INTENSITY_HIGH);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SeekBarPreference(mContext); mPreference = new SliderPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -91,7 +91,7 @@ public class AlarmVibrationIntensityPreferenceControllerTest {
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo( assertThat(mPreference.getValue()).isEqualTo(
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_ALARM)); mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_ALARM));
} }
@@ -101,17 +101,17 @@ public class AlarmVibrationIntensityPreferenceControllerTest {
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
} }
@@ -119,25 +119,25 @@ public class AlarmVibrationIntensityPreferenceControllerTest {
public void updateState_shouldDisplayIntensityInSliderPosition() { public void updateState_shouldDisplayIntensityInSliderPosition() {
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM); Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
public void setProgress_updatesIntensitySetting() throws Exception { public void setSliderPosition_updatesIntensitySetting() throws Exception {
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.ALARM_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.ALARM_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);

View File

@@ -32,8 +32,8 @@ import androidx.test.core.app.ApplicationProvider;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.SliderPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -58,7 +58,7 @@ public class HapticFeedbackIntensityPreferenceControllerTest {
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
private HapticFeedbackIntensityPreferenceController mController; private HapticFeedbackIntensityPreferenceController mController;
private SeekBarPreference mPreference; private SliderPreference mPreference;
@Before @Before
public void setUp() { public void setUp() {
@@ -71,7 +71,7 @@ public class HapticFeedbackIntensityPreferenceControllerTest {
mController = new HapticFeedbackIntensityPreferenceController(mContext, PREFERENCE_KEY, mController = new HapticFeedbackIntensityPreferenceController(mContext, PREFERENCE_KEY,
Vibrator.VIBRATION_INTENSITY_HIGH); Vibrator.VIBRATION_INTENSITY_HIGH);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SeekBarPreference(mContext); mPreference = new SliderPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -91,7 +91,7 @@ public class HapticFeedbackIntensityPreferenceControllerTest {
Settings.System.putString(mContext.getContentResolver(), Settings.System.putString(mContext.getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_INTENSITY, /* value= */ null); Settings.System.HAPTIC_FEEDBACK_INTENSITY, /* value= */ null);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()) assertThat(mPreference.getValue())
.isEqualTo(mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_TOUCH)); .isEqualTo(mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_TOUCH));
} }
@@ -101,17 +101,17 @@ public class HapticFeedbackIntensityPreferenceControllerTest {
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
} }
@@ -121,44 +121,44 @@ public class HapticFeedbackIntensityPreferenceControllerTest {
updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM); Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
public void updateState_shouldDisplayIntensityInSliderPosition() { public void updateState_shouldDisplayIntensityInSliderPosition() {
updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM); Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
public void setProgress_updatesIntensityAndDependentSettings() throws Exception { public void setSliderPosition_updatesIntensityAndDependentSettings() throws Exception {
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY)) assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);

View File

@@ -34,8 +34,8 @@ import com.android.settings.R;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.SettingsShadowResources; import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.SliderPreference;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@@ -60,7 +60,7 @@ public class MediaVibrationIntensityPreferenceControllerTest {
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
private MediaVibrationIntensityPreferenceController mController; private MediaVibrationIntensityPreferenceController mController;
private SeekBarPreference mPreference; private SliderPreference mPreference;
@Before @Before
public void setUp() { public void setUp() {
@@ -73,7 +73,7 @@ public class MediaVibrationIntensityPreferenceControllerTest {
mController = new MediaVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY, mController = new MediaVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY,
Vibrator.VIBRATION_INTENSITY_HIGH); Vibrator.VIBRATION_INTENSITY_HIGH);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SeekBarPreference(mContext); mPreference = new SliderPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -100,7 +100,7 @@ public class MediaVibrationIntensityPreferenceControllerTest {
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo( assertThat(mPreference.getValue()).isEqualTo(
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_MEDIA)); mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_MEDIA));
} }
@@ -110,17 +110,17 @@ public class MediaVibrationIntensityPreferenceControllerTest {
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
} }
@@ -128,25 +128,25 @@ public class MediaVibrationIntensityPreferenceControllerTest {
public void updateState_shouldDisplayIntensityInSliderPosition() { public void updateState_shouldDisplayIntensityInSliderPosition() {
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM); Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
public void setProgress_updatesIntensitySetting() throws Exception { public void setSliderPosition_updatesIntensitySetting() throws Exception {
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.MEDIA_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.MEDIA_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);

View File

@@ -30,10 +30,11 @@ import android.provider.Settings;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.SliderPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -56,7 +57,7 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
private NotificationVibrationIntensityPreferenceController mController; private NotificationVibrationIntensityPreferenceController mController;
private SeekBarPreference mPreference; private SliderPreference mPreference;
@Before @Before
public void setUp() { public void setUp() {
@@ -69,7 +70,7 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
mController = new NotificationVibrationIntensityPreferenceController(mContext, mController = new NotificationVibrationIntensityPreferenceController(mContext,
PREFERENCE_KEY, Vibrator.VIBRATION_INTENSITY_HIGH); PREFERENCE_KEY, Vibrator.VIBRATION_INTENSITY_HIGH);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SeekBarPreference(mContext); mPreference = new SliderPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -89,7 +90,7 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
Settings.System.putString(mContext.getContentResolver(), Settings.System.putString(mContext.getContentResolver(),
Settings.System.NOTIFICATION_VIBRATION_INTENSITY, /* value= */ null); Settings.System.NOTIFICATION_VIBRATION_INTENSITY, /* value= */ null);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo( assertThat(mPreference.getValue()).isEqualTo(
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_NOTIFICATION)); mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_NOTIFICATION));
} }
@@ -101,22 +102,21 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.getSummary()).isNull(); assertThat(mPreference.getSummary()).isNull();
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
// TODO(b/136805769): summary is broken in SeekBarPreference, enable this once fixed assertThat(mPreference.getSummary()).isNotNull();
// assertThat(mPreference.getSummary()).isNotNull(); assertThat(mPreference.getSummary().toString()).isEqualTo(mContext.getString(
// assertThat(mPreference.getSummary().toString()).isEqualTo(mContext.getString( R.string.accessibility_vibration_setting_disabled_for_silent_mode_summary));
// R.string.accessibility_vibration_setting_disabled_for_silent_mode_summary));
assertThat(mPreference.isEnabled()).isFalse(); assertThat(mPreference.isEnabled()).isFalse();
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.getSummary()).isNull(); assertThat(mPreference.getSummary()).isNull();
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
} }
@@ -126,27 +126,27 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
updateSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY, updateSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_HIGH); Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
updateSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY, updateSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM); Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY, updateSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_LOW); Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY, updateSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_OFF); Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
public void setProgress_updatesIntensitySetting() throws Exception { public void setSliderPosition_updatesIntensitySetting() throws Exception {
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);

View File

@@ -30,10 +30,11 @@ import android.provider.Settings;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.SliderPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -59,7 +60,7 @@ public class RingVibrationIntensityPreferenceControllerTest {
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
private RingVibrationIntensityPreferenceController mController; private RingVibrationIntensityPreferenceController mController;
private SeekBarPreference mPreference; private SliderPreference mPreference;
@Before @Before
public void setUp() { public void setUp() {
@@ -72,7 +73,7 @@ public class RingVibrationIntensityPreferenceControllerTest {
mController = new RingVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY, mController = new RingVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY,
Vibrator.VIBRATION_INTENSITY_HIGH); Vibrator.VIBRATION_INTENSITY_HIGH);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SeekBarPreference(mContext); mPreference = new SliderPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -92,7 +93,7 @@ public class RingVibrationIntensityPreferenceControllerTest {
Settings.System.putString(mContext.getContentResolver(), Settings.System.putString(mContext.getContentResolver(),
Settings.System.RING_VIBRATION_INTENSITY, /* value= */ null); Settings.System.RING_VIBRATION_INTENSITY, /* value= */ null);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo( assertThat(mPreference.getValue()).isEqualTo(
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_RINGTONE)); mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_RINGTONE));
} }
@@ -102,22 +103,21 @@ public class RingVibrationIntensityPreferenceControllerTest {
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.getSummary()).isNull(); assertThat(mPreference.getSummary()).isNull();
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
// TODO(b/136805769): summary is broken in SeekBarPreference, enable this once fixed assertThat(mPreference.getSummary()).isNotNull();
// assertThat(mPreference.getSummary()).isNotNull(); assertThat(mPreference.getSummary().toString()).isEqualTo(mContext.getString(
// assertThat(mPreference.getSummary().toString()).isEqualTo(mContext.getString( R.string.accessibility_vibration_setting_disabled_for_silent_mode_summary));
// R.string.accessibility_vibration_setting_disabled_for_silent_mode_summary));
assertThat(mPreference.isEnabled()).isFalse(); assertThat(mPreference.isEnabled()).isFalse();
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.getSummary()).isNull(); assertThat(mPreference.getSummary()).isNull();
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
} }
@@ -129,44 +129,44 @@ public class RingVibrationIntensityPreferenceControllerTest {
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, updateSetting(Settings.System.RING_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM); Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
public void updateState_shouldDisplayIntensityInSliderPosition() { public void updateState_shouldDisplayIntensityInSliderPosition() {
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, updateSetting(Settings.System.RING_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM); Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
public void setProgress_updatesIntensityAndDependentSettings() throws Exception { public void setSliderPosition_updatesIntensityAndDependentSettings() throws Exception {
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);

View File

@@ -29,8 +29,8 @@ import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.SliderPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -70,7 +70,7 @@ public class VibrationIntensityPreferenceControllerTest {
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
private SeekBarPreference mPreference; private SliderPreference mPreference;
@Before @Before
public void setUp() { public void setUp() {
@@ -85,7 +85,7 @@ public class VibrationIntensityPreferenceControllerTest {
VibrationIntensityPreferenceController controller = createPreferenceController(3); VibrationIntensityPreferenceController controller = createPreferenceController(3);
Settings.System.putString(mContext.getContentResolver(), SETTING_KEY, /* value= */ null); Settings.System.putString(mContext.getContentResolver(), SETTING_KEY, /* value= */ null);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()) assertThat(mPreference.getValue())
.isEqualTo(mVibrator.getDefaultVibrationIntensity(VIBRATION_USAGE)); .isEqualTo(mVibrator.getDefaultVibrationIntensity(VIBRATION_USAGE));
} }
@@ -96,17 +96,17 @@ public class VibrationIntensityPreferenceControllerTest {
updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, ON); updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, ON);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, OFF); updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, OFF);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(mPreference.isEnabled()).isFalse(); assertThat(mPreference.isEnabled()).isFalse();
updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, ON); updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, ON);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.isEnabled()).isTrue(); assertThat(mPreference.isEnabled()).isTrue();
} }
@@ -116,19 +116,19 @@ public class VibrationIntensityPreferenceControllerTest {
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_HIGH);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_MEDIUM); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_MEDIUM);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
@@ -137,19 +137,19 @@ public class VibrationIntensityPreferenceControllerTest {
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_HIGH);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_MEDIUM); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_MEDIUM);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
@@ -158,39 +158,39 @@ public class VibrationIntensityPreferenceControllerTest {
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_HIGH);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_MEDIUM); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_MEDIUM);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
public void setProgress_mainSwitchDisabled_ignoresUpdates() throws Exception { public void setSliderPosition_mainSwitchDisabled_ignoresUpdates() throws Exception {
VibrationIntensityPreferenceController controller = createPreferenceController(3); VibrationIntensityPreferenceController controller = createPreferenceController(3);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, OFF); updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, OFF);
controller.updateState(mPreference); controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(mPreference.isEnabled()).isFalse(); assertThat(mPreference.isEnabled()).isFalse();
assertThat(controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH)).isFalse(); assertThat(controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH)).isFalse();
assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@Test @Test
public void setProgress_allSupportedPositions_updatesIntensitySetting() throws Exception { public void setSliderPosition_allSupportedPositions_updatesIntensitySetting() throws Exception {
VibrationIntensityPreferenceController controller = createPreferenceController(3); VibrationIntensityPreferenceController controller = createPreferenceController(3);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
@@ -207,7 +207,8 @@ public class VibrationIntensityPreferenceControllerTest {
} }
@Test @Test
public void setProgress_twoSupportedPositions_updatesMediumPositionToHigh() throws Exception { public void setSliderPosition_twoSupportedPositions_updatesMediumPositionToHigh()
throws Exception {
VibrationIntensityPreferenceController controller = createPreferenceController(2); VibrationIntensityPreferenceController controller = createPreferenceController(2);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
@@ -224,7 +225,7 @@ public class VibrationIntensityPreferenceControllerTest {
} }
@Test @Test
public void setProgress_oneSupportedPosition_updatesOnPositionsToDeviceDefault() public void setSliderPosition_oneSupportedPosition_updatesOnPositionsToDeviceDefault()
throws Exception { throws Exception {
int defaultIntensity = mVibrator.getDefaultVibrationIntensity(VIBRATION_USAGE); int defaultIntensity = mVibrator.getDefaultVibrationIntensity(VIBRATION_USAGE);
VibrationIntensityPreferenceController controller = createPreferenceController(1); VibrationIntensityPreferenceController controller = createPreferenceController(1);
@@ -255,7 +256,7 @@ public class VibrationIntensityPreferenceControllerTest {
VibrationIntensityPreferenceController controller = VibrationIntensityPreferenceController controller =
new TestPreferenceController(mContext, supportedIntensityLevels); new TestPreferenceController(mContext, supportedIntensityLevels);
mLifecycle.addObserver(controller); mLifecycle.addObserver(controller);
mPreference = new SeekBarPreference(mContext); mPreference = new SliderPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(controller.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(controller.getPreferenceKey())).thenReturn(mPreference);
controller.displayPreference(mScreen); controller.displayPreference(mScreen);