Fix the missed call notification.

It should show a missed call notification for each missed call. Before
the fix it only show one missed call notification no matter how many
missed calls there are.

Fixes: 143499577
Test: manually
Change-Id: I4c5e2f6a519ca19c6530fbceb24140fbd038bab0
diff --git a/src/com/android/car/dialer/notification/MissedCallNotificationController.java b/src/com/android/car/dialer/notification/MissedCallNotificationController.java
index bcd577d..2e96977 100644
--- a/src/com/android/car/dialer/notification/MissedCallNotificationController.java
+++ b/src/com/android/car/dialer/notification/MissedCallNotificationController.java
@@ -40,7 +40,9 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 
 /** Controller that manages the missed call notifications. */
@@ -93,7 +95,7 @@
     private final UnreadMissedCallLiveData mUnreadMissedCallLiveData;
     private final Observer<List<PhoneCallLog>> mUnreadMissedCallObserver;
     private final List<PhoneCallLog> mCurrentPhoneCallLogList;
-    private CompletableFuture<Void> mUpdateNotificationFuture;
+    private final Map<String, CompletableFuture<Void>> mUpdateFutures;
 
     @TargetApi(26)
     private MissedCallNotificationController(Context context) {
@@ -109,6 +111,8 @@
         mUnreadMissedCallLiveData = UnreadMissedCallLiveData.newInstance(context);
         mUnreadMissedCallObserver = this::updateNotifications;
         mUnreadMissedCallLiveData.observeForever(mUnreadMissedCallObserver);
+
+        mUpdateFutures = new HashMap<>();
     }
 
     /**
@@ -134,11 +138,13 @@
 
     private void showMissedCallNotification(PhoneCallLog callLog) {
         L.d(TAG, "show missed call notification %s", callLog);
-        if (mUpdateNotificationFuture != null) {
-            mUpdateNotificationFuture.cancel(true);
-        }
         String phoneNumber = callLog.getPhoneNumberString();
-        mUpdateNotificationFuture = NotificationUtils.getDisplayNameAndRoundedAvatar(
+        String tag = getTag(callLog);
+        CompletableFuture<Void> updateFuture = mUpdateFutures.get(tag);
+        if (updateFuture != null) {
+            updateFuture.cancel(true);
+        }
+        updateFuture = NotificationUtils.getDisplayNameAndRoundedAvatar(
                 mContext, phoneNumber)
                 .thenAcceptAsync((pair) -> {
                     Notification.Builder builder = new Notification.Builder(mContext, CHANNEL_ID)
@@ -161,15 +167,18 @@
                     }
 
                     mNotificationManager.notify(
-                            getTag(callLog),
+                            tag,
                             NOTIFICATION_ID,
                             builder.build());
                 }, mContext.getMainExecutor());
+        mUpdateFutures.put(tag, updateFuture);
     }
 
     private void cancelMissedCallNotification(PhoneCallLog phoneCallLog) {
         L.d(TAG, "cancel missed call notification %s", phoneCallLog);
-        mNotificationManager.cancel(getTag(phoneCallLog), NOTIFICATION_ID);
+        String tag = getTag(phoneCallLog);
+        mNotificationManager.cancel(tag, NOTIFICATION_ID);
+        mUpdateFutures.remove(tag);
     }
 
     private PendingIntent getContentPendingIntent() {