Merge "Make Media Vibration setting configurable" am: dcb1dbc7f5
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/2432412 Change-Id: I1b9b9ff95026831fec9329ccfefeb6096e984389 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -217,6 +217,10 @@
|
||||
-->
|
||||
<integer name="config_vibration_supported_intensity_levels">1</integer>
|
||||
|
||||
<!-- Whether or not to show Media vibration settings in the vibration and haptics screen.
|
||||
Can be overridden for specific product builds if the target device does not support it -->
|
||||
<bool name="config_media_vibration_supported">true</bool>
|
||||
|
||||
<!--
|
||||
Whether or not the homepage should be powered by legacy suggestion (versus contextual cards)
|
||||
Default to true as not all devices support contextual cards.
|
||||
|
@@ -20,6 +20,8 @@ import android.content.Context;
|
||||
import android.os.VibrationAttributes;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/** Preference controller for am vibration intensity */
|
||||
public class MediaVibrationIntensityPreferenceController
|
||||
extends VibrationIntensityPreferenceController {
|
||||
@@ -46,6 +48,7 @@ public class MediaVibrationIntensityPreferenceController
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
return mContext.getResources().getBoolean(R.bool.config_media_vibration_supported) ?
|
||||
AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.accessibility;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.accessibility.MediaVibrationIntensityPreferenceController.MediaVibrationPreferenceConfig;
|
||||
import com.android.settings.R;
|
||||
|
||||
/** Preference controller for alarm vibration with only a toggle for on/off states. */
|
||||
public class MediaVibrationTogglePreferenceController extends VibrationTogglePreferenceController {
|
||||
@@ -29,6 +30,7 @@ public class MediaVibrationTogglePreferenceController extends VibrationTogglePre
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
return mContext.getResources().getBoolean(R.bool.config_media_vibration_supported) ?
|
||||
AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
}
|
||||
|
@@ -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