diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java index 4cc379e987a56..e285b1c771221 100644 --- a/core/java/android/service/notification/ZenModeConfig.java +++ b/core/java/android/service/notification/ZenModeConfig.java @@ -777,6 +777,8 @@ public class ZenModeConfig implements Parcelable { final int calls = safeInt(parser, ALLOW_ATT_CALLS_FROM, ZenPolicy.PEOPLE_TYPE_UNSET); final int messages = safeInt(parser, ALLOW_ATT_MESSAGES_FROM, ZenPolicy.PEOPLE_TYPE_UNSET); final int repeatCallers = safeInt(parser, ALLOW_ATT_REPEAT_CALLERS, ZenPolicy.STATE_UNSET); + final int conversations = safeInt(parser, ALLOW_ATT_CONV_FROM, + ZenPolicy.CONVERSATION_SENDERS_UNSET); final int alarms = safeInt(parser, ALLOW_ATT_ALARMS, ZenPolicy.STATE_UNSET); final int media = safeInt(parser, ALLOW_ATT_MEDIA, ZenPolicy.STATE_UNSET); final int system = safeInt(parser, ALLOW_ATT_SYSTEM, ZenPolicy.STATE_UNSET); @@ -795,6 +797,10 @@ public class ZenModeConfig implements Parcelable { builder.allowRepeatCallers(repeatCallers == ZenPolicy.STATE_ALLOW); policySet = true; } + if (conversations != ZenPolicy.CONVERSATION_SENDERS_UNSET) { + builder.allowConversations(conversations); + policySet = true; + } if (alarms != ZenPolicy.STATE_UNSET) { builder.allowAlarms(alarms == ZenPolicy.STATE_ALLOW); policySet = true; @@ -870,6 +876,7 @@ public class ZenModeConfig implements Parcelable { writeZenPolicyState(ALLOW_ATT_MESSAGES_FROM, policy.getPriorityMessageSenders(), out); writeZenPolicyState(ALLOW_ATT_REPEAT_CALLERS, policy.getPriorityCategoryRepeatCallers(), out); + writeZenPolicyState(ALLOW_ATT_CONV_FROM, policy.getPriorityConversationSenders(), out); writeZenPolicyState(ALLOW_ATT_ALARMS, policy.getPriorityCategoryAlarms(), out); writeZenPolicyState(ALLOW_ATT_MEDIA, policy.getPriorityCategoryMedia(), out); writeZenPolicyState(ALLOW_ATT_SYSTEM, policy.getPriorityCategorySystem(), out); @@ -894,6 +901,10 @@ public class ZenModeConfig implements Parcelable { if (val != ZenPolicy.PEOPLE_TYPE_UNSET) { out.attributeInt(null, attr, val); } + } else if (Objects.equals(attr, ALLOW_ATT_CONV_FROM)) { + if (val != ZenPolicy.CONVERSATION_SENDERS_UNSET) { + out.attributeInt(null, attr, val); + } } else { if (val != ZenPolicy.STATE_UNSET) { out.attributeInt(null, attr, val); diff --git a/core/java/android/service/notification/ZenPolicy.java b/core/java/android/service/notification/ZenPolicy.java index a04f07380ce87..a892570f589c1 100644 --- a/core/java/android/service/notification/ZenPolicy.java +++ b/core/java/android/service/notification/ZenPolicy.java @@ -498,11 +498,11 @@ public final class ZenPolicy implements Parcelable { mZenPolicy.mPriorityCategories.set(category, STATE_UNSET); if (category == PRIORITY_CATEGORY_MESSAGES) { - mZenPolicy.mPriorityMessages = STATE_UNSET; + mZenPolicy.mPriorityMessages = PEOPLE_TYPE_UNSET; } else if (category == PRIORITY_CATEGORY_CALLS) { - mZenPolicy.mPriorityCalls = STATE_UNSET; + mZenPolicy.mPriorityCalls = PEOPLE_TYPE_UNSET; } else if (category == PRIORITY_CATEGORY_CONVERSATIONS) { - mZenPolicy.mConversationSenders = STATE_UNSET; + mZenPolicy.mConversationSenders = CONVERSATION_SENDERS_UNSET; } return this; diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java index 9dca23566b98e..949455a18570e 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java @@ -20,6 +20,7 @@ import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_IMPORT import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertNotNull; import static junit.framework.TestCase.assertNull; import static junit.framework.TestCase.assertTrue; @@ -311,6 +312,92 @@ public class ZenModeConfigTest extends UiServiceTestCase { assertTrue(fromXml.isAutomaticActive()); } + @Test + public void testZenPolicyXml_allUnset() throws Exception { + String tag = "tag"; + + ZenPolicy policy = new ZenPolicy.Builder().build(); + + TypedXmlSerializer out = Xml.newFastSerializer(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + out.setOutput(new BufferedOutputStream(baos), "utf-8"); + out.startDocument(null, true); + out.startTag(null, tag); + ZenModeConfig.writeZenPolicyXml(policy, out); + out.endTag(null, tag); + out.endDocument(); + + TypedXmlPullParser parser = Xml.newFastPullParser(); + parser.setInput(new BufferedInputStream( + new ByteArrayInputStream(baos.toByteArray())), null); + parser.nextTag(); + ZenPolicy fromXml = ZenModeConfig.readZenPolicyXml(parser); + + // nothing was set, so we should have nothing from the parser + assertNull(fromXml); + } + + @Test + public void testZenPolicyXml() throws Exception { + String tag = "tag"; + + ZenPolicy policy = new ZenPolicy.Builder() + .allowCalls(ZenPolicy.PEOPLE_TYPE_CONTACTS) + .allowMessages(ZenPolicy.PEOPLE_TYPE_NONE) + .allowConversations(ZenPolicy.CONVERSATION_SENDERS_IMPORTANT) + .allowRepeatCallers(true) + .allowAlarms(true) + .allowMedia(false) + .allowSystem(true) + .allowReminders(false) + .allowEvents(true) + .hideAllVisualEffects() + .showVisualEffect(ZenPolicy.VISUAL_EFFECT_AMBIENT, true) + .build(); + + TypedXmlSerializer out = Xml.newFastSerializer(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + out.setOutput(new BufferedOutputStream(baos), "utf-8"); + out.startDocument(null, true); + out.startTag(null, tag); + ZenModeConfig.writeZenPolicyXml(policy, out); + out.endTag(null, tag); + out.endDocument(); + + TypedXmlPullParser parser = Xml.newFastPullParser(); + parser.setInput(new BufferedInputStream( + new ByteArrayInputStream(baos.toByteArray())), null); + parser.nextTag(); + ZenPolicy fromXml = ZenModeConfig.readZenPolicyXml(parser); + + assertNotNull(fromXml); + assertEquals(policy.getPriorityCategoryCalls(), fromXml.getPriorityCategoryCalls()); + assertEquals(policy.getPriorityCallSenders(), fromXml.getPriorityCallSenders()); + assertEquals(policy.getPriorityCategoryMessages(), fromXml.getPriorityCategoryMessages()); + assertEquals(policy.getPriorityMessageSenders(), fromXml.getPriorityMessageSenders()); + assertEquals(policy.getPriorityCategoryConversations(), + fromXml.getPriorityCategoryConversations()); + assertEquals(policy.getPriorityConversationSenders(), + fromXml.getPriorityConversationSenders()); + assertEquals(policy.getPriorityCategoryRepeatCallers(), + fromXml.getPriorityCategoryRepeatCallers()); + assertEquals(policy.getPriorityCategoryAlarms(), fromXml.getPriorityCategoryAlarms()); + assertEquals(policy.getPriorityCategoryMedia(), fromXml.getPriorityCategoryMedia()); + assertEquals(policy.getPriorityCategorySystem(), fromXml.getPriorityCategorySystem()); + assertEquals(policy.getPriorityCategoryReminders(), fromXml.getPriorityCategoryReminders()); + assertEquals(policy.getPriorityCategoryEvents(), fromXml.getPriorityCategoryEvents()); + + assertEquals(policy.getVisualEffectFullScreenIntent(), + fromXml.getVisualEffectFullScreenIntent()); + assertEquals(policy.getVisualEffectLights(), fromXml.getVisualEffectLights()); + assertEquals(policy.getVisualEffectPeek(), fromXml.getVisualEffectPeek()); + assertEquals(policy.getVisualEffectStatusBar(), fromXml.getVisualEffectStatusBar()); + assertEquals(policy.getVisualEffectBadge(), fromXml.getVisualEffectBadge()); + assertEquals(policy.getVisualEffectAmbient(), fromXml.getVisualEffectAmbient()); + assertEquals(policy.getVisualEffectNotificationList(), + fromXml.getVisualEffectNotificationList()); + } + private ZenModeConfig getMutedRingerConfig() { ZenModeConfig config = new ZenModeConfig(); // Allow alarms, media