[WFC] The WFC UI did not refresh after the subscriptionInfoChanged

Add the listener for subscriptionInfoChanged and update the Visible
of the category.

Bug: 233783112
Test: atest NetworkProviderWifiCallingGroupTest
Change-Id: I7698915abb2f3b0ba2b40d8e78fe4e3302756c91
diff --git a/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroup.java b/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroup.java
index 14bdd41..688084f 100644
--- a/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroup.java
+++ b/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroup.java
@@ -74,6 +74,7 @@
     private Map<Integer, PhoneAccountHandle> mSimCallManagerList = new HashMap<>();
     private Map<Integer, Preference> mWifiCallingForSubPreferences;
     private List<SubscriptionInfo> mSubInfoListForWfc;
+    private SubscriptionsChangeListener mChangeListener;
 
     public NetworkProviderWifiCallingGroup(Context context, Lifecycle lifecycle,
             String preferenceGroupKey) {
@@ -87,26 +88,25 @@
             mTelephonyCallback = new PhoneCallStateTelephonyCallback();
         }
         lifecycle.addObserver(this);
+        mChangeListener = new SubscriptionsChangeListener(context, this);
     }
 
     private void setSubscriptionInfoList(Context context) {
         mSubInfoListForWfc = new ArrayList<>(
                 SubscriptionUtil.getActiveSubscriptions(mSubscriptionManager));
-        if (mSubInfoListForWfc != null) {
-            mSubInfoListForWfc.removeIf(info -> {
-                final int subId = info.getSubscriptionId();
-                setTelephonyManagerForSubscriptionId(context, subId);
-                setPhoneAccountHandleForSubscriptionId(context, subId);
-                boolean isExisted = mSubInfoListForWfc.contains(info);
-                boolean shouldShowWfcForSub = shouldShowWifiCallingForSub(subId);
-                if (!shouldShowWfcForSub && isExisted) {
-                    return true;
-                }
-                return false;
-            });
-        } else {
-            Log.d(TAG, "No active subscriptions");
-        }
+        mSubInfoListForWfc.removeIf(info -> {
+            final int subId = info.getSubscriptionId();
+            setTelephonyManagerForSubscriptionId(context, subId);
+            setPhoneAccountHandleForSubscriptionId(context, subId);
+            boolean isExisted = mSubInfoListForWfc.contains(info);
+            boolean shouldShowWfcForSub = shouldShowWifiCallingForSub(subId);
+            if (!shouldShowWfcForSub && isExisted) {
+                return true;
+            }
+            return false;
+        });
+        Log.d(TAG, "setSubscriptionInfoList: mSubInfoListForWfc size:"
+                + mSubInfoListForWfc.size());
     }
 
     private void setTelephonyManagerForSubscriptionId(Context context, int subId) {
@@ -137,12 +137,18 @@
 
     @OnLifecycleEvent(Event.ON_RESUME)
     public void onResume() {
+        if (mChangeListener != null) {
+            mChangeListener.start();
+        }
         updateListener();
         update();
     }
 
     @OnLifecycleEvent(Event.ON_PAUSE)
     public void onPause() {
+        if (mChangeListener != null) {
+            mChangeListener.stop();
+        }
         if ((mTelephonyCallback != null)) {
             mTelephonyCallback.unregister();
         }
@@ -176,6 +182,7 @@
 
     private void update() {
         if (mPreferenceGroup == null) {
+            Log.d(TAG, "mPreferenceGroup == null");
             return;
         }
 
@@ -255,7 +262,11 @@
 
     @Override
     public void onSubscriptionsChanged() {
+        Log.d(TAG, "onSubscriptionsChanged:");
         setSubscriptionInfoList(mContext);
+        if (mPreferenceGroup != null) {
+            mPreferenceGroup.setVisible(isAvailable());
+        }
         updateListener();
         update();
     }
@@ -322,6 +333,7 @@
                         CarrierConfigManager.KEY_CARRIER_WFC_IMS_AVAILABLE_BOOL);
             }
         }
+        Log.d(TAG, "isWifiCallingAvailableForCarrier:" + isWifiCallingAvailableForCarrier);
         return isWifiCallingAvailableForCarrier;
     }