From eb455965ef7ff4b79ffe5626548d3aa4d3e16473 Mon Sep 17 00:00:00 2001 From: Beverly Date: Tue, 20 Mar 2018 15:42:12 -0400 Subject: [PATCH] Category message is sufficient for message notif If a notification is marked with category message, then it is sufficient enough to be deemed a "message" notification. However, to be considered an important message, we still check if the message is from the default messaging app and has category = message. Change-Id: I4f2b502634b805919bdf8b82e3bdf475c0992bdd Fixes:76019310 Test: AttentionManagementVerifierActivity Test: atest services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java --- .../util/NotificationMessagingUtil.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/core/java/com/android/internal/util/NotificationMessagingUtil.java b/core/java/com/android/internal/util/NotificationMessagingUtil.java index b962d4fc9f5e4..bf796cddd89e0 100644 --- a/core/java/com/android/internal/util/NotificationMessagingUtil.java +++ b/core/java/com/android/internal/util/NotificationMessagingUtil.java @@ -26,7 +26,6 @@ import android.os.Looper; import android.os.UserHandle; import android.provider.Settings; import android.service.notification.StatusBarNotification; -import android.text.TextUtils; import android.util.ArrayMap; import java.util.Objects; @@ -47,6 +46,18 @@ public class NotificationMessagingUtil { Settings.Secure.getUriFor(DEFAULT_SMS_APP_SETTING), false, mSmsContentObserver); } + public boolean isImportantMessaging(StatusBarNotification sbn, int importance) { + if (importance < NotificationManager.IMPORTANCE_LOW) { + return false; + } + + return hasMessagingStyle(sbn) || (isCategoryMessage(sbn) && isDefaultMessagingApp(sbn)); + } + + public boolean isMessaging(StatusBarNotification sbn) { + return hasMessagingStyle(sbn) || isDefaultMessagingApp(sbn) || isCategoryMessage(sbn); + } + @SuppressWarnings("deprecation") private boolean isDefaultMessagingApp(StatusBarNotification sbn) { final int userId = sbn.getUserId(); @@ -73,25 +84,12 @@ public class NotificationMessagingUtil { } }; - public boolean isImportantMessaging(StatusBarNotification sbn, int importance) { - if (importance < NotificationManager.IMPORTANCE_LOW) { - return false; - } - - return isMessaging(sbn); + private boolean hasMessagingStyle(StatusBarNotification sbn) { + Class style = sbn.getNotification().getNotificationStyle(); + return Notification.MessagingStyle.class.equals(style); } - public boolean isMessaging(StatusBarNotification sbn) { - Class style = sbn.getNotification().getNotificationStyle(); - if (Notification.MessagingStyle.class.equals(style)) { - return true; - } - - if (Notification.CATEGORY_MESSAGE.equals(sbn.getNotification().category) - && isDefaultMessagingApp(sbn)) { - return true; - } - - return false; + private boolean isCategoryMessage(StatusBarNotification sbn) { + return Notification.CATEGORY_MESSAGE.equals(sbn.getNotification().category); } }