From aa5618fd820697be0e11fcbbb29ff52eaa96cd52 Mon Sep 17 00:00:00 2001 From: jackqdyulei Date: Mon, 24 Jul 2017 18:34:33 -0700 Subject: [PATCH] Add ResultPayload for Allow notification dots Bug: 62022517 Test: robotests Change-Id: I86caa1c8604ae8eff27574ca45b5e9f3f6830f8f --- .../BadgingNotificationPreferenceController.java | 23 +++++++++++-- ...adgingNotificationPreferenceControllerTest.java | 38 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/notification/BadgingNotificationPreferenceController.java b/src/com/android/settings/notification/BadgingNotificationPreferenceController.java index 39522e83ad..94eccf9d37 100644 --- a/src/com/android/settings/notification/BadgingNotificationPreferenceController.java +++ b/src/com/android/settings/notification/BadgingNotificationPreferenceController.java @@ -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; @@ -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; @@ -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; @@ -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); } @@ -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 { @@ -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 */); + } } diff --git a/tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java index 618574cdda..c1a7d05546 100644 --- a/tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java @@ -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; @@ -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; @@ -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; @@ -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); + } } -- 2.11.0