Loading services/core/java/com/android/server/notification/NotificationManagerService.java +12 −4 Original line number Diff line number Diff line Loading @@ -4106,11 +4106,19 @@ public class NotificationManagerService extends SystemService { if (r == null) { return; } if (mAssistants.isAdjustmentAllowed(adjustment.getKey())) { if (adjustment.getSignals() != null) { Bundle.setDefusable(adjustment.getSignals(), true); r.addAdjustment(adjustment); final Bundle adjustments = adjustment.getSignals(); Bundle.setDefusable(adjustments, true); List<String> toRemove = new ArrayList<>(); for (String potentialKey : adjustments.keySet()) { if (!mAssistants.isAdjustmentAllowed(potentialKey)) { toRemove.add(potentialKey); } } for (String removeKey : toRemove) { adjustments.remove(removeKey); } r.addAdjustment(adjustment); } } Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +39 −16 Original line number Diff line number Diff line Loading @@ -40,6 +40,8 @@ import static android.content.pm.PackageManager.PERMISSION_DENIED; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.Build.VERSION_CODES.O_MR1; import static android.os.Build.VERSION_CODES.P; import static android.service.notification.Adjustment.KEY_IMPORTANCE; import static android.service.notification.Adjustment.KEY_USER_SENTIMENT; import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE; import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL; Loading Loading @@ -492,6 +494,19 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { return answers; } private void clearDeviceConfig() { DeviceConfig.resetToDefaults( Settings.RESET_MODE_PACKAGE_DEFAULTS, DeviceConfig.NAMESPACE_SYSTEMUI); } private void setDefaultAssistantInDeviceConfig(String componentName) { DeviceConfig.setProperty( DeviceConfig.NAMESPACE_SYSTEMUI, SystemUiDeviceConfigFlags.NAS_DEFAULT_SERVICE, componentName, false); } @Test public void testCreateNotificationChannels_SingleChannel() throws Exception { final NotificationChannel channel = Loading Loading @@ -831,7 +846,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addEnqueuedNotification(r); Bundle bundle = new Bundle(); bundle.putInt(Adjustment.KEY_IMPORTANCE, IMPORTANCE_NONE); bundle.putInt(KEY_IMPORTANCE, IMPORTANCE_NONE); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), bundle, "", r.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); Loading Loading @@ -2826,7 +2841,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.setHandler(handler); Bundle signals = new Bundle(); signals.putInt(Adjustment.KEY_IMPORTANCE, IMPORTANCE_NONE); signals.putInt(KEY_IMPORTANCE, IMPORTANCE_NONE); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true); Loading Loading @@ -2867,7 +2882,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mAssistants.isSameUser(eq(null), anyInt())).thenReturn(true); Bundle signals = new Bundle(); signals.putInt(Adjustment.KEY_IMPORTANCE, IMPORTANCE_LOW); signals.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); Loading @@ -2885,13 +2900,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mAssistants.isSameUser(eq(null), anyInt())).thenReturn(true); Bundle signals = new Bundle(); signals.putInt(Adjustment.KEY_IMPORTANCE, IMPORTANCE_LOW); signals.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); assertEquals(IMPORTANCE_DEFAULT, r.getImportance()); assertFalse(r.hasAdjustment(Adjustment.KEY_IMPORTANCE)); assertFalse(r.hasAdjustment(KEY_IMPORTANCE)); } @Test Loading Loading @@ -4275,18 +4290,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .onGranted(eq(xmlConfig), eq(0), eq(true)); } private void clearDeviceConfig() { DeviceConfig.resetToDefaults( Settings.RESET_MODE_PACKAGE_DEFAULTS, DeviceConfig.NAMESPACE_SYSTEMUI); } private void setDefaultAssistantInDeviceConfig(String componentName) { DeviceConfig.setProperty( DeviceConfig.NAMESPACE_SYSTEMUI, SystemUiDeviceConfigFlags.NAS_DEFAULT_SERVICE, componentName, false); } public void testGetAllowedAssistantCapabilities() throws Exception { List<String> capabilities = mBinderService.getAllowedAssistantCapabilities(null); Loading @@ -4301,4 +4305,23 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertFalse(currentCapabilities.contains(capability)); } } public void testAdjustRestrictedKey() throws Exception { NotificationRecord r = generateNotificationRecord(mTestNotificationChannel); when(mAssistants.isAdjustmentAllowed(KEY_IMPORTANCE)).thenReturn(true); when(mAssistants.isAdjustmentAllowed(KEY_USER_SENTIMENT)).thenReturn(false); Bundle signals = new Bundle(); signals.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); signals.putInt(KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE); Adjustment adjustment = new Adjustment(r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); mBinderService.applyAdjustmentFromAssistant(null, adjustment); r.applyAdjustments(); assertEquals(IMPORTANCE_LOW, r.getAssistantImportance()); assertEquals(USER_SENTIMENT_NEUTRAL, r.getUserSentiment()); } } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +12 −4 Original line number Diff line number Diff line Loading @@ -4106,11 +4106,19 @@ public class NotificationManagerService extends SystemService { if (r == null) { return; } if (mAssistants.isAdjustmentAllowed(adjustment.getKey())) { if (adjustment.getSignals() != null) { Bundle.setDefusable(adjustment.getSignals(), true); r.addAdjustment(adjustment); final Bundle adjustments = adjustment.getSignals(); Bundle.setDefusable(adjustments, true); List<String> toRemove = new ArrayList<>(); for (String potentialKey : adjustments.keySet()) { if (!mAssistants.isAdjustmentAllowed(potentialKey)) { toRemove.add(potentialKey); } } for (String removeKey : toRemove) { adjustments.remove(removeKey); } r.addAdjustment(adjustment); } } Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +39 −16 Original line number Diff line number Diff line Loading @@ -40,6 +40,8 @@ import static android.content.pm.PackageManager.PERMISSION_DENIED; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.Build.VERSION_CODES.O_MR1; import static android.os.Build.VERSION_CODES.P; import static android.service.notification.Adjustment.KEY_IMPORTANCE; import static android.service.notification.Adjustment.KEY_USER_SENTIMENT; import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE; import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL; Loading Loading @@ -492,6 +494,19 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { return answers; } private void clearDeviceConfig() { DeviceConfig.resetToDefaults( Settings.RESET_MODE_PACKAGE_DEFAULTS, DeviceConfig.NAMESPACE_SYSTEMUI); } private void setDefaultAssistantInDeviceConfig(String componentName) { DeviceConfig.setProperty( DeviceConfig.NAMESPACE_SYSTEMUI, SystemUiDeviceConfigFlags.NAS_DEFAULT_SERVICE, componentName, false); } @Test public void testCreateNotificationChannels_SingleChannel() throws Exception { final NotificationChannel channel = Loading Loading @@ -831,7 +846,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addEnqueuedNotification(r); Bundle bundle = new Bundle(); bundle.putInt(Adjustment.KEY_IMPORTANCE, IMPORTANCE_NONE); bundle.putInt(KEY_IMPORTANCE, IMPORTANCE_NONE); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), bundle, "", r.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); Loading Loading @@ -2826,7 +2841,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.setHandler(handler); Bundle signals = new Bundle(); signals.putInt(Adjustment.KEY_IMPORTANCE, IMPORTANCE_NONE); signals.putInt(KEY_IMPORTANCE, IMPORTANCE_NONE); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true); Loading Loading @@ -2867,7 +2882,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mAssistants.isSameUser(eq(null), anyInt())).thenReturn(true); Bundle signals = new Bundle(); signals.putInt(Adjustment.KEY_IMPORTANCE, IMPORTANCE_LOW); signals.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); Loading @@ -2885,13 +2900,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mAssistants.isSameUser(eq(null), anyInt())).thenReturn(true); Bundle signals = new Bundle(); signals.putInt(Adjustment.KEY_IMPORTANCE, IMPORTANCE_LOW); signals.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); Adjustment adjustment = new Adjustment( r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment); assertEquals(IMPORTANCE_DEFAULT, r.getImportance()); assertFalse(r.hasAdjustment(Adjustment.KEY_IMPORTANCE)); assertFalse(r.hasAdjustment(KEY_IMPORTANCE)); } @Test Loading Loading @@ -4275,18 +4290,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .onGranted(eq(xmlConfig), eq(0), eq(true)); } private void clearDeviceConfig() { DeviceConfig.resetToDefaults( Settings.RESET_MODE_PACKAGE_DEFAULTS, DeviceConfig.NAMESPACE_SYSTEMUI); } private void setDefaultAssistantInDeviceConfig(String componentName) { DeviceConfig.setProperty( DeviceConfig.NAMESPACE_SYSTEMUI, SystemUiDeviceConfigFlags.NAS_DEFAULT_SERVICE, componentName, false); } public void testGetAllowedAssistantCapabilities() throws Exception { List<String> capabilities = mBinderService.getAllowedAssistantCapabilities(null); Loading @@ -4301,4 +4305,23 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertFalse(currentCapabilities.contains(capability)); } } public void testAdjustRestrictedKey() throws Exception { NotificationRecord r = generateNotificationRecord(mTestNotificationChannel); when(mAssistants.isAdjustmentAllowed(KEY_IMPORTANCE)).thenReturn(true); when(mAssistants.isAdjustmentAllowed(KEY_USER_SENTIMENT)).thenReturn(false); Bundle signals = new Bundle(); signals.putInt(KEY_IMPORTANCE, IMPORTANCE_LOW); signals.putInt(KEY_USER_SENTIMENT, USER_SENTIMENT_NEGATIVE); Adjustment adjustment = new Adjustment(r.sbn.getPackageName(), r.getKey(), signals, "", r.getUser().getIdentifier()); mBinderService.applyAdjustmentFromAssistant(null, adjustment); r.applyAdjustments(); assertEquals(IMPORTANCE_LOW, r.getAssistantImportance()); assertEquals(USER_SENTIMENT_NEUTRAL, r.getUserSentiment()); } }