Loading src/com/android/settings/notification/BadgingNotificationPreferenceController.java +20 −3 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settings.notification; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; Loading @@ -28,6 +29,10 @@ import android.support.v7.preference.TwoStatePreference; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settings.R; import com.android.settings.search.DatabaseIndexingUtils; import com.android.settings.search.InlineSwitchPayload; import com.android.settings.search.ResultPayload; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnPause; import com.android.settingslib.core.lifecycle.events.OnResume; Loading @@ -40,7 +45,8 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC private static final String TAG = "BadgeNotifPrefContr"; private static final String KEY_NOTIFICATION_BADGING = "notification_badging"; private static final int DEFAULT_VALUE = 1; private static final int ON = 1; private static final int OFF = 0; private SettingObserver mSettingObserver; Loading Loading @@ -85,7 +91,7 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC @Override public void updateState(Preference preference) { final boolean checked = Settings.Secure.getInt(mContext.getContentResolver(), NOTIFICATION_BADGING, DEFAULT_VALUE) == 1; NOTIFICATION_BADGING, ON) == ON; ((TwoStatePreference) preference).setChecked(checked); } Loading @@ -93,7 +99,7 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean val = (Boolean) newValue; return Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, val ? 1 : 0); NOTIFICATION_BADGING, val ? ON : OFF); } class SettingObserver extends ContentObserver { Loading Loading @@ -124,4 +130,15 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC } } } @Override public ResultPayload getResultPayload() { final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext, ConfigureNotificationSettings.class.getName(), KEY_NOTIFICATION_BADGING, mContext.getString(R.string.configure_notification_settings)); return new InlineSwitchPayload(Settings.Secure.NOTIFICATION_BADGING, ResultPayload.SettingsSource.SECURE, ON /* onValue */, intent, isAvailable(), ON /* defaultValue */); } } tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settings.notification; import android.content.ContentResolver; import android.content.Context; import android.provider.Settings; import android.support.v7.preference.Preference; Loading @@ -23,6 +24,9 @@ import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.TwoStatePreference; import com.android.settings.TestConfig; import com.android.settings.search.InlinePayload; import com.android.settings.search.InlineSwitchPayload; import com.android.settings.testutils.shadow.ShadowSecureSettings; import org.junit.Before; import org.junit.Test; Loading @@ -35,6 +39,9 @@ import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; import static android.provider.Settings.Secure.NOTIFICATION_BADGING; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; Loading Loading @@ -106,4 +113,35 @@ public class BadgingNotificationPreferenceControllerTest { verify(preference).setChecked(false); } @Test public void testPreferenceController_ProperResultPayloadType() { assertThat(mController.getResultPayload()).isInstanceOf(InlineSwitchPayload.class); } @Test @Config(shadows = ShadowSecureSettings.class) public void testSetValue_updatesCorrectly() { int newValue = 0; ContentResolver resolver = mContext.getContentResolver(); Settings.Secure.putInt(resolver, Settings.Secure.NOTIFICATION_BADGING, 1); ((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue); int updatedValue = Settings.Secure.getInt(resolver, Settings.Secure.NOTIFICATION_BADGING, 1); assertThat(updatedValue).isEqualTo(newValue); } @Test @Config(shadows = ShadowSecureSettings.class) public void testGetValue_correctValueReturned() { int currentValue = 1; ContentResolver resolver = mContext.getContentResolver(); Settings.Secure.putInt(resolver, Settings.Secure.NOTIFICATION_BADGING, currentValue); int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext); assertThat(newValue).isEqualTo(currentValue); } } Loading
src/com/android/settings/notification/BadgingNotificationPreferenceController.java +20 −3 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settings.notification; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; Loading @@ -28,6 +29,10 @@ import android.support.v7.preference.TwoStatePreference; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settings.R; import com.android.settings.search.DatabaseIndexingUtils; import com.android.settings.search.InlineSwitchPayload; import com.android.settings.search.ResultPayload; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnPause; import com.android.settingslib.core.lifecycle.events.OnResume; Loading @@ -40,7 +45,8 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC private static final String TAG = "BadgeNotifPrefContr"; private static final String KEY_NOTIFICATION_BADGING = "notification_badging"; private static final int DEFAULT_VALUE = 1; private static final int ON = 1; private static final int OFF = 0; private SettingObserver mSettingObserver; Loading Loading @@ -85,7 +91,7 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC @Override public void updateState(Preference preference) { final boolean checked = Settings.Secure.getInt(mContext.getContentResolver(), NOTIFICATION_BADGING, DEFAULT_VALUE) == 1; NOTIFICATION_BADGING, ON) == ON; ((TwoStatePreference) preference).setChecked(checked); } Loading @@ -93,7 +99,7 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean val = (Boolean) newValue; return Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, val ? 1 : 0); NOTIFICATION_BADGING, val ? ON : OFF); } class SettingObserver extends ContentObserver { Loading Loading @@ -124,4 +130,15 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC } } } @Override public ResultPayload getResultPayload() { final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext, ConfigureNotificationSettings.class.getName(), KEY_NOTIFICATION_BADGING, mContext.getString(R.string.configure_notification_settings)); return new InlineSwitchPayload(Settings.Secure.NOTIFICATION_BADGING, ResultPayload.SettingsSource.SECURE, ON /* onValue */, intent, isAvailable(), ON /* defaultValue */); } }
tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settings.notification; import android.content.ContentResolver; import android.content.Context; import android.provider.Settings; import android.support.v7.preference.Preference; Loading @@ -23,6 +24,9 @@ import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.TwoStatePreference; import com.android.settings.TestConfig; import com.android.settings.search.InlinePayload; import com.android.settings.search.InlineSwitchPayload; import com.android.settings.testutils.shadow.ShadowSecureSettings; import org.junit.Before; import org.junit.Test; Loading @@ -35,6 +39,9 @@ import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; import static android.provider.Settings.Secure.NOTIFICATION_BADGING; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; Loading Loading @@ -106,4 +113,35 @@ public class BadgingNotificationPreferenceControllerTest { verify(preference).setChecked(false); } @Test public void testPreferenceController_ProperResultPayloadType() { assertThat(mController.getResultPayload()).isInstanceOf(InlineSwitchPayload.class); } @Test @Config(shadows = ShadowSecureSettings.class) public void testSetValue_updatesCorrectly() { int newValue = 0; ContentResolver resolver = mContext.getContentResolver(); Settings.Secure.putInt(resolver, Settings.Secure.NOTIFICATION_BADGING, 1); ((InlinePayload) mController.getResultPayload()).setValue(mContext, newValue); int updatedValue = Settings.Secure.getInt(resolver, Settings.Secure.NOTIFICATION_BADGING, 1); assertThat(updatedValue).isEqualTo(newValue); } @Test @Config(shadows = ShadowSecureSettings.class) public void testGetValue_correctValueReturned() { int currentValue = 1; ContentResolver resolver = mContext.getContentResolver(); Settings.Secure.putInt(resolver, Settings.Secure.NOTIFICATION_BADGING, currentValue); int newValue = ((InlinePayload) mController.getResultPayload()).getValue(mContext); assertThat(newValue).isEqualTo(currentValue); } }