Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 268bdc12 authored by Bonian Chen's avatar Bonian Chen Committed by Android (Google) Code Review
Browse files

Merge "[Settings] Code Refactor" into rvc-dev

parents cd329951 21475ae6
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -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);
        }
+8 −0
Original line number Diff line number Diff line
@@ -351,5 +351,13 @@ public class WifiCallingSettingsForSubTest {
                    return null;
            }
        }

        @Override
        TelephonyManager getTelephonyManagerForSub(int subId) {
            return mTelephonyManager;
        }

        @Override
        void showAlert(Intent intent) {}
    }
}