Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aaac61eb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "If zen settings are updated, don't show onboarding" into pi-dev

parents a1be4c08 8aef786b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -156,6 +156,12 @@ public class ZenOnboardingActivity extends Activity {
        // ZEN_SETTINGS_UPDATED is true for:
        // - fresh P+ device
        // - if zen visual effects values were changed by the user in Settings
        NotificationManager nm = context.getSystemService(NotificationManager.class);
        if (NotificationManager.Policy.areAllVisualEffectsSuppressed(
                nm.getNotificationPolicy().suppressedVisualEffects)) {
            Settings.Global.putInt(context.getContentResolver(),
                    Settings.Global.ZEN_SETTINGS_UPDATED, 1);
        }
        return Settings.Global.getInt(context.getContentResolver(),
                Settings.Global.ZEN_SETTINGS_UPDATED, 0) != 0;
    }
+32 −4
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;

@RunWith(SettingsRobolectricTestRunner.class)
public class ZenOnboardingActivityTest {
@@ -68,6 +69,8 @@ public class ZenOnboardingActivityTest {
    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        ShadowApplication shadowApplication = ShadowApplication.getInstance();
        shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);

        mActivity = Robolectric.buildActivity(ZenOnboardingActivity.class)
                .create()
@@ -124,6 +127,9 @@ public class ZenOnboardingActivityTest {

    @Test
    public void isSuggestionComplete_zenUpdated() {
        Policy policy = new Policy(0, 0, 0, 0);
        when(mNm.getNotificationPolicy()).thenReturn(policy);

        setZenUpdated(true);
        setShowSettingsSuggestion(false);
        setWithinTimeThreshold(true);
@@ -132,6 +138,9 @@ public class ZenOnboardingActivityTest {

    @Test
    public void isSuggestionComplete_withinTimeThreshold() {
        Policy policy = new Policy(0, 0, 0, 0);
        when(mNm.getNotificationPolicy()).thenReturn(policy);

        setZenUpdated(false);
        setShowSettingsSuggestion(false);
        setWithinTimeThreshold(true);
@@ -140,6 +149,9 @@ public class ZenOnboardingActivityTest {

    @Test
    public void isSuggestionComplete_showSettingsSuggestionTrue() {
        Policy policy = new Policy(0, 0, 0, 0);
        when(mNm.getNotificationPolicy()).thenReturn(policy);

        setZenUpdated(false);
        setShowSettingsSuggestion(true);
        setWithinTimeThreshold(false);
@@ -148,18 +160,34 @@ public class ZenOnboardingActivityTest {

    @Test
    public void isSuggestionComplete_showSettingsSuggestionFalse_notWithinTimeThreshold() {
        Policy policy = new Policy(0, 0, 0, 0);
        when(mNm.getNotificationPolicy()).thenReturn(policy);

        setZenUpdated(false);
        setShowSettingsSuggestion(false);
        setWithinTimeThreshold(false);
        assertThat(isSuggestionComplete(mContext)).isTrue();
    }

    private void setZenUpdated(boolean updated) {
        int zenUpdated = 0;
        if (updated) {
            zenUpdated = 1;

    @Test
    public void isSuggestionComplete_visualEffectsUpdated() {
        // all values suppressed
        Policy policy = new Policy(0, 0, 0, 511);
        when(mNm.getNotificationPolicy()).thenReturn(policy);

        setZenUpdated(false);
        setShowSettingsSuggestion(true);
        setWithinTimeThreshold(true);
        assertThat(isSuggestionComplete(mContext)).isTrue();
        assertThat(Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.ZEN_SETTINGS_UPDATED, -1)).isEqualTo(1);
    }


    private void setZenUpdated(boolean updated) {
        int zenUpdated = updated ? 1 : 0;

        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.ZEN_SETTINGS_UPDATED, zenUpdated);
    }