Loading core/java/android/app/INotificationManager.aidl +1 −0 Original line number Original line Diff line number Diff line Loading @@ -58,6 +58,7 @@ interface INotificationManager void setShowBadge(String pkg, int uid, boolean showBadge); void setShowBadge(String pkg, int uid, boolean showBadge); boolean canShowBadge(String pkg, int uid); boolean canShowBadge(String pkg, int uid); boolean hasSentMessage(String pkg, int uid); void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled); void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled); /** /** * Updates the notification's enabled state. Additionally locks importance for all of the * Updates the notification's enabled state. Additionally locks importance for all of the Loading services/core/java/com/android/server/notification/NotificationManagerService.java +17 −0 Original line number Original line Diff line number Diff line Loading @@ -2719,6 +2719,16 @@ public class NotificationManagerService extends SystemService { return text == null ? null : String.valueOf(text); return text == null ? null : String.valueOf(text); } } protected void maybeRegisterMessageSent(NotificationRecord r) { Context appContext = r.getSbn().getPackageContext(getContext()); Notification.Builder nb = Notification.Builder.recoverBuilder(appContext, r.getNotification()); if (nb.getStyle() instanceof Notification.MessagingStyle) { mPreferencesHelper.setMessageSent(r.getSbn().getPackageName(), r.getUid()); handleSavePolicyFile(); } } /** /** * Report to usage stats that the user interacted with the notification. * Report to usage stats that the user interacted with the notification. * @param r notification record * @param r notification record Loading Loading @@ -3145,6 +3155,12 @@ public class NotificationManagerService extends SystemService { handleSavePolicyFile(); handleSavePolicyFile(); } } @Override public boolean hasSentMessage(String pkg, int uid) { checkCallerIsSystem(); return mPreferencesHelper.hasSentMessage(pkg, uid); } @Override @Override public void setNotificationDelegate(String callingPkg, String delegate) { public void setNotificationDelegate(String callingPkg, String delegate) { checkCallerIsSameApp(callingPkg); checkCallerIsSameApp(callingPkg); Loading Loading @@ -6459,6 +6475,7 @@ public class NotificationManagerService extends SystemService { } } maybeRecordInterruptionLocked(r); maybeRecordInterruptionLocked(r); maybeRegisterMessageSent(r); // Log event to statsd // Log event to statsd mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position, mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position, Loading services/core/java/com/android/server/notification/PreferencesHelper.java +19 −1 Original line number Original line Diff line number Diff line Loading @@ -116,6 +116,7 @@ public class PreferencesHelper implements RankingConfig { private static final String ATT_ENABLED = "enabled"; private static final String ATT_ENABLED = "enabled"; private static final String ATT_USER_ALLOWED = "allowed"; private static final String ATT_USER_ALLOWED = "allowed"; private static final String ATT_HIDE_SILENT = "hide_gentle"; private static final String ATT_HIDE_SILENT = "hide_gentle"; private static final String ATT_SENT_MESSAGE = "sent_msg"; private static final int DEFAULT_PRIORITY = Notification.PRIORITY_DEFAULT; private static final int DEFAULT_PRIORITY = Notification.PRIORITY_DEFAULT; private static final int DEFAULT_VISIBILITY = NotificationManager.VISIBILITY_NO_OVERRIDE; private static final int DEFAULT_VISIBILITY = NotificationManager.VISIBILITY_NO_OVERRIDE; Loading Loading @@ -269,6 +270,8 @@ public class PreferencesHelper implements RankingConfig { parser, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE); parser, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE); r.lockedAppFields = XmlUtils.readIntAttribute(parser, r.lockedAppFields = XmlUtils.readIntAttribute(parser, ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS); ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS); r.hasSentMessage = XmlUtils.readBooleanAttribute( parser, ATT_SENT_MESSAGE, false); final int innerDepth = parser.getDepth(); final int innerDepth = parser.getDepth(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT while ((type = parser.next()) != XmlPullParser.END_DOCUMENT Loading Loading @@ -510,7 +513,8 @@ public class PreferencesHelper implements RankingConfig { || r.channels.size() > 0 || r.channels.size() > 0 || r.groups.size() > 0 || r.groups.size() > 0 || r.delegate != null || r.delegate != null || r.bubblePreference != DEFAULT_BUBBLE_PREFERENCE; || r.bubblePreference != DEFAULT_BUBBLE_PREFERENCE || r.hasSentMessage; if (hasNonDefaultSettings) { if (hasNonDefaultSettings) { out.startTag(null, TAG_PACKAGE); out.startTag(null, TAG_PACKAGE); out.attribute(null, ATT_NAME, r.pkg); out.attribute(null, ATT_NAME, r.pkg); Loading @@ -529,6 +533,7 @@ public class PreferencesHelper implements RankingConfig { out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(r.showBadge)); out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(r.showBadge)); out.attribute(null, ATT_APP_USER_LOCKED_FIELDS, out.attribute(null, ATT_APP_USER_LOCKED_FIELDS, Integer.toString(r.lockedAppFields)); Integer.toString(r.lockedAppFields)); out.attribute(null, ATT_SENT_MESSAGE, Boolean.toString(r.hasSentMessage)); if (!forBackup) { if (!forBackup) { out.attribute(null, ATT_UID, Integer.toString(r.uid)); out.attribute(null, ATT_UID, Integer.toString(r.uid)); Loading Loading @@ -647,6 +652,18 @@ public class PreferencesHelper implements RankingConfig { updateConfig(); updateConfig(); } } public boolean hasSentMessage(String packageName, int uid) { synchronized (mPackagePreferences) { return getOrCreatePackagePreferencesLocked(packageName, uid).hasSentMessage; } } public void setMessageSent(String packageName, int uid) { synchronized (mPackagePreferences) { getOrCreatePackagePreferencesLocked(packageName, uid).hasSentMessage = true; } } @Override @Override public boolean isGroupBlocked(String packageName, int uid, String groupId) { public boolean isGroupBlocked(String packageName, int uid, String groupId) { if (groupId == null) { if (groupId == null) { Loading Loading @@ -2271,6 +2288,7 @@ public class PreferencesHelper implements RankingConfig { boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE; boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE; List<String> oemLockedChannels = new ArrayList<>(); List<String> oemLockedChannels = new ArrayList<>(); boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE; boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE; boolean hasSentMessage = false; Delegate delegate = null; Delegate delegate = null; ArrayMap<String, NotificationChannel> channels = new ArrayMap<>(); ArrayMap<String, NotificationChannel> channels = new ArrayMap<>(); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +12 −0 Original line number Original line Diff line number Diff line Loading @@ -6573,4 +6573,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { fail(e.getMessage()); fail(e.getMessage()); } } } } @Test public void testRecordMessages() throws RemoteException { NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "testRecordMessages"); mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); assertTrue(mBinderService.hasSentMessage(PKG, mUid)); } } } services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +16 −0 Original line number Original line Diff line number Diff line Loading @@ -454,6 +454,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false); mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false); mHelper.setShowBadge(PKG_N_MR1, UID_N_MR1, true); mHelper.setShowBadge(PKG_N_MR1, UID_N_MR1, true); mHelper.setMessageSent(PKG_P, UID_P); mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE); mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE); Loading @@ -469,6 +470,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertEquals(IMPORTANCE_NONE, mHelper.getImportance(PKG_O, UID_O)); assertEquals(IMPORTANCE_NONE, mHelper.getImportance(PKG_O, UID_O)); assertTrue(mHelper.canShowBadge(PKG_N_MR1, UID_N_MR1)); assertTrue(mHelper.canShowBadge(PKG_N_MR1, UID_N_MR1)); assertTrue(mHelper.hasSentMessage(PKG_P, UID_P)); assertFalse(mHelper.hasSentMessage(PKG_N_MR1, UID_N_MR1)); assertEquals(channel1, assertEquals(channel1, mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1.getId(), false)); mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1.getId(), false)); compareChannels(channel2, compareChannels(channel2, Loading Loading @@ -3390,4 +3393,17 @@ public class PreferencesHelperTest extends UiServiceTestCase { .NOTIFICATION_CHANNEL_CONVERSATION_DELETED, .NOTIFICATION_CHANNEL_CONVERSATION_DELETED, mLogger.get(6).event); // Delete Channel channel2 - Conversation A person calls mLogger.get(6).event); // Delete Channel channel2 - Conversation A person calls } } @Test public void testMessageSent() { // create package preferences mHelper.canShowBadge(PKG_P, UID_P); // check default value assertFalse(mHelper.hasSentMessage(PKG_P, UID_P)); // change it mHelper.setMessageSent(PKG_P, UID_P); assertTrue(mHelper.hasSentMessage(PKG_P, UID_P)); } } } Loading
core/java/android/app/INotificationManager.aidl +1 −0 Original line number Original line Diff line number Diff line Loading @@ -58,6 +58,7 @@ interface INotificationManager void setShowBadge(String pkg, int uid, boolean showBadge); void setShowBadge(String pkg, int uid, boolean showBadge); boolean canShowBadge(String pkg, int uid); boolean canShowBadge(String pkg, int uid); boolean hasSentMessage(String pkg, int uid); void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled); void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled); /** /** * Updates the notification's enabled state. Additionally locks importance for all of the * Updates the notification's enabled state. Additionally locks importance for all of the Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +17 −0 Original line number Original line Diff line number Diff line Loading @@ -2719,6 +2719,16 @@ public class NotificationManagerService extends SystemService { return text == null ? null : String.valueOf(text); return text == null ? null : String.valueOf(text); } } protected void maybeRegisterMessageSent(NotificationRecord r) { Context appContext = r.getSbn().getPackageContext(getContext()); Notification.Builder nb = Notification.Builder.recoverBuilder(appContext, r.getNotification()); if (nb.getStyle() instanceof Notification.MessagingStyle) { mPreferencesHelper.setMessageSent(r.getSbn().getPackageName(), r.getUid()); handleSavePolicyFile(); } } /** /** * Report to usage stats that the user interacted with the notification. * Report to usage stats that the user interacted with the notification. * @param r notification record * @param r notification record Loading Loading @@ -3145,6 +3155,12 @@ public class NotificationManagerService extends SystemService { handleSavePolicyFile(); handleSavePolicyFile(); } } @Override public boolean hasSentMessage(String pkg, int uid) { checkCallerIsSystem(); return mPreferencesHelper.hasSentMessage(pkg, uid); } @Override @Override public void setNotificationDelegate(String callingPkg, String delegate) { public void setNotificationDelegate(String callingPkg, String delegate) { checkCallerIsSameApp(callingPkg); checkCallerIsSameApp(callingPkg); Loading Loading @@ -6459,6 +6475,7 @@ public class NotificationManagerService extends SystemService { } } maybeRecordInterruptionLocked(r); maybeRecordInterruptionLocked(r); maybeRegisterMessageSent(r); // Log event to statsd // Log event to statsd mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position, mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position, Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +19 −1 Original line number Original line Diff line number Diff line Loading @@ -116,6 +116,7 @@ public class PreferencesHelper implements RankingConfig { private static final String ATT_ENABLED = "enabled"; private static final String ATT_ENABLED = "enabled"; private static final String ATT_USER_ALLOWED = "allowed"; private static final String ATT_USER_ALLOWED = "allowed"; private static final String ATT_HIDE_SILENT = "hide_gentle"; private static final String ATT_HIDE_SILENT = "hide_gentle"; private static final String ATT_SENT_MESSAGE = "sent_msg"; private static final int DEFAULT_PRIORITY = Notification.PRIORITY_DEFAULT; private static final int DEFAULT_PRIORITY = Notification.PRIORITY_DEFAULT; private static final int DEFAULT_VISIBILITY = NotificationManager.VISIBILITY_NO_OVERRIDE; private static final int DEFAULT_VISIBILITY = NotificationManager.VISIBILITY_NO_OVERRIDE; Loading Loading @@ -269,6 +270,8 @@ public class PreferencesHelper implements RankingConfig { parser, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE); parser, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE); r.lockedAppFields = XmlUtils.readIntAttribute(parser, r.lockedAppFields = XmlUtils.readIntAttribute(parser, ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS); ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS); r.hasSentMessage = XmlUtils.readBooleanAttribute( parser, ATT_SENT_MESSAGE, false); final int innerDepth = parser.getDepth(); final int innerDepth = parser.getDepth(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT while ((type = parser.next()) != XmlPullParser.END_DOCUMENT Loading Loading @@ -510,7 +513,8 @@ public class PreferencesHelper implements RankingConfig { || r.channels.size() > 0 || r.channels.size() > 0 || r.groups.size() > 0 || r.groups.size() > 0 || r.delegate != null || r.delegate != null || r.bubblePreference != DEFAULT_BUBBLE_PREFERENCE; || r.bubblePreference != DEFAULT_BUBBLE_PREFERENCE || r.hasSentMessage; if (hasNonDefaultSettings) { if (hasNonDefaultSettings) { out.startTag(null, TAG_PACKAGE); out.startTag(null, TAG_PACKAGE); out.attribute(null, ATT_NAME, r.pkg); out.attribute(null, ATT_NAME, r.pkg); Loading @@ -529,6 +533,7 @@ public class PreferencesHelper implements RankingConfig { out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(r.showBadge)); out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(r.showBadge)); out.attribute(null, ATT_APP_USER_LOCKED_FIELDS, out.attribute(null, ATT_APP_USER_LOCKED_FIELDS, Integer.toString(r.lockedAppFields)); Integer.toString(r.lockedAppFields)); out.attribute(null, ATT_SENT_MESSAGE, Boolean.toString(r.hasSentMessage)); if (!forBackup) { if (!forBackup) { out.attribute(null, ATT_UID, Integer.toString(r.uid)); out.attribute(null, ATT_UID, Integer.toString(r.uid)); Loading Loading @@ -647,6 +652,18 @@ public class PreferencesHelper implements RankingConfig { updateConfig(); updateConfig(); } } public boolean hasSentMessage(String packageName, int uid) { synchronized (mPackagePreferences) { return getOrCreatePackagePreferencesLocked(packageName, uid).hasSentMessage; } } public void setMessageSent(String packageName, int uid) { synchronized (mPackagePreferences) { getOrCreatePackagePreferencesLocked(packageName, uid).hasSentMessage = true; } } @Override @Override public boolean isGroupBlocked(String packageName, int uid, String groupId) { public boolean isGroupBlocked(String packageName, int uid, String groupId) { if (groupId == null) { if (groupId == null) { Loading Loading @@ -2271,6 +2288,7 @@ public class PreferencesHelper implements RankingConfig { boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE; boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE; List<String> oemLockedChannels = new ArrayList<>(); List<String> oemLockedChannels = new ArrayList<>(); boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE; boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE; boolean hasSentMessage = false; Delegate delegate = null; Delegate delegate = null; ArrayMap<String, NotificationChannel> channels = new ArrayMap<>(); ArrayMap<String, NotificationChannel> channels = new ArrayMap<>(); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +12 −0 Original line number Original line Diff line number Diff line Loading @@ -6573,4 +6573,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { fail(e.getMessage()); fail(e.getMessage()); } } } } @Test public void testRecordMessages() throws RemoteException { NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "testRecordMessages"); mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); assertTrue(mBinderService.hasSentMessage(PKG, mUid)); } } }
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +16 −0 Original line number Original line Diff line number Diff line Loading @@ -454,6 +454,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false); mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false); mHelper.setShowBadge(PKG_N_MR1, UID_N_MR1, true); mHelper.setShowBadge(PKG_N_MR1, UID_N_MR1, true); mHelper.setMessageSent(PKG_P, UID_P); mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE); mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE); Loading @@ -469,6 +470,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertEquals(IMPORTANCE_NONE, mHelper.getImportance(PKG_O, UID_O)); assertEquals(IMPORTANCE_NONE, mHelper.getImportance(PKG_O, UID_O)); assertTrue(mHelper.canShowBadge(PKG_N_MR1, UID_N_MR1)); assertTrue(mHelper.canShowBadge(PKG_N_MR1, UID_N_MR1)); assertTrue(mHelper.hasSentMessage(PKG_P, UID_P)); assertFalse(mHelper.hasSentMessage(PKG_N_MR1, UID_N_MR1)); assertEquals(channel1, assertEquals(channel1, mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1.getId(), false)); mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1.getId(), false)); compareChannels(channel2, compareChannels(channel2, Loading Loading @@ -3390,4 +3393,17 @@ public class PreferencesHelperTest extends UiServiceTestCase { .NOTIFICATION_CHANNEL_CONVERSATION_DELETED, .NOTIFICATION_CHANNEL_CONVERSATION_DELETED, mLogger.get(6).event); // Delete Channel channel2 - Conversation A person calls mLogger.get(6).event); // Delete Channel channel2 - Conversation A person calls } } @Test public void testMessageSent() { // create package preferences mHelper.canShowBadge(PKG_P, UID_P); // check default value assertFalse(mHelper.hasSentMessage(PKG_P, UID_P)); // change it mHelper.setMessageSent(PKG_P, UID_P); assertTrue(mHelper.hasSentMessage(PKG_P, UID_P)); } } }