diff --git a/src/com/android/settings/gestures/PreventRingingParentPreferenceController.java b/src/com/android/settings/gestures/PreventRingingParentPreferenceController.java index 88147657b27..afb34315260 100644 --- a/src/com/android/settings/gestures/PreventRingingParentPreferenceController.java +++ b/src/com/android/settings/gestures/PreventRingingParentPreferenceController.java @@ -16,12 +16,20 @@ package com.android.settings.gestures; -import android.content.Context; +import static android.provider.Settings.Secure.VOLUME_HUSH_GESTURE; +import static android.provider.Settings.Secure.VOLUME_HUSH_MUTE; +import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE; +import android.content.Context; +import android.provider.Settings; + +import com.android.settings.R; import com.android.settings.core.BasePreferenceController; public class PreventRingingParentPreferenceController extends BasePreferenceController { + final String SECURE_KEY = VOLUME_HUSH_GESTURE; + public PreventRingingParentPreferenceController(Context context, String preferenceKey) { super(context, preferenceKey); } @@ -33,4 +41,21 @@ public class PreventRingingParentPreferenceController extends BasePreferenceCont ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE; } + @Override + public CharSequence getSummary() { + int value = Settings.Secure.getInt( + mContext.getContentResolver(), SECURE_KEY, VOLUME_HUSH_VIBRATE); + int summary; + switch (value) { + case VOLUME_HUSH_VIBRATE: + summary = R.string.prevent_ringing_option_vibrate_summary; + break; + case VOLUME_HUSH_MUTE: + summary = R.string.prevent_ringing_option_mute_summary; + break; + default: + summary = R.string.prevent_ringing_option_none_summary; + } + return mContext.getText(summary); + } } diff --git a/src/com/android/settings/gestures/PreventRingingPreferenceController.java b/src/com/android/settings/gestures/PreventRingingPreferenceController.java index be55151f91e..7f685e59b56 100644 --- a/src/com/android/settings/gestures/PreventRingingPreferenceController.java +++ b/src/com/android/settings/gestures/PreventRingingPreferenceController.java @@ -50,8 +50,6 @@ public class PreventRingingPreferenceController extends PreventRingingParentPref @VisibleForTesting boolean mVideoPaused; - private final String SECURE_KEY = VOLUME_HUSH_GESTURE; - public PreventRingingPreferenceController(Context context, String key) { super(context, key); } @@ -95,24 +93,6 @@ public class PreventRingingPreferenceController extends PreventRingingParentPref } } - @Override - public CharSequence getSummary() { - int value = Settings.Secure.getInt( - mContext.getContentResolver(), SECURE_KEY, VOLUME_HUSH_VIBRATE); - int summary; - switch (value) { - case VOLUME_HUSH_VIBRATE: - summary = R.string.prevent_ringing_option_vibrate_summary; - break; - case VOLUME_HUSH_MUTE: - summary = R.string.prevent_ringing_option_mute_summary; - break; - default: - summary = R.string.prevent_ringing_option_none_summary; - } - return mContext.getString(summary); - } - @Override public void onCreate(Bundle savedInstanceState) { if (savedInstanceState != null) { diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java index 33a00fac303..bffc847a3b7 100644 --- a/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java @@ -16,14 +16,25 @@ package com.android.settings.gestures; +import static android.provider.Settings.Secure.VOLUME_HUSH_GESTURE; +import static android.provider.Settings.Secure.VOLUME_HUSH_MUTE; +import static android.provider.Settings.Secure.VOLUME_HUSH_OFF; +import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE; + import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE; + import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.res.Resources; +import android.provider.Settings; +import com.android.settings.R; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; @@ -41,18 +52,20 @@ public class PreventRingingParentPreferenceControllerTest { private Context mContext; private PreventRingingParentPreferenceController mController; + private final String VIBRATE_SUMMARY = "On (vibrate)"; + private final String MUTE_SUMMARY = "On (mute)"; + private final String NONE_SUMMARY = "Off"; @Before public void setUp() { MockitoAnnotations.initMocks(this); - mContext = spy(RuntimeEnvironment.application); - when(mContext.getResources()).thenReturn(mResources); - + mContext = spy(RuntimeEnvironment.application.getApplicationContext()); mController = new PreventRingingParentPreferenceController(mContext, "test_key"); } @Test public void testIsAvailable_configIsTrue_shouldAvailableUnSearchable() { + when(mContext.getResources()).thenReturn(mResources); when(mResources.getBoolean( com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(true); @@ -61,9 +74,28 @@ public class PreventRingingParentPreferenceControllerTest { @Test public void testIsAvailable_configIsFalse_shouldReturnFalse() { + when(mContext.getResources()).thenReturn(mResources); when(mResources.getBoolean( com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(false); assertThat(mController.isAvailable()).isFalse(); } + + @Test + public void updateState_summaryUpdated() { + Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE, + VOLUME_HUSH_MUTE); + assertThat(mController.getSummary()).isEqualTo(mContext.getResources().getText( + R.string.prevent_ringing_option_mute_summary)); + + Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE, + VOLUME_HUSH_VIBRATE); + assertThat(mController.getSummary()).isEqualTo(mContext.getResources().getText( + R.string.prevent_ringing_option_vibrate_summary)); + + Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE, + VOLUME_HUSH_OFF); + assertThat(mController.getSummary()).isEqualTo(mContext.getResources().getText( + R.string.prevent_ringing_option_none_summary)); + } } diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java index 833a09d59b0..514bb58dc4d 100644 --- a/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java @@ -87,29 +87,6 @@ public class PreventRingingPreferenceControllerTest { assertThat(mController.isAvailable()).isFalse(); } - @Test - public void testGetSummary_mute() { - Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE, - Settings.Secure.VOLUME_HUSH_MUTE); - assertEquals(mContext.getString(R.string.prevent_ringing_option_mute_summary), - mController.getSummary()); - } - - @Test - public void testGetSummary_vibrate() { - Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE, - Settings.Secure.VOLUME_HUSH_VIBRATE); - assertEquals(mContext.getString(R.string.prevent_ringing_option_vibrate_summary), - mController.getSummary()); - } - @Test - public void testGetSummary_other() { - Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE, - 7); - assertEquals(mContext.getString(R.string.prevent_ringing_option_none_summary), - mController.getSummary()); - } - @Test public void testUpdateState_mute() { ListPreference pref = mock(ListPreference.class);