[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();
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);
}

View File

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