diff options
3 files changed, 52 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/notification/ManagedServices.java b/services/core/java/com/android/server/notification/ManagedServices.java index 88d73fb10902..c222e6948a3d 100644 --- a/services/core/java/com/android/server/notification/ManagedServices.java +++ b/services/core/java/com/android/server/notification/ManagedServices.java @@ -767,6 +767,23 @@ abstract public class ManagedServices { return installed; } + protected Set<String> getAllowedPackages() { + final Set<String> allowedPackages = new ArraySet<>(); + for (int k = 0; k < mApproved.size(); k++) { + ArrayMap<Boolean, ArraySet<String>> allowedByType = mApproved.valueAt(k); + for (int i = 0; i < allowedByType.size(); i++) { + final ArraySet<String> allowed = allowedByType.valueAt(i); + for (int j = 0; j < allowed.size(); j++) { + String pkgName = getPackageName(allowed.valueAt(j)); + if (!TextUtils.isEmpty(pkgName)) { + allowedPackages.add(pkgName); + } + } + } + } + return allowedPackages; + } + private void trimApprovedListsAccordingToInstalledServices() { int N = mApproved.size(); for (int i = 0 ; i < N; i++) { diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 4f21db159625..c68e0f98325e 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1701,8 +1701,16 @@ public class NotificationManagerService extends SystemService { } private void sendRegisteredOnlyBroadcast(String action) { - getContext().sendBroadcastAsUser(new Intent(action) - .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.ALL, null); + Intent intent = new Intent(action); + getContext().sendBroadcastAsUser(intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), + UserHandle.ALL, null); + // explicitly send the broadcast to all DND packages, even if they aren't currently running + intent.setFlags(0); + final Set<String> dndApprovedPackages = mConditionProviders.getAllowedPackages(); + for (String pkg : dndApprovedPackages) { + intent.setPackage(pkg); + getContext().sendBroadcastAsUser(intent, UserHandle.ALL); + } } @Override diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java index 8b65e763b088..20f72bfe9938 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java @@ -613,7 +613,7 @@ public class ManagedServicesTest extends UiServiceTestCase { } @Test - public void testGetAllowedPackages() throws Exception { + public void testGetAllowedPackages_byUser() throws Exception { for (int approvalLevel : new int[] {APPROVAL_BY_COMPONENT, APPROVAL_BY_PACKAGE}) { ManagedServices service = new TestManagedServices(getContext(), mLock, mUserProfiles, mIpm, approvalLevel); @@ -681,6 +681,30 @@ public class ManagedServicesTest extends UiServiceTestCase { } @Test + public void testGetAllowedPackages() throws Exception { + ManagedServices service = new TestManagedServices(getContext(), mLock, mUserProfiles, + mIpm, APPROVAL_BY_COMPONENT); + loadXml(service); + service.mApprovalLevel = APPROVAL_BY_PACKAGE; + loadXml(service); + + List<String> allowedPackages = new ArrayList<>(); + allowedPackages.add("this.is.a.package.name"); + allowedPackages.add("another.package"); + allowedPackages.add("secondary"); + allowedPackages.add("this.is.another.package"); + allowedPackages.add("package"); + allowedPackages.add("component"); + allowedPackages.add("bananas!"); + + Set<String> actual = service.getAllowedPackages(); + assertEquals(allowedPackages.size(), actual.size()); + for (String pkg : allowedPackages) { + assertTrue(actual.contains(pkg)); + } + } + + @Test public void testOnUserRemoved() throws Exception { for (int approvalLevel : new int[] {APPROVAL_BY_COMPONENT, APPROVAL_BY_PACKAGE}) { ManagedServices service = new TestManagedServices(getContext(), mLock, mUserProfiles, |