Only show missed call notification for first hfp device

Fixes: 170484869
Test: manually
Change-Id: If117e910cdf349f14c05ffa335e9ed5af8118fab
diff --git a/src/com/android/car/dialer/livedata/UnreadMissedCallLiveData.java b/src/com/android/car/dialer/livedata/UnreadMissedCallLiveData.java
index 08f3910..95d3be0 100644
--- a/src/com/android/car/dialer/livedata/UnreadMissedCallLiveData.java
+++ b/src/com/android/car/dialer/livedata/UnreadMissedCallLiveData.java
@@ -36,13 +36,15 @@
     private static final String[] EMPTY_STRING_ARRAY = new String[0];
 
     /** Get the {@link UnreadMissedCallLiveData} instance. */
-    public static UnreadMissedCallLiveData newInstance(Context context) {
+    public static UnreadMissedCallLiveData newInstance(Context context, String phoneAccountId) {
         StringBuilder where = new StringBuilder();
         List<String> selectionArgs = new ArrayList<>();
         where.append(String.format("(%s = ?)", CallLog.Calls.TYPE));
+        selectionArgs.add(Integer.toString(CallLog.Calls.MISSED_TYPE));
         where.append(String.format("AND (%s = 1)", CallLog.Calls.NEW));
         where.append(String.format("AND (%s IS NOT 1)", CallLog.Calls.IS_READ));
-        selectionArgs.add(Integer.toString(CallLog.Calls.MISSED_TYPE));
+        where.append(String.format("AND (%s = ?)", CallLog.Calls.PHONE_ACCOUNT_ID));
+        selectionArgs.add(phoneAccountId);
 
         String selection = where.length() > 0 ? where.toString() : null;
 
diff --git a/src/com/android/car/dialer/notification/MissedCallNotificationController.java b/src/com/android/car/dialer/notification/MissedCallNotificationController.java
index 219f879..1946006 100644
--- a/src/com/android/car/dialer/notification/MissedCallNotificationController.java
+++ b/src/com/android/car/dialer/notification/MissedCallNotificationController.java
@@ -27,10 +27,13 @@
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.annotation.StringRes;
+import androidx.lifecycle.LiveData;
 import androidx.lifecycle.Observer;
 
+import com.android.car.arch.common.LiveDataFunctions;
 import com.android.car.dialer.Constants;
 import com.android.car.dialer.R;
+import com.android.car.dialer.bluetooth.UiBluetoothMonitor;
 import com.android.car.dialer.livedata.UnreadMissedCallLiveData;
 import com.android.car.dialer.log.L;
 import com.android.car.dialer.ui.TelecomActivity;
@@ -92,7 +95,7 @@
 
     private final Context mContext;
     private final NotificationManager mNotificationManager;
-    private final UnreadMissedCallLiveData mUnreadMissedCallLiveData;
+    private final LiveData<List<PhoneCallLog>> mUnreadMissedCallLiveData;
     private final Observer<List<PhoneCallLog>> mUnreadMissedCallObserver;
     private final List<PhoneCallLog> mCurrentPhoneCallLogList;
     private final Map<String, CompletableFuture<Void>> mUpdateFutures = new HashMap<>();
@@ -107,7 +110,9 @@
         mNotificationManager.createNotificationChannel(notificationChannel);
 
         mCurrentPhoneCallLogList = new ArrayList<>();
-        mUnreadMissedCallLiveData = UnreadMissedCallLiveData.newInstance(context);
+        mUnreadMissedCallLiveData = LiveDataFunctions.switchMapNonNull(
+                UiBluetoothMonitor.get().getFirstHfpConnectedDevice(),
+                device-> UnreadMissedCallLiveData.newInstance(context, device.getAddress()));
         mUnreadMissedCallObserver = this::updateNotifications;
         mUnreadMissedCallLiveData.observeForever(mUnreadMissedCallObserver);
     }