Merge "If zen settings are updated, don't show onboarding" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
aaac61eb5e
@@ -156,6 +156,12 @@ public class ZenOnboardingActivity extends Activity {
|
|||||||
// ZEN_SETTINGS_UPDATED is true for:
|
// ZEN_SETTINGS_UPDATED is true for:
|
||||||
// - fresh P+ device
|
// - fresh P+ device
|
||||||
// - if zen visual effects values were changed by the user in Settings
|
// - 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(),
|
return Settings.Global.getInt(context.getContentResolver(),
|
||||||
Settings.Global.ZEN_SETTINGS_UPDATED, 0) != 0;
|
Settings.Global.ZEN_SETTINGS_UPDATED, 0) != 0;
|
||||||
}
|
}
|
||||||
|
@@ -51,6 +51,7 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.Robolectric;
|
import org.robolectric.Robolectric;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
public class ZenOnboardingActivityTest {
|
public class ZenOnboardingActivityTest {
|
||||||
@@ -68,6 +69,8 @@ public class ZenOnboardingActivityTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||||
|
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
||||||
|
|
||||||
mActivity = Robolectric.buildActivity(ZenOnboardingActivity.class)
|
mActivity = Robolectric.buildActivity(ZenOnboardingActivity.class)
|
||||||
.create()
|
.create()
|
||||||
@@ -124,6 +127,9 @@ public class ZenOnboardingActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSuggestionComplete_zenUpdated() {
|
public void isSuggestionComplete_zenUpdated() {
|
||||||
|
Policy policy = new Policy(0, 0, 0, 0);
|
||||||
|
when(mNm.getNotificationPolicy()).thenReturn(policy);
|
||||||
|
|
||||||
setZenUpdated(true);
|
setZenUpdated(true);
|
||||||
setShowSettingsSuggestion(false);
|
setShowSettingsSuggestion(false);
|
||||||
setWithinTimeThreshold(true);
|
setWithinTimeThreshold(true);
|
||||||
@@ -132,6 +138,9 @@ public class ZenOnboardingActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSuggestionComplete_withinTimeThreshold() {
|
public void isSuggestionComplete_withinTimeThreshold() {
|
||||||
|
Policy policy = new Policy(0, 0, 0, 0);
|
||||||
|
when(mNm.getNotificationPolicy()).thenReturn(policy);
|
||||||
|
|
||||||
setZenUpdated(false);
|
setZenUpdated(false);
|
||||||
setShowSettingsSuggestion(false);
|
setShowSettingsSuggestion(false);
|
||||||
setWithinTimeThreshold(true);
|
setWithinTimeThreshold(true);
|
||||||
@@ -140,6 +149,9 @@ public class ZenOnboardingActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSuggestionComplete_showSettingsSuggestionTrue() {
|
public void isSuggestionComplete_showSettingsSuggestionTrue() {
|
||||||
|
Policy policy = new Policy(0, 0, 0, 0);
|
||||||
|
when(mNm.getNotificationPolicy()).thenReturn(policy);
|
||||||
|
|
||||||
setZenUpdated(false);
|
setZenUpdated(false);
|
||||||
setShowSettingsSuggestion(true);
|
setShowSettingsSuggestion(true);
|
||||||
setWithinTimeThreshold(false);
|
setWithinTimeThreshold(false);
|
||||||
@@ -148,17 +160,33 @@ public class ZenOnboardingActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSuggestionComplete_showSettingsSuggestionFalse_notWithinTimeThreshold() {
|
public void isSuggestionComplete_showSettingsSuggestionFalse_notWithinTimeThreshold() {
|
||||||
|
Policy policy = new Policy(0, 0, 0, 0);
|
||||||
|
when(mNm.getNotificationPolicy()).thenReturn(policy);
|
||||||
|
|
||||||
setZenUpdated(false);
|
setZenUpdated(false);
|
||||||
setShowSettingsSuggestion(false);
|
setShowSettingsSuggestion(false);
|
||||||
setWithinTimeThreshold(false);
|
setWithinTimeThreshold(false);
|
||||||
assertThat(isSuggestionComplete(mContext)).isTrue();
|
assertThat(isSuggestionComplete(mContext)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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) {
|
private void setZenUpdated(boolean updated) {
|
||||||
int zenUpdated = 0;
|
int zenUpdated = updated ? 1 : 0;
|
||||||
if (updated) {
|
|
||||||
zenUpdated = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Settings.Global.ZEN_SETTINGS_UPDATED, zenUpdated);
|
Settings.Global.ZEN_SETTINGS_UPDATED, zenUpdated);
|
||||||
|
Reference in New Issue
Block a user