[Settings] Code Refactor

Code refactor in order to support auto testing

Bug:  140542283
Test: m RunSettingsRoboTests -j
ROBOTEST_FILTER=WifiCallingSettingsForSubTest

Change-Id: I2427732435b59d7359a102e0dd56317ac6a024b4
This commit is contained in:
Bonian Chen
2020-03-30 15:03:46 +08:00
parent 477c4fef48
commit 21475ae6c6
2 changed files with 25 additions and 5 deletions

View File

@@ -119,8 +119,9 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
queryImsState(WifiCallingSettingsForSub.this.mSubId).isAllowUserControl(); queryImsState(WifiCallingSettingsForSub.this.mSubId).isAllowUserControl();
final boolean isWfcEnabled = mSwitchBar.isChecked() final boolean isWfcEnabled = mSwitchBar.isChecked()
&& isNonTtyOrTtyOnVolteEnabled; && isNonTtyOrTtyOnVolteEnabled;
boolean isCallStateIdle = boolean isCallStateIdle = getTelephonyManagerForSub(
mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE; WifiCallingSettingsForSub.this.mSubId).getCallState()
== TelephonyManager.CALL_STATE_IDLE;
mSwitchBar.setEnabled(isCallStateIdle mSwitchBar.setEnabled(isCallStateIdle
&& isNonTtyOrTtyOnVolteEnabled); && isNonTtyOrTtyOnVolteEnabled);
@@ -201,7 +202,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
mSwitchBar.hide(); mSwitchBar.hide();
} }
private void showAlert(Intent intent) { @VisibleForTesting
void showAlert(Intent intent) {
final Context context = getActivity(); final Context context = getActivity();
final CharSequence title = intent.getCharSequenceExtra(Phone.EXTRA_KEY_ALERT_TITLE); final CharSequence title = intent.getCharSequenceExtra(Phone.EXTRA_KEY_ALERT_TITLE);
@@ -247,6 +249,14 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
return 0; return 0;
} }
@VisibleForTesting
TelephonyManager getTelephonyManagerForSub(int subId) {
if (mTelephonyManager == null) {
mTelephonyManager = getContext().getSystemService(TelephonyManager.class);
}
return mTelephonyManager.createForSubscriptionId(subId);
}
@VisibleForTesting @VisibleForTesting
WifiCallingQueryImsState queryImsState(int subId) { WifiCallingQueryImsState queryImsState(int subId) {
return new WifiCallingQueryImsState(getContext(), subId); return new WifiCallingQueryImsState(getContext(), subId);
@@ -420,7 +430,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
updateBody(); updateBody();
if (queryImsState(mSubId).isWifiCallingSupported()) { if (queryImsState(mSubId).isWifiCallingSupported()) {
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); getTelephonyManagerForSub(mSubId).listen(mPhoneStateListener,
PhoneStateListener.LISTEN_CALL_STATE);
mSwitchBar.addOnSwitchChangeListener(this); mSwitchBar.addOnSwitchChangeListener(this);
@@ -448,7 +459,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
if (mValidListener) { if (mValidListener) {
mValidListener = false; mValidListener = false;
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); getTelephonyManagerForSub(mSubId).listen(mPhoneStateListener,
PhoneStateListener.LISTEN_NONE);
mSwitchBar.removeOnSwitchChangeListener(this); mSwitchBar.removeOnSwitchChangeListener(this);
} }

View File

@@ -351,5 +351,13 @@ public class WifiCallingSettingsForSubTest {
return null; return null;
} }
} }
@Override
TelephonyManager getTelephonyManagerForSub(int subId) {
return mTelephonyManager;
}
@Override
void showAlert(Intent intent) {}
} }
} }