Add ResultPayload for Allow notification dots

Bug: 62022517
Test: robotests
Change-Id: I86caa1c8604ae8eff27574ca45b5e9f3f6830f8f
Merged-In: I86caa1c8604ae8eff27574ca45b5e9f3f6830f8f
This commit is contained in:
jackqdyulei
2017-07-24 18:34:33 -07:00
parent 70f0013e43
commit c50495ba06
2 changed files with 58 additions and 4 deletions

View 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;
@@ -25,9 +26,12 @@ import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.TwoStatePreference;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
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;
@@ -39,7 +43,8 @@ public class BadgingNotificationPreferenceController extends PreferenceControlle
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;
@@ -84,7 +89,7 @@ public class BadgingNotificationPreferenceController extends PreferenceControlle
@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);
}
@@ -92,7 +97,7 @@ public class BadgingNotificationPreferenceController extends PreferenceControlle
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 {
@@ -123,4 +128,15 @@ public class BadgingNotificationPreferenceController extends PreferenceControlle
}
}
}
@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 */);
}
}

View 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);
}
}