Loading services/core/java/com/android/server/notification/NotificationManagerService.java +2 −2 Original line number Diff line number Diff line Loading @@ -10429,10 +10429,10 @@ public class NotificationManagerService extends SystemService { boolean isPrimary, boolean enabled, boolean userSet) { super.setPackageOrComponentEnabled(pkgOrComponent, userId, isPrimary, enabled, userSet); getContext().sendBroadcastAsUser( mContext.sendBroadcastAsUser( new Intent(ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED) .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.ALL, null); UserHandle.of(userId), null); } @Override Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationListenersTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -27,8 +27,13 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.INotificationManager; Loading @@ -38,8 +43,10 @@ import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; import android.content.pm.VersionedPackage; import android.os.Bundle; import android.os.UserHandle; import android.service.notification.NotificationListenerFilter; import android.service.notification.NotificationListenerService; import android.testing.TestableContext; import android.util.ArraySet; import android.util.Pair; import android.util.TypedXmlPullParser; Loading Loading @@ -69,6 +76,7 @@ public class NotificationListenersTest extends UiServiceTestCase { NotificationManagerService mNm; @Mock private INotificationManager mINm; private TestableContext mContext = spy(getContext()); NotificationManagerService.NotificationListeners mListeners; Loading @@ -80,6 +88,7 @@ public class NotificationListenersTest extends UiServiceTestCase { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); getContext().setMockPackageManager(mPm); doNothing().when(mContext).sendBroadcastAsUser(any(), any(), any()); mListeners = spy(mNm.new NotificationListeners( mContext, new Object(), mock(ManagedServices.UserProfiles.class), miPm)); Loading Loading @@ -370,4 +379,13 @@ public class NotificationListenersTest extends UiServiceTestCase { assertFalse(mListeners.hasAllowedListener(mCn2.getPackageName(), uid1)); assertFalse(mListeners.hasAllowedListener(mCn2.getPackageName(), uid2)); } @Test public void testBroadcastUsers() { int userId = 0; mListeners.setPackageOrComponentEnabled(mCn1.flattenToString(), userId, true, false, true); verify(mContext).sendBroadcastAsUser( any(), eq(UserHandle.of(userId)), nullable(String.class)); } } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +2 −2 Original line number Diff line number Diff line Loading @@ -10429,10 +10429,10 @@ public class NotificationManagerService extends SystemService { boolean isPrimary, boolean enabled, boolean userSet) { super.setPackageOrComponentEnabled(pkgOrComponent, userId, isPrimary, enabled, userSet); getContext().sendBroadcastAsUser( mContext.sendBroadcastAsUser( new Intent(ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED) .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY), UserHandle.ALL, null); UserHandle.of(userId), null); } @Override Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationListenersTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -27,8 +27,13 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.INotificationManager; Loading @@ -38,8 +43,10 @@ import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; import android.content.pm.VersionedPackage; import android.os.Bundle; import android.os.UserHandle; import android.service.notification.NotificationListenerFilter; import android.service.notification.NotificationListenerService; import android.testing.TestableContext; import android.util.ArraySet; import android.util.Pair; import android.util.TypedXmlPullParser; Loading Loading @@ -69,6 +76,7 @@ public class NotificationListenersTest extends UiServiceTestCase { NotificationManagerService mNm; @Mock private INotificationManager mINm; private TestableContext mContext = spy(getContext()); NotificationManagerService.NotificationListeners mListeners; Loading @@ -80,6 +88,7 @@ public class NotificationListenersTest extends UiServiceTestCase { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); getContext().setMockPackageManager(mPm); doNothing().when(mContext).sendBroadcastAsUser(any(), any(), any()); mListeners = spy(mNm.new NotificationListeners( mContext, new Object(), mock(ManagedServices.UserProfiles.class), miPm)); Loading Loading @@ -370,4 +379,13 @@ public class NotificationListenersTest extends UiServiceTestCase { assertFalse(mListeners.hasAllowedListener(mCn2.getPackageName(), uid1)); assertFalse(mListeners.hasAllowedListener(mCn2.getPackageName(), uid2)); } @Test public void testBroadcastUsers() { int userId = 0; mListeners.setPackageOrComponentEnabled(mCn1.flattenToString(), userId, true, false, true); verify(mContext).sendBroadcastAsUser( any(), eq(UserHandle.of(userId)), nullable(String.class)); } }