Loading core/java/android/app/INotificationManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ interface INotificationManager boolean isInInvalidMsgState(String pkg, int uid); boolean hasUserDemotedInvalidMsgApp(String pkg, int uid); void setInvalidMsgAppDemoted(String pkg, int uid, boolean isDemoted); boolean hasSentValidBubble(String pkg, int uid); void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled); /** * Updates the notification's enabled state. Additionally locks importance for all of the Loading services/core/java/com/android/server/notification/NotificationManagerService.java +13 −0 Original line number Diff line number Diff line Loading @@ -3094,6 +3094,13 @@ public class NotificationManagerService extends SystemService { if (mPreferencesHelper.setValidMessageSent( r.getSbn().getPackageName(), r.getUid())) { handleSavePolicyFile(); } else if (r.getNotification().getBubbleMetadata() != null) { // If bubble metadata is present it is valid (if invalid it's removed // via BubbleExtractor). if (mPreferencesHelper.setValidBubbleSent( r.getSbn().getPackageName(), r.getUid())) { handleSavePolicyFile(); } } } else { if (mPreferencesHelper.setInvalidMessageSent( Loading Loading @@ -3596,6 +3603,12 @@ public class NotificationManagerService extends SystemService { handleSavePolicyFile(); } @Override public boolean hasSentValidBubble(String pkg, int uid) { checkCallerIsSystem(); return mPreferencesHelper.hasSentValidBubble(pkg, uid); } @Override public void setNotificationDelegate(String callingPkg, String delegate) { checkCallerIsSameApp(callingPkg); Loading services/core/java/com/android/server/notification/PreferencesHelper.java +19 −1 Original line number Diff line number Diff line Loading @@ -808,6 +808,23 @@ public class PreferencesHelper implements RankingConfig { } } /** Sets whether this package has sent a notification with valid bubble metadata. */ public boolean setValidBubbleSent(String packageName, int uid) { synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(packageName, uid); boolean valueChanged = !r.hasSentValidBubble; r.hasSentValidBubble = true; return valueChanged; } } boolean hasSentValidBubble(String packageName, int uid) { synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(packageName, uid); return r.hasSentValidBubble; } } @Override public boolean isGroupBlocked(String packageName, int uid, String groupId) { if (groupId == null) { Loading Loading @@ -2813,8 +2830,9 @@ public class PreferencesHelper implements RankingConfig { boolean hasSentInvalidMessage = false; boolean hasSentValidMessage = false; // notE: only valid while hasSentMessage is false and hasSentInvalidMessage is true // note: only valid while hasSentMessage is false and hasSentInvalidMessage is true boolean userDemotedMsgApp = false; boolean hasSentValidBubble = false; Delegate delegate = null; ArrayMap<String, NotificationChannel> channels = new ArrayMap<>(); Loading services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -542,6 +542,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.setInvalidMessageSent(PKG_P, UID_P); mHelper.setValidMessageSent(PKG_P, UID_P); mHelper.setInvalidMsgAppDemoted(PKG_P, UID_P, true); mHelper.setValidBubbleSent(PKG_P, UID_P); mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE); Loading @@ -561,6 +562,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertFalse(mHelper.hasSentInvalidMsg(PKG_N_MR1, UID_N_MR1)); assertTrue(mHelper.hasSentValidMsg(PKG_P, UID_P)); assertTrue(mHelper.didUserEverDemoteInvalidMsgApp(PKG_P, UID_P)); assertTrue(mHelper.hasSentValidBubble(PKG_P, UID_P)); assertEquals(channel1, mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1.getId(), false)); compareChannels(channel2, Loading Loading @@ -4926,6 +4928,18 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertFalse(mHelper.hasUserDemotedInvalidMsgApp(PKG_P, UID_P)); } @Test public void testValidBubbleSent() { // create package preferences mHelper.canShowBadge(PKG_P, UID_P); // false by default assertFalse(mHelper.hasSentValidBubble(PKG_P, UID_P)); // set something valid was sent mHelper.setValidBubbleSent(PKG_P, UID_P); assertTrue(mHelper.hasSentValidBubble(PKG_P, UID_P)); } @Test public void testPullPackageChannelPreferencesStats() { String channelId = "parent"; Loading Loading
core/java/android/app/INotificationManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ interface INotificationManager boolean isInInvalidMsgState(String pkg, int uid); boolean hasUserDemotedInvalidMsgApp(String pkg, int uid); void setInvalidMsgAppDemoted(String pkg, int uid, boolean isDemoted); boolean hasSentValidBubble(String pkg, int uid); void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled); /** * Updates the notification's enabled state. Additionally locks importance for all of the Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +13 −0 Original line number Diff line number Diff line Loading @@ -3094,6 +3094,13 @@ public class NotificationManagerService extends SystemService { if (mPreferencesHelper.setValidMessageSent( r.getSbn().getPackageName(), r.getUid())) { handleSavePolicyFile(); } else if (r.getNotification().getBubbleMetadata() != null) { // If bubble metadata is present it is valid (if invalid it's removed // via BubbleExtractor). if (mPreferencesHelper.setValidBubbleSent( r.getSbn().getPackageName(), r.getUid())) { handleSavePolicyFile(); } } } else { if (mPreferencesHelper.setInvalidMessageSent( Loading Loading @@ -3596,6 +3603,12 @@ public class NotificationManagerService extends SystemService { handleSavePolicyFile(); } @Override public boolean hasSentValidBubble(String pkg, int uid) { checkCallerIsSystem(); return mPreferencesHelper.hasSentValidBubble(pkg, uid); } @Override public void setNotificationDelegate(String callingPkg, String delegate) { checkCallerIsSameApp(callingPkg); Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +19 −1 Original line number Diff line number Diff line Loading @@ -808,6 +808,23 @@ public class PreferencesHelper implements RankingConfig { } } /** Sets whether this package has sent a notification with valid bubble metadata. */ public boolean setValidBubbleSent(String packageName, int uid) { synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(packageName, uid); boolean valueChanged = !r.hasSentValidBubble; r.hasSentValidBubble = true; return valueChanged; } } boolean hasSentValidBubble(String packageName, int uid) { synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(packageName, uid); return r.hasSentValidBubble; } } @Override public boolean isGroupBlocked(String packageName, int uid, String groupId) { if (groupId == null) { Loading Loading @@ -2813,8 +2830,9 @@ public class PreferencesHelper implements RankingConfig { boolean hasSentInvalidMessage = false; boolean hasSentValidMessage = false; // notE: only valid while hasSentMessage is false and hasSentInvalidMessage is true // note: only valid while hasSentMessage is false and hasSentInvalidMessage is true boolean userDemotedMsgApp = false; boolean hasSentValidBubble = false; Delegate delegate = null; ArrayMap<String, NotificationChannel> channels = new ArrayMap<>(); Loading
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -542,6 +542,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.setInvalidMessageSent(PKG_P, UID_P); mHelper.setValidMessageSent(PKG_P, UID_P); mHelper.setInvalidMsgAppDemoted(PKG_P, UID_P, true); mHelper.setValidBubbleSent(PKG_P, UID_P); mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE); Loading @@ -561,6 +562,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertFalse(mHelper.hasSentInvalidMsg(PKG_N_MR1, UID_N_MR1)); assertTrue(mHelper.hasSentValidMsg(PKG_P, UID_P)); assertTrue(mHelper.didUserEverDemoteInvalidMsgApp(PKG_P, UID_P)); assertTrue(mHelper.hasSentValidBubble(PKG_P, UID_P)); assertEquals(channel1, mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1.getId(), false)); compareChannels(channel2, Loading Loading @@ -4926,6 +4928,18 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertFalse(mHelper.hasUserDemotedInvalidMsgApp(PKG_P, UID_P)); } @Test public void testValidBubbleSent() { // create package preferences mHelper.canShowBadge(PKG_P, UID_P); // false by default assertFalse(mHelper.hasSentValidBubble(PKG_P, UID_P)); // set something valid was sent mHelper.setValidBubbleSent(PKG_P, UID_P); assertTrue(mHelper.hasSentValidBubble(PKG_P, UID_P)); } @Test public void testPullPackageChannelPreferencesStats() { String channelId = "parent"; Loading