Merge "Hide haptic intensity settings for devices without enough dynamic range." into pi-dev am: 8c60fc69b7
am: 23460d03bc
Change-Id: I5c5e8a4157874f19abe28201fba772c72bc7f9d9
This commit is contained in:
@@ -18,10 +18,12 @@ package com.android.settings.accessibility;
|
||||
|
||||
import static android.provider.Settings.System.NOTIFICATION_VIBRATION_INTENSITY;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.Settings;
|
||||
import androidx.preference.Preference;
|
||||
@@ -48,6 +50,7 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private Lifecycle mLifecycle;
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private NotificationVibrationIntensityPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
|
||||
@@ -56,7 +59,11 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(R.bool.config_vibration_supports_multiple_intensities))
|
||||
.thenReturn(true);
|
||||
mController = new NotificationVibrationIntensityPreferenceController(mContext) {
|
||||
@Override
|
||||
protected int getDefaultIntensity() {
|
||||
@@ -68,7 +75,6 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
|
||||
mPreference.setSummary("Test");
|
||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,7 +86,10 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldRefreshSummary() {
|
||||
public void updateState_withMultipleIntensitySuport_shouldRefreshSummary() {
|
||||
setSupportsMultipleIntensities(true);
|
||||
showPreference();
|
||||
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
|
||||
mController.updateState(mPreference);
|
||||
@@ -105,4 +114,43 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.accessibility_vibration_intensity_off));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_withoutMultipleIntensitySupport_shouldRefreshSummary() {
|
||||
setSupportsMultipleIntensities(false);
|
||||
showPreference();
|
||||
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.switch_on_text));
|
||||
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.switch_on_text));
|
||||
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_MEDIUM);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.switch_on_text));
|
||||
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.switch_off_text));
|
||||
}
|
||||
|
||||
private void setSupportsMultipleIntensities(boolean hasSupport) {
|
||||
when(mResources.getBoolean(R.bool.config_vibration_supports_multiple_intensities))
|
||||
.thenReturn(hasSupport);
|
||||
}
|
||||
|
||||
private void showPreference() {
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,16 +20,19 @@ import static com.android.settings.accessibility.VibrationPreferenceFragment.KEY
|
||||
import static com.android.settings.accessibility.VibrationPreferenceFragment.KEY_INTENSITY_LOW;
|
||||
import static com.android.settings.accessibility.VibrationPreferenceFragment.KEY_INTENSITY_MEDIUM;
|
||||
import static com.android.settings.accessibility.VibrationPreferenceFragment.KEY_INTENSITY_OFF;
|
||||
import static com.android.settings.accessibility.VibrationPreferenceFragment.KEY_INTENSITY_ON;
|
||||
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.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.UserManager;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.VibrationPreferenceFragment.VibrationIntensityCandidateInfo;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -58,12 +61,11 @@ public class VibrationPreferenceFragmentTest {
|
||||
INTENSITY_TO_KEY.put(Vibrator.VIBRATION_INTENSITY_HIGH, KEY_INTENSITY_HIGH);
|
||||
}
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private TestVibrationPreferenceFragment mFragment;
|
||||
|
||||
@Before
|
||||
@@ -71,16 +73,18 @@ public class VibrationPreferenceFragmentTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest();
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
mFragment = spy(new TestVibrationPreferenceFragment());
|
||||
doReturn(mUserManager).when(mActivity).getSystemService(Context.USER_SERVICE);
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
mFragment.onAttach(mActivity);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeIntensitySetting_shouldResultInCorrespondingKey() {
|
||||
setSupportsMultipleIntensities(true);
|
||||
mFragment.onAttach(mContext);
|
||||
for (Map.Entry<Integer, String> entry : INTENSITY_TO_KEY.entrySet()) {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.System.HAPTIC_FEEDBACK_INTENSITY, entry.getKey());
|
||||
@@ -88,13 +92,38 @@ public class VibrationPreferenceFragmentTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeIntensitySetting_WithoutMultipleIntensitySupport_shouldResultInOn() {
|
||||
setSupportsMultipleIntensities(false);
|
||||
mFragment.onAttach(mContext);
|
||||
for (int intensity : INTENSITY_TO_KEY.keySet()) {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.System.HAPTIC_FEEDBACK_INTENSITY, intensity);
|
||||
final String expectedKey = intensity == Vibrator.VIBRATION_INTENSITY_OFF
|
||||
? KEY_INTENSITY_OFF
|
||||
: KEY_INTENSITY_ON;
|
||||
assertThat(mFragment.getDefaultKey()).isEqualTo(expectedKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialDefaultKey_shouldBeMedium() {
|
||||
setSupportsMultipleIntensities(true);
|
||||
mFragment.onAttach(mContext);
|
||||
assertThat(mFragment.getDefaultKey()).isEqualTo(KEY_INTENSITY_MEDIUM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialDefaultKey_WithoutMultipleIntensitySupport_shouldBeOn() {
|
||||
setSupportsMultipleIntensities(false);
|
||||
mFragment.onAttach(mContext);
|
||||
assertThat(mFragment.getDefaultKey()).isEqualTo(KEY_INTENSITY_ON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void candidates_shouldBeSortedByIntensity() {
|
||||
setSupportsMultipleIntensities(true);
|
||||
mFragment.onAttach(mContext);
|
||||
final List<? extends CandidateInfo> candidates = mFragment.getCandidates();
|
||||
assertThat(candidates.size()).isEqualTo(INTENSITY_TO_KEY.size());
|
||||
VibrationIntensityCandidateInfo prevCandidate =
|
||||
@@ -106,6 +135,11 @@ public class VibrationPreferenceFragmentTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void setSupportsMultipleIntensities(boolean hasSupport) {
|
||||
when(mResources.getBoolean(R.bool.config_vibration_supports_multiple_intensities))
|
||||
.thenReturn(hasSupport);
|
||||
}
|
||||
|
||||
private class TestVibrationPreferenceFragment extends VibrationPreferenceFragment {
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
@@ -129,5 +163,10 @@ public class VibrationPreferenceFragmentTest {
|
||||
protected int getDefaultVibrationIntensity() {
|
||||
return Vibrator.VIBRATION_INTENSITY_MEDIUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user