Merge "Limit broadcast by user" into tm-dev am: 50c8a48d3a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17350684

Change-Id: I48c5f586fbe2ab27a2817fd56f19d96a4d0455da
This commit is contained in:
TreeHugger Robot
2022-03-24 16:03:53 +00:00
committed by Automerger Merge Worker
2 changed files with 20 additions and 2 deletions

View File

@@ -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

View File

@@ -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;
@@ -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;
@@ -69,6 +76,7 @@ public class NotificationListenersTest extends UiServiceTestCase {
NotificationManagerService mNm;
@Mock
private INotificationManager mINm;
private TestableContext mContext = spy(getContext());
NotificationManagerService.NotificationListeners mListeners;
@@ -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));
@@ -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));
}
}