OSDN Git Service

Add ResultPayload for Allow notification dots
authorjackqdyulei <jackqdyulei@google.com>
Tue, 25 Jul 2017 01:34:33 +0000 (18:34 -0700)
committerjackqdyulei <jackqdyulei@google.com>
Thu, 27 Jul 2017 00:55:11 +0000 (17:55 -0700)
Bug: 62022517
Test: robotests
Change-Id: I86caa1c8604ae8eff27574ca45b5e9f3f6830f8f

src/com/android/settings/notification/BadgingNotificationPreferenceController.java
tests/robotests/src/com/android/settings/notification/BadgingNotificationPreferenceControllerTest.java

index 39522e8..94eccf9 100644 (file)
@@ -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 */);
+    }
 }
index 618574c..c1a7d05 100644 (file)
@@ -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);
+    }
 }