Make Media Vibration setting configurable
Add a configuration boolean to control whether or not to display Media Vibration switch (default: display the switch). This configuration can then be overriden by OEMs for devices that don't support media vibration. Bug: 268657239 Test: make RunSettingsRoboTests ROBOTEST_FILTER= "com.android.settings.accessibility.MediaVibration" Change-Id: I91857fbb04abc97b290559895010c3cbeef7ebab
This commit is contained in:
@@ -31,10 +31,13 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.widget.SeekBarPreference;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -45,7 +48,7 @@ import org.robolectric.annotation.Config;
|
||||
|
||||
/** Test for {@link MediaVibrationIntensityPreferenceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowInteractionJankMonitor.class})
|
||||
@Config(shadows = {ShadowInteractionJankMonitor.class, SettingsShadowResources.class})
|
||||
public class MediaVibrationIntensityPreferenceControllerTest {
|
||||
|
||||
private static final String PREFERENCE_KEY = "preference_key";
|
||||
@@ -76,6 +79,11 @@ public class MediaVibrationIntensityPreferenceControllerTest {
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyConstants() {
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo(PREFERENCE_KEY);
|
||||
@@ -156,6 +164,32 @@ public class MediaVibrationIntensityPreferenceControllerTest {
|
||||
.isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configForMediaVibration_enabled_shouldShowSlider() {
|
||||
SettingsShadowResources.overrideResource(R.bool.config_media_vibration_supported, true);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
final boolean mediaVibrationConfig = mContext.getResources()
|
||||
.getBoolean(R.bool.config_media_vibration_supported);
|
||||
|
||||
assertThat(mediaVibrationConfig).isTrue();
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mController.isSupported()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configForMediaVibration_disabled_shouldHideSlider() {
|
||||
SettingsShadowResources.overrideResource(R.bool.config_media_vibration_supported, false);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
final boolean mediaVibrationConfig = mContext.getResources()
|
||||
.getBoolean(R.bool.config_media_vibration_supported);
|
||||
|
||||
assertThat(mediaVibrationConfig).isFalse();
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mController.isSupported()).isFalse();
|
||||
}
|
||||
|
||||
private void updateSetting(String key, int value) {
|
||||
Settings.System.putInt(mContext.getContentResolver(), key, value);
|
||||
}
|
||||
|
@@ -32,17 +32,22 @@ import androidx.preference.SwitchPreference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Test for {@link MediaVibrationIntensityPreferenceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {SettingsShadowResources.class})
|
||||
public class MediaVibrationTogglePreferenceControllerTest {
|
||||
|
||||
private static final String PREFERENCE_KEY = "preference_key";
|
||||
@@ -72,6 +77,11 @@ public class MediaVibrationTogglePreferenceControllerTest {
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyConstants() {
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo(PREFERENCE_KEY);
|
||||
@@ -144,6 +154,32 @@ public class MediaVibrationTogglePreferenceControllerTest {
|
||||
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configForMediaVibration_enabled_shouldShowToogle() {
|
||||
SettingsShadowResources.overrideResource(R.bool.config_media_vibration_supported, true);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
final boolean mediaVibrationConfig = mContext.getResources()
|
||||
.getBoolean(R.bool.config_media_vibration_supported);
|
||||
|
||||
assertThat(mediaVibrationConfig).isTrue();
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mController.isSupported()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configForMediaVibration_disabled_shouldHideToggle() {
|
||||
SettingsShadowResources.overrideResource(R.bool.config_media_vibration_supported, false);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
final boolean mediaVibrationConfig = mContext.getResources()
|
||||
.getBoolean(R.bool.config_media_vibration_supported);
|
||||
|
||||
assertThat(mediaVibrationConfig).isFalse();
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mController.isSupported()).isFalse();
|
||||
}
|
||||
|
||||
private void updateSetting(String key, int value) {
|
||||
Settings.System.putInt(mContext.getContentResolver(), key, value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user