Fix issue of hearing ring sound twice.

For subscription where no change in MWI status, keep isRefresh to true
so that no alert sound is heard again, if its already visible.

Bug: 34871334
Change-Id: Ib7e85f83309d9db966dee7a3ad6fe41a8d53b2e6
diff --git a/src/com/android/phone/CallNotifier.java b/src/com/android/phone/CallNotifier.java
index d084e92..1a7a1d1 100644
--- a/src/com/android/phone/CallNotifier.java
+++ b/src/com/android/phone/CallNotifier.java
@@ -105,6 +105,10 @@
     // they don't step on each others' toes.
     public static final int INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE = 22;
 
+    public static final int UPDATE_TYPE_MWI = 0;
+    public static final int UPDATE_TYPE_CFI = 1;
+    public static final int UPDATE_TYPE_MWI_CFI = 2;
+
     /**
      * Initialize the singleton CallNotifier instance.
      * This is only done once, at startup, from PhoneApp.onCreate().
@@ -578,6 +582,11 @@
     }
 
     public void updatePhoneStateListeners(boolean isRefresh) {
+        updatePhoneStateListeners(isRefresh, UPDATE_TYPE_MWI_CFI,
+                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+    }
+
+    public void updatePhoneStateListeners(boolean isRefresh, int updateType, int subIdToUpdate) {
         List<SubscriptionInfo> subInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
 
         // Sort sub id list based on slot id, so that CFI/MWI notifications will be updated for
@@ -609,10 +618,20 @@
                 Log.d(LOG_TAG, "updatePhoneStateListeners: update CF notifications.");
 
                 if (mCFIStatus.containsKey(subId)) {
-                    mApplication.notificationMgr.updateCfi(subId, mCFIStatus.get(subId));
+                    if ((updateType == UPDATE_TYPE_CFI) && (subId == subIdToUpdate)) {
+                        mApplication.notificationMgr.updateCfi(subId, mCFIStatus.get(subId),
+                                isRefresh);
+                    } else {
+                        mApplication.notificationMgr.updateCfi(subId, mCFIStatus.get(subId), true);
+                    }
                 }
                 if (mMWIStatus.containsKey(subId)) {
-                    mApplication.notificationMgr.updateMwi(subId, mMWIStatus.get(subId), isRefresh);
+                    if ((updateType == UPDATE_TYPE_MWI) && (subId == subIdToUpdate)) {
+                        mApplication.notificationMgr.updateMwi(subId, mMWIStatus.get(subId),
+                            isRefresh);
+                    } else {
+                        mApplication.notificationMgr.updateMwi(subId, mMWIStatus.get(subId), true);
+                    }
                 }
             }
         }
@@ -785,7 +804,7 @@
         public void onMessageWaitingIndicatorChanged(boolean visible) {
             if (VDBG) log("onMessageWaitingIndicatorChanged(): " + this.mSubId + " " + visible);
             mMWIStatus.put(this.mSubId, visible);
-            updatePhoneStateListeners(false);
+            updatePhoneStateListeners(false, UPDATE_TYPE_MWI, this.mSubId);
         }
 
         @Override
@@ -793,7 +812,7 @@
             Log.i(LOG_TAG, "onCallForwardingIndicatorChanged(): subId=" + this.mSubId
                     + ", visible=" + (visible ? "Y" : "N"));
             mCFIStatus.put(this.mSubId, visible);
-            updatePhoneStateListeners(false);
+            updatePhoneStateListeners(false, UPDATE_TYPE_CFI, this.mSubId);
         }
     };
 
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index da97582..fbb6dc5 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -453,9 +453,19 @@
     /**
      * Updates the message call forwarding indicator notification.
      *
-     * @param visible true if there are messages waiting
+     * @param visible true if call forwarding enabled
      */
-    /* package */ void updateCfi(int subId, boolean visible) {
+
+     /* package */ void updateCfi(int subId, boolean visible) {
+        updateCfi(subId, visible, false /* isRefresh */);
+    }
+
+    /**
+     * Updates the message call forwarding indicator notification.
+     *
+     * @param visible true if call forwarding enabled
+     */
+    /* package */ void updateCfi(int subId, boolean visible, boolean isRefresh) {
         logi("updateCfi: subId= " + subId + ", visible=" + (visible ? "Y" : "N"));
         if (visible) {
             // If Unconditional Call Forwarding (forward all calls) for VOICE
@@ -493,7 +503,8 @@
                     .setContentText(mContext.getString(R.string.sum_cfu_enabled_indicator))
                     .setShowWhen(false)
                     .setOngoing(true)
-                    .setChannel(NotificationChannelController.CHANNEL_ID_CALL_FORWARD);
+                    .setChannel(NotificationChannelController.CHANNEL_ID_CALL_FORWARD)
+                    .setOnlyAlertOnce(isRefresh);
 
             Intent intent = new Intent(Intent.ACTION_MAIN);
             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);