Loading core/java/android/app/NotificationManager.java +6 −0 Original line number Diff line number Diff line Loading @@ -562,6 +562,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 packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java +6 −2 Original line number Diff line number Diff line Loading @@ -243,7 +243,9 @@ public class RestrictedSwitchPreference extends SwitchPreference { return mHelper != null ? mHelper.packageName : null; } public void updateState(@NonNull String packageName, int uid, boolean isEnabled) { /** Updates enabled state based on associated package. */ public void updateState( @NonNull String packageName, int uid, boolean isEnableAllowed, boolean isEnabled) { mHelper.updatePackageDetails(packageName, uid); if (mAppOpsManager == null) { mAppOpsManager = getContext().getSystemService(AppOpsManager.class); Loading @@ -254,7 +256,9 @@ public class RestrictedSwitchPreference extends SwitchPreference { final boolean ecmEnabled = getContext().getResources().getBoolean( com.android.internal.R.bool.config_enhancedConfirmationModeEnabled); final boolean appOpsAllowed = !ecmEnabled || mode == AppOpsManager.MODE_ALLOWED; if (isEnabled) { if (!isEnableAllowed && !isEnabled) { setEnabled(false); } else if (isEnabled) { setEnabled(true); } else if (appOpsAllowed && isDisabledByAppOps()) { setEnabled(true); Loading services/core/java/com/android/server/notification/NotificationManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -5449,6 +5449,11 @@ public class NotificationManagerService extends SystemService { boolean granted, boolean userSet) { Objects.requireNonNull(listener); checkNotificationListenerAccess(); if (granted && listener.flattenToString().length() > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) { throw new IllegalArgumentException( "Component name too long: " + listener.flattenToString()); } if (!userSet && isNotificationListenerAccessUserSet(listener)) { // Don't override user's choice return; Loading services/core/java/com/android/server/vr/VrManagerService.java +5 −1 Original line number Diff line number Diff line Loading @@ -1049,7 +1049,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 +25 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.fail; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyLong; Loading Loading @@ -3724,6 +3725,30 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean()); } @Test public void testSetListenerAccessForUser_grantWithNameTooLong_throws() { UserHandle user = UserHandle.of(mContext.getUserId() + 10); ComponentName c = new ComponentName("com.example.package", com.google.common.base.Strings.repeat("Blah", 150)); assertThrows(IllegalArgumentException.class, () -> mBinderService.setNotificationListenerAccessGrantedForUser( c, user.getIdentifier(), /* enabled= */ true, true)); } @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, true); verify(mListeners).setPackageOrComponentEnabled( c.flattenToString(), user.getIdentifier(), true, /* enabled= */ false, true); } @Test public void testSetAssistantAccessForUser() throws Exception { UserInfo ui = new UserInfo(); Loading Loading
core/java/android/app/NotificationManager.java +6 −0 Original line number Diff line number Diff line Loading @@ -562,6 +562,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
packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java +6 −2 Original line number Diff line number Diff line Loading @@ -243,7 +243,9 @@ public class RestrictedSwitchPreference extends SwitchPreference { return mHelper != null ? mHelper.packageName : null; } public void updateState(@NonNull String packageName, int uid, boolean isEnabled) { /** Updates enabled state based on associated package. */ public void updateState( @NonNull String packageName, int uid, boolean isEnableAllowed, boolean isEnabled) { mHelper.updatePackageDetails(packageName, uid); if (mAppOpsManager == null) { mAppOpsManager = getContext().getSystemService(AppOpsManager.class); Loading @@ -254,7 +256,9 @@ public class RestrictedSwitchPreference extends SwitchPreference { final boolean ecmEnabled = getContext().getResources().getBoolean( com.android.internal.R.bool.config_enhancedConfirmationModeEnabled); final boolean appOpsAllowed = !ecmEnabled || mode == AppOpsManager.MODE_ALLOWED; if (isEnabled) { if (!isEnableAllowed && !isEnabled) { setEnabled(false); } else if (isEnabled) { setEnabled(true); } else if (appOpsAllowed && isDisabledByAppOps()) { setEnabled(true); Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -5449,6 +5449,11 @@ public class NotificationManagerService extends SystemService { boolean granted, boolean userSet) { Objects.requireNonNull(listener); checkNotificationListenerAccess(); if (granted && listener.flattenToString().length() > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) { throw new IllegalArgumentException( "Component name too long: " + listener.flattenToString()); } if (!userSet && isNotificationListenerAccessUserSet(listener)) { // Don't override user's choice return; Loading
services/core/java/com/android/server/vr/VrManagerService.java +5 −1 Original line number Diff line number Diff line Loading @@ -1049,7 +1049,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 +25 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.fail; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyLong; Loading Loading @@ -3724,6 +3725,30 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean()); } @Test public void testSetListenerAccessForUser_grantWithNameTooLong_throws() { UserHandle user = UserHandle.of(mContext.getUserId() + 10); ComponentName c = new ComponentName("com.example.package", com.google.common.base.Strings.repeat("Blah", 150)); assertThrows(IllegalArgumentException.class, () -> mBinderService.setNotificationListenerAccessGrantedForUser( c, user.getIdentifier(), /* enabled= */ true, true)); } @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, true); verify(mListeners).setPackageOrComponentEnabled( c.flattenToString(), user.getIdentifier(), true, /* enabled= */ false, true); } @Test public void testSetAssistantAccessForUser() throws Exception { UserInfo ui = new UserInfo(); Loading