Loading core/java/android/app/NotificationManager.java +6 −0 Original line number Diff line number Diff line Loading @@ -465,6 +465,12 @@ public class NotificationManager { */ public static final int BUBBLE_PREFERENCE_SELECTED = 2; /** * Maximum length of the component name of a registered NotificationListenerService. * @hide */ public static int MAX_SERVICE_COMPONENT_NAME_LENGTH = 500; @UnsupportedAppUsage private static INotificationManager sService; Loading services/core/java/com/android/server/notification/NotificationManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -4932,6 +4932,11 @@ public class NotificationManagerService extends SystemService { boolean granted) { Objects.requireNonNull(listener); checkCallerIsSystemOrShell(); if (granted && listener.flattenToString().length() > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) { throw new IllegalArgumentException( "Component name too long: " + listener.flattenToString()); } final long identity = Binder.clearCallingIdentity(); try { if (mAllowedManagedServicePackages.test( Loading services/core/java/com/android/server/vr/VrManagerService.java +5 −1 Original line number Diff line number Diff line Loading @@ -1045,7 +1045,11 @@ public class VrManagerService extends SystemService for (ComponentName c : possibleServices) { if (Objects.equals(c.getPackageName(), pkg)) { try { nm.setNotificationListenerAccessGrantedForUser(c, userId, true); } catch (Exception e) { Slog.w(TAG, "Could not grant NLS access to package " + pkg, e); } } } } Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -3143,6 +3143,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { any(), anyInt(), anyBoolean(), anyBoolean()); } @Test public void testSetListenerAccessForUser_grantWithNameTooLong_throws() throws Exception { UserHandle user = UserHandle.of(mContext.getUserId() + 10); ComponentName c = new ComponentName("com.example.package", com.google.common.base.Strings.repeat("Blah", 150)); try { mBinderService.setNotificationListenerAccessGrantedForUser(c, user.getIdentifier(), /* enabled= */ true); fail("Should've thrown IllegalArgumentException"); } catch (IllegalArgumentException e) { // Good! } } @Test public void testSetListenerAccessForUser_revokeWithNameTooLong_okay() throws Exception { UserHandle user = UserHandle.of(mContext.getUserId() + 10); ComponentName c = new ComponentName("com.example.package", com.google.common.base.Strings.repeat("Blah", 150)); mBinderService.setNotificationListenerAccessGrantedForUser( c, user.getIdentifier(), /* enabled= */ false); verify(mListeners).setPackageOrComponentEnabled( c.flattenToString(), user.getIdentifier(), true, /* enabled= */ false); } @Test public void testSetAssistantAccessForUser() throws Exception { UserHandle user = UserHandle.of(10); Loading Loading
core/java/android/app/NotificationManager.java +6 −0 Original line number Diff line number Diff line Loading @@ -465,6 +465,12 @@ public class NotificationManager { */ public static final int BUBBLE_PREFERENCE_SELECTED = 2; /** * Maximum length of the component name of a registered NotificationListenerService. * @hide */ public static int MAX_SERVICE_COMPONENT_NAME_LENGTH = 500; @UnsupportedAppUsage private static INotificationManager sService; Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -4932,6 +4932,11 @@ public class NotificationManagerService extends SystemService { boolean granted) { Objects.requireNonNull(listener); checkCallerIsSystemOrShell(); if (granted && listener.flattenToString().length() > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) { throw new IllegalArgumentException( "Component name too long: " + listener.flattenToString()); } final long identity = Binder.clearCallingIdentity(); try { if (mAllowedManagedServicePackages.test( Loading
services/core/java/com/android/server/vr/VrManagerService.java +5 −1 Original line number Diff line number Diff line Loading @@ -1045,7 +1045,11 @@ public class VrManagerService extends SystemService for (ComponentName c : possibleServices) { if (Objects.equals(c.getPackageName(), pkg)) { try { nm.setNotificationListenerAccessGrantedForUser(c, userId, true); } catch (Exception e) { Slog.w(TAG, "Could not grant NLS access to package " + pkg, e); } } } } Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -3143,6 +3143,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { any(), anyInt(), anyBoolean(), anyBoolean()); } @Test public void testSetListenerAccessForUser_grantWithNameTooLong_throws() throws Exception { UserHandle user = UserHandle.of(mContext.getUserId() + 10); ComponentName c = new ComponentName("com.example.package", com.google.common.base.Strings.repeat("Blah", 150)); try { mBinderService.setNotificationListenerAccessGrantedForUser(c, user.getIdentifier(), /* enabled= */ true); fail("Should've thrown IllegalArgumentException"); } catch (IllegalArgumentException e) { // Good! } } @Test public void testSetListenerAccessForUser_revokeWithNameTooLong_okay() throws Exception { UserHandle user = UserHandle.of(mContext.getUserId() + 10); ComponentName c = new ComponentName("com.example.package", com.google.common.base.Strings.repeat("Blah", 150)); mBinderService.setNotificationListenerAccessGrantedForUser( c, user.getIdentifier(), /* enabled= */ false); verify(mListeners).setPackageOrComponentEnabled( c.flattenToString(), user.getIdentifier(), true, /* enabled= */ false); } @Test public void testSetAssistantAccessForUser() throws Exception { UserHandle user = UserHandle.of(10); Loading