Fix issue that preferences of call settings cannot be disabled

Video calling and Wi-fi calling preferences cannot be disabled when
SIM2 receives an incoming call while call settings for SIM1 is
displayed. The cause is that it registers a phone listener only for
a subId corresponding to currently displayed call setting.

To resolve this issue, listen phone state by the default
TelephonyManager to receive phone status of all subs.

Test: Checked that Video calling and Wi-fi calling preferences are
disabled when SIM2 receives an incoming call while the call
settings for SIM1 is displayed.
Bug: 74414829

Change-Id: Id97965e93f9fc6727164dc9de64f51bc014ab06d
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index dfbec46..e2f4fee 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -190,16 +190,25 @@
         }
     }
 
+    private void listenPhoneState(boolean listen) {
+        TelephonyManager telephonyManager =
+                (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
+        telephonyManager.listen(mPhoneStateListener, listen
+                ? PhoneStateListener.LISTEN_CALL_STATE : PhoneStateListener.LISTEN_NONE);
+    }
+
     private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
         @Override
         public void onCallStateChanged(int state, String incomingNumber) {
             if (DBG) log("PhoneStateListener onCallStateChanged: state is " + state);
+            // Use TelecomManager#getCallStete instead of 'state' parameter because it needs
+            // to check the current state of all phone calls.
+            boolean isCallStateIdle =
+                    mTelecomManager.getCallState() == TelephonyManager.CALL_STATE_IDLE;
             if (mEnableVideoCalling != null) {
-                // Use TelephonyManager#getCallStete instead of 'state' parameter because it needs
-                // to check the current state of all phone calls.
-                boolean isCallStateIdle =
-                        mTelecomManager.getCallState() == TelephonyManager.CALL_STATE_IDLE;
                 mEnableVideoCalling.setEnabled(isCallStateIdle);
+            }
+            if (mButtonWifiCalling != null) {
                 mButtonWifiCalling.setEnabled(isCallStateIdle);
             }
         }
@@ -208,10 +217,7 @@
     @Override
     protected void onPause() {
         super.onPause();
-        TelephonyManager telephonyManager =
-                (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-        telephonyManager.createForSubscriptionId(mPhone.getSubId())
-                .listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
+        listenPhoneState(false);
     }
 
     @Override
@@ -219,6 +225,7 @@
         super.onResume();
 
         updateImsManager(mPhone);
+        listenPhoneState(true);
         PreferenceScreen preferenceScreen = getPreferenceScreen();
         if (preferenceScreen != null) {
             preferenceScreen.removeAll();
@@ -228,7 +235,6 @@
 
         TelephonyManager telephonyManager = getSystemService(TelephonyManager.class)
                 .createForSubscriptionId(mPhone.getSubId());
-        telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
 
         PreferenceScreen prefSet = getPreferenceScreen();
         mVoicemailSettingsScreen =