diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java index 96aae0ea4bb..6b279ed947d 100644 --- a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java +++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java @@ -119,8 +119,9 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment queryImsState(WifiCallingSettingsForSub.this.mSubId).isAllowUserControl(); final boolean isWfcEnabled = mSwitchBar.isChecked() && isNonTtyOrTtyOnVolteEnabled; - boolean isCallStateIdle = - mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE; + boolean isCallStateIdle = getTelephonyManagerForSub( + WifiCallingSettingsForSub.this.mSubId).getCallState() + == TelephonyManager.CALL_STATE_IDLE; mSwitchBar.setEnabled(isCallStateIdle && isNonTtyOrTtyOnVolteEnabled); @@ -201,7 +202,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment mSwitchBar.hide(); } - private void showAlert(Intent intent) { + @VisibleForTesting + void showAlert(Intent intent) { final Context context = getActivity(); final CharSequence title = intent.getCharSequenceExtra(Phone.EXTRA_KEY_ALERT_TITLE); @@ -247,6 +249,14 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment return 0; } + @VisibleForTesting + TelephonyManager getTelephonyManagerForSub(int subId) { + if (mTelephonyManager == null) { + mTelephonyManager = getContext().getSystemService(TelephonyManager.class); + } + return mTelephonyManager.createForSubscriptionId(subId); + } + @VisibleForTesting WifiCallingQueryImsState queryImsState(int subId) { return new WifiCallingQueryImsState(getContext(), subId); @@ -420,7 +430,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment updateBody(); if (queryImsState(mSubId).isWifiCallingSupported()) { - mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); + getTelephonyManagerForSub(mSubId).listen(mPhoneStateListener, + PhoneStateListener.LISTEN_CALL_STATE); mSwitchBar.addOnSwitchChangeListener(this); @@ -448,7 +459,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment if (mValidListener) { mValidListener = false; - mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); + getTelephonyManagerForSub(mSubId).listen(mPhoneStateListener, + PhoneStateListener.LISTEN_NONE); mSwitchBar.removeOnSwitchChangeListener(this); } diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java index 5b76adc84c5..a9df33d36c6 100644 --- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java +++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java @@ -351,5 +351,13 @@ public class WifiCallingSettingsForSubTest { return null; } } + + @Override + TelephonyManager getTelephonyManagerForSub(int subId) { + return mTelephonyManager; + } + + @Override + void showAlert(Intent intent) {} } }