Snap for 6304846 from f4b1655a9110d37dc7444d11d4a0b6f4c8bdf9ed to qt-qpr3-release

Change-Id: Ica33bbb6d1fa93be4e6d62b6c381b8d0f5d0a7b3
diff --git a/res/values-pt/strings.xml b/res/values-pt/strings.xml
index d82d53e..fb3895d 100644
--- a/res/values-pt/strings.xml
+++ b/res/values-pt/strings.xml
@@ -27,7 +27,7 @@
     <string name="toast_message_sent_success" msgid="1159956191974273064">"Mensagem enviada."</string>
     <string name="notification_service_label" msgid="7512186049723777468">"Serviço de escuta de notificações do carro"</string>
     <string name="notifications" msgid="2865534625906329283">"Central de notificações"</string>
-    <string name="clear_all" msgid="1845314281571237722">"Limpar tudo"</string>
+    <string name="clear_all" msgid="1845314281571237722">"Excluir tudo"</string>
     <string name="ellipsized_string" msgid="6993649229498857557">"…"</string>
     <string name="show_more" msgid="7291378544926443344">"Mostrar mais"</string>
     <string name="notification_header" msgid="324550431063568049">"Notificações"</string>
diff --git a/src/com/android/car/notification/CarNotificationListener.java b/src/com/android/car/notification/CarNotificationListener.java
index 59020c8..e35b9d6 100644
--- a/src/com/android/car/notification/CarNotificationListener.java
+++ b/src/com/android/car/notification/CarNotificationListener.java
@@ -17,6 +17,7 @@
 
 import android.annotation.Nullable;
 import android.app.ActivityManager;
+import android.app.NotificationManager;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -198,7 +199,12 @@
     }
 
     private void notifyNotificationPosted(StatusBarNotification sbn) {
-        mNotificationDataManager.addNewMessageNotification(sbn);
+        if (shouldTrackUnseen(sbn)) {
+            mNotificationDataManager.addNewMessageNotification(sbn);
+        } else {
+            mNotificationDataManager.untrackUnseenNotification(sbn);
+        }
+
         mHeadsUpManager.maybeShowHeadsUp(sbn, getCurrentRanking(), mActiveNotifications);
         if (mHandler == null) {
             return;
@@ -214,4 +220,12 @@
             return CarNotificationListener.this;
         }
     }
+
+    // We do not want to show unseen markers for <= LOW importance notifications to be consistent
+    // with how these notifications are handled on phones
+    boolean shouldTrackUnseen(StatusBarNotification sbn) {
+        Ranking ranking = new NotificationListenerService.Ranking();
+        mRankingMap.getRanking(sbn.getKey(), ranking);
+        return ranking.getImportance() > NotificationManager.IMPORTANCE_LOW;
+    }
 }
diff --git a/src/com/android/car/notification/NotificationDataManager.java b/src/com/android/car/notification/NotificationDataManager.java
index 96fabbf..59d019f 100644
--- a/src/com/android/car/notification/NotificationDataManager.java
+++ b/src/com/android/car/notification/NotificationDataManager.java
@@ -91,6 +91,15 @@
         }
     }
 
+    void untrackUnseenNotification(StatusBarNotification notification) {
+        if (mUnseenNotificationMap.containsKey(notification.getKey())) {
+            mUnseenNotificationMap.remove(notification.getKey());
+            if (mOnUnseenCountUpdateListener != null) {
+                mOnUnseenCountUpdateListener.onUnseenCountUpdate();
+            }
+        }
+    }
+
     void updateUnseenNotification(List<NotificationGroup> notificationGroups) {
         Set<String> currentNotificationKeys = new HashSet<>();
 
diff --git a/src/com/android/car/notification/NotificationViewController.java b/src/com/android/car/notification/NotificationViewController.java
index dfdfeaa..b4c347d 100644
--- a/src/com/android/car/notification/NotificationViewController.java
+++ b/src/com/android/car/notification/NotificationViewController.java
@@ -11,6 +11,7 @@
 import android.widget.Toast;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * This class is a bridge to collect signals from the notification and ux restriction services and
@@ -105,7 +106,12 @@
                 mCarNotificationListener.getNotifications(),
                 mCarNotificationListener.getCurrentRanking());
 
-        mNotificationDataManager.updateUnseenNotification(notificationGroups);
+        List<NotificationGroup> unseenNotifications = notificationGroups.stream()
+                .filter(g -> g.getChildNotifications().stream()
+                        .anyMatch(mCarNotificationListener::shouldTrackUnseen))
+                .collect(Collectors.toList());
+
+        mNotificationDataManager.updateUnseenNotification(unseenNotifications);
         mCarNotificationView.setNotifications(notificationGroups);
     }