Loading services/core/java/com/android/server/notification/ZenModeHelper.java +6 −1 Original line number Diff line number Diff line Loading @@ -291,7 +291,7 @@ public class ZenModeHelper { public String addAutomaticZenRule(String pkg, AutomaticZenRule automaticZenRule, String reason) { if (!ZenModeConfig.SYSTEM_AUTHORITY.equals(pkg)) { if (!isSystemRule(automaticZenRule)) { PackageItemInfo component = getServiceInfo(automaticZenRule.getOwner()); if (component == null) { component = getActivityInfo(automaticZenRule.getConfigurationActivity()); Loading Loading @@ -532,6 +532,11 @@ public class ZenModeHelper { } } private boolean isSystemRule(AutomaticZenRule rule) { return rule.getOwner() != null && ZenModeConfig.SYSTEM_AUTHORITY.equals(rule.getOwner().getPackageName()); } private ServiceInfo getServiceInfo(ComponentName owner) { Intent queryIntent = new Intent(); queryIntent.setComponent(owner); Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +0 −30 Original line number Diff line number Diff line Loading @@ -1426,36 +1426,6 @@ public class ZenModeHelperTest extends UiServiceTestCase { } } @Test public void testAddAutomaticZenRule_claimedSystemOwner() { // Make sure anything that claims to have a "system" owner but not actually part of the // system package still gets limited on number of rules for (int i = 0; i < RULE_LIMIT_PER_PACKAGE; i++) { ScheduleInfo si = new ScheduleInfo(); si.startHour = i; AutomaticZenRule zenRule = new AutomaticZenRule("name" + i, new ComponentName("android", "ScheduleConditionProvider" + i), null, // configuration activity ZenModeConfig.toScheduleConditionId(si), new ZenPolicy.Builder().build(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true); String id = mZenModeHelperSpy.addAutomaticZenRule("pkgname", zenRule, "test"); assertNotNull(id); } try { AutomaticZenRule zenRule = new AutomaticZenRule("name", new ComponentName("android", "ScheduleConditionProviderFinal"), null, // configuration activity ZenModeConfig.toScheduleConditionId(new ScheduleInfo()), new ZenPolicy.Builder().build(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true); String id = mZenModeHelperSpy.addAutomaticZenRule("pkgname", zenRule, "test"); fail("allowed too many rules to be created"); } catch (IllegalArgumentException e) { // yay } } private void setupZenConfig() { mZenModeHelperSpy.mZenMode = Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; mZenModeHelperSpy.mConfig.allowAlarms = false; Loading Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +6 −1 Original line number Diff line number Diff line Loading @@ -291,7 +291,7 @@ public class ZenModeHelper { public String addAutomaticZenRule(String pkg, AutomaticZenRule automaticZenRule, String reason) { if (!ZenModeConfig.SYSTEM_AUTHORITY.equals(pkg)) { if (!isSystemRule(automaticZenRule)) { PackageItemInfo component = getServiceInfo(automaticZenRule.getOwner()); if (component == null) { component = getActivityInfo(automaticZenRule.getConfigurationActivity()); Loading Loading @@ -532,6 +532,11 @@ public class ZenModeHelper { } } private boolean isSystemRule(AutomaticZenRule rule) { return rule.getOwner() != null && ZenModeConfig.SYSTEM_AUTHORITY.equals(rule.getOwner().getPackageName()); } private ServiceInfo getServiceInfo(ComponentName owner) { Intent queryIntent = new Intent(); queryIntent.setComponent(owner); Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +0 −30 Original line number Diff line number Diff line Loading @@ -1426,36 +1426,6 @@ public class ZenModeHelperTest extends UiServiceTestCase { } } @Test public void testAddAutomaticZenRule_claimedSystemOwner() { // Make sure anything that claims to have a "system" owner but not actually part of the // system package still gets limited on number of rules for (int i = 0; i < RULE_LIMIT_PER_PACKAGE; i++) { ScheduleInfo si = new ScheduleInfo(); si.startHour = i; AutomaticZenRule zenRule = new AutomaticZenRule("name" + i, new ComponentName("android", "ScheduleConditionProvider" + i), null, // configuration activity ZenModeConfig.toScheduleConditionId(si), new ZenPolicy.Builder().build(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true); String id = mZenModeHelperSpy.addAutomaticZenRule("pkgname", zenRule, "test"); assertNotNull(id); } try { AutomaticZenRule zenRule = new AutomaticZenRule("name", new ComponentName("android", "ScheduleConditionProviderFinal"), null, // configuration activity ZenModeConfig.toScheduleConditionId(new ScheduleInfo()), new ZenPolicy.Builder().build(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true); String id = mZenModeHelperSpy.addAutomaticZenRule("pkgname", zenRule, "test"); fail("allowed too many rules to be created"); } catch (IllegalArgumentException e) { // yay } } private void setupZenConfig() { mZenModeHelperSpy.mZenMode = Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; mZenModeHelperSpy.mConfig.allowAlarms = false; Loading