Loading services/core/java/com/android/server/notification/ZenModeHelper.java +3 −2 Original line number Diff line number Diff line Loading @@ -104,6 +104,7 @@ public class ZenModeHelper { // The amount of time rules instances can exist without their owning app being installed. private static final int RULE_INSTANCE_GRACE_PERIOD = 1000 * 60 * 60 * 72; static final int RULE_LIMIT_PER_PACKAGE = 100; // pkg|userId => uid protected final ArrayMap<String, Integer> mRulesUidCache = new ArrayMap<>(); Loading Loading @@ -325,10 +326,10 @@ public class ZenModeHelper { int newRuleInstanceCount = getCurrentInstanceCount(automaticZenRule.getOwner()) + getCurrentInstanceCount(automaticZenRule.getConfigurationActivity()) + 1; if (ruleInstanceLimit > 0 && ruleInstanceLimit < newRuleInstanceCount) { if (newRuleInstanceCount > RULE_LIMIT_PER_PACKAGE || (ruleInstanceLimit > 0 && ruleInstanceLimit < newRuleInstanceCount)) { throw new IllegalArgumentException("Rule instance limit exceeded"); } } ZenModeConfig newConfig; Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import static com.android.os.AtomsProto.DNDModeProto.ENABLED_FIELD_NUMBER; import static com.android.os.AtomsProto.DNDModeProto.ID_FIELD_NUMBER; import static com.android.os.AtomsProto.DNDModeProto.UID_FIELD_NUMBER; import static com.android.os.AtomsProto.DNDModeProto.ZEN_MODE_FIELD_NUMBER; import static com.android.server.notification.ZenModeHelper.RULE_LIMIT_PER_PACKAGE; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; Loading Loading @@ -1606,6 +1607,35 @@ public class ZenModeHelperTest extends UiServiceTestCase { assertFalse(Objects.equals(defaultRuleName, ruleAfterUpdating.name)); // update name } @Test public void testAddAutomaticZenRule_beyondSystemLimit() { for (int i = 0; i < RULE_LIMIT_PER_PACKAGE; i++) { ScheduleInfo si = new ScheduleInfo(); si.startHour = i; AutomaticZenRule zenRule = new AutomaticZenRule("name" + i, null, new ComponentName("android", "ScheduleConditionProvider"), ZenModeConfig.toScheduleConditionId(si), new ZenPolicy.Builder().build(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true); String id = mZenModeHelperSpy.addAutomaticZenRule("android", zenRule, "test"); assertNotNull(id); } try { AutomaticZenRule zenRule = new AutomaticZenRule("name", null, new ComponentName("android", "ScheduleConditionProvider"), ZenModeConfig.toScheduleConditionId(new ScheduleInfo()), new ZenPolicy.Builder().build(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true); String id = mZenModeHelperSpy.addAutomaticZenRule("android", zenRule, "test"); fail("allowed too many rules to be created"); } catch (IllegalArgumentException e) { // yay } } @Test public void testAddAutomaticZenRule_CA() { AutomaticZenRule zenRule = new AutomaticZenRule("name", Loading Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +3 −2 Original line number Diff line number Diff line Loading @@ -104,6 +104,7 @@ public class ZenModeHelper { // The amount of time rules instances can exist without their owning app being installed. private static final int RULE_INSTANCE_GRACE_PERIOD = 1000 * 60 * 60 * 72; static final int RULE_LIMIT_PER_PACKAGE = 100; // pkg|userId => uid protected final ArrayMap<String, Integer> mRulesUidCache = new ArrayMap<>(); Loading Loading @@ -325,10 +326,10 @@ public class ZenModeHelper { int newRuleInstanceCount = getCurrentInstanceCount(automaticZenRule.getOwner()) + getCurrentInstanceCount(automaticZenRule.getConfigurationActivity()) + 1; if (ruleInstanceLimit > 0 && ruleInstanceLimit < newRuleInstanceCount) { if (newRuleInstanceCount > RULE_LIMIT_PER_PACKAGE || (ruleInstanceLimit > 0 && ruleInstanceLimit < newRuleInstanceCount)) { throw new IllegalArgumentException("Rule instance limit exceeded"); } } ZenModeConfig newConfig; Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import static com.android.os.AtomsProto.DNDModeProto.ENABLED_FIELD_NUMBER; import static com.android.os.AtomsProto.DNDModeProto.ID_FIELD_NUMBER; import static com.android.os.AtomsProto.DNDModeProto.UID_FIELD_NUMBER; import static com.android.os.AtomsProto.DNDModeProto.ZEN_MODE_FIELD_NUMBER; import static com.android.server.notification.ZenModeHelper.RULE_LIMIT_PER_PACKAGE; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; Loading Loading @@ -1606,6 +1607,35 @@ public class ZenModeHelperTest extends UiServiceTestCase { assertFalse(Objects.equals(defaultRuleName, ruleAfterUpdating.name)); // update name } @Test public void testAddAutomaticZenRule_beyondSystemLimit() { for (int i = 0; i < RULE_LIMIT_PER_PACKAGE; i++) { ScheduleInfo si = new ScheduleInfo(); si.startHour = i; AutomaticZenRule zenRule = new AutomaticZenRule("name" + i, null, new ComponentName("android", "ScheduleConditionProvider"), ZenModeConfig.toScheduleConditionId(si), new ZenPolicy.Builder().build(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true); String id = mZenModeHelperSpy.addAutomaticZenRule("android", zenRule, "test"); assertNotNull(id); } try { AutomaticZenRule zenRule = new AutomaticZenRule("name", null, new ComponentName("android", "ScheduleConditionProvider"), ZenModeConfig.toScheduleConditionId(new ScheduleInfo()), new ZenPolicy.Builder().build(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true); String id = mZenModeHelperSpy.addAutomaticZenRule("android", zenRule, "test"); fail("allowed too many rules to be created"); } catch (IllegalArgumentException e) { // yay } } @Test public void testAddAutomaticZenRule_CA() { AutomaticZenRule zenRule = new AutomaticZenRule("name", Loading