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

Commit fe3749dd authored by Meng Wang's avatar Meng Wang
Browse files

WiFiCallingSettings: show roaming preferrence

Bug: 31492826
Change-Id: I45cd8455e84802d690d074099d6a8e9c9398e157
parent 2dc974a6
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -1983,15 +1983,26 @@
    <string name="wifi_calling_suggestion_title">Turn on Wi-Fi Calling</string>
    <!-- Summary of suggestion to turn on wifi calling [CHAR LIMIT=60] -->
    <string name="wifi_calling_suggestion_summary">Use Wi-Fi instead of mobile network</string>
    <!-- WFC mode [CHAR LIMIT=30] -->
    <!-- Title of WFC preference item [CHAR LIMIT=30] -->
    <string name="wifi_calling_mode_title">Calling preference</string>
    <!-- WFC mode dialog [CHAR LIMIT=30] -->
    <!-- Title of WFC preference selection dialog [CHAR LIMIT=30] -->
    <string name="wifi_calling_mode_dialog_title">Wi-Fi calling mode</string>
    <!-- Title of WFC roaming preference item [CHAR LIMIT=45] -->
    <string name="wifi_calling_roaming_mode_title">Roaming preference</string>
    <!-- Summary of WFC roaming preference item [CHAR LIMIT=NONE]-->
    <string name="wifi_calling_roaming_mode_summary"><xliff:g id="wfc_roaming_preference" example="Wi-Fi">%1$s</xliff:g></string>
    <!-- WFC mode dialog [CHAR LIMIT=45] -->
    <string name="wifi_calling_roaming_mode_dialog_title">Roaming preference</string>
    <string-array name="wifi_calling_mode_choices">
        <item>Wi-Fi preferred</item>
        <item>Cellular preferred</item>
        <item>Wi-Fi only</item>
    </string-array>
    <string-array name="wifi_calling_mode_choices_v2">
        <item>Wi-Fi</item>
        <item>Cellular</item>
        <item>Wi-Fi only</item>
    </string-array>
    <string-array name="wifi_calling_mode_values">
        <item>"2"</item>
        <item>"1"</item>
@@ -2001,13 +2012,19 @@
        <item>Wi-Fi preferred</item>
        <item>Cellular preferred</item>
    </string-array>
    <string-array name="wifi_calling_mode_choices_v2_without_wifi_only">
        <item>Wi-Fi</item>
        <item>Cellular</item>
    </string-array>
    <string-array name="wifi_calling_mode_values_without_wifi_only">
        <item>"2"</item>
        <item>"1"</item>
    </string-array>
    <!-- Wi-Fi Calling settings. Text displayed when Wi-Fi Calling is off -->
    <string name="wifi_calling_off_explanation">When Wi-Fi calling is on, your phone can route calls via Wi-Fi networks or your carrier\u2019s network, depending on your preference and which signal is stronger. Before turning on this feature, check with your carrier regarding fees and other details.</string>
    <!-- Title of a preference for updating emergency address [CHAR LIMIT=40] -->
    <string name="emergency_address_title">Update Emergency Address</string>
    <!-- Summary of Update Emergency Address preference, explaining usage of emergency address [CHAR LIMIT=NONE] -->
    <string name="emergency_address_summary">Address used by emergency services as your location if you make a 911 call using WiFi</string>
+11 −4
Original line number Diff line number Diff line
@@ -26,10 +26,17 @@
            android:entryValues="@array/wifi_calling_mode_values"
            android:dialogTitle="@string/wifi_calling_mode_dialog_title" />

    <ListPreference
            android:key="wifi_calling_roaming_mode"
            android:title="@string/wifi_calling_roaming_mode_title"
            android:summary="@string/wifi_calling_roaming_mode_summary"
            android:entries="@array/wifi_calling_mode_choices_v2"
            android:entryValues="@array/wifi_calling_mode_values"
            android:dialogTitle="@string/wifi_calling_roaming_mode_dialog_title" />

    <Preference
            android:key="emergency_address_key"
            android:title="@string/emergency_address_title"
        android:summary="@string/emergency_address_summary">
    </Preference>
            android:summary="@string/emergency_address_summary" />

</PreferenceScreen>
+70 −22
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public class WifiCallingSettings extends SettingsPreferenceFragment

    //String keys for preference lookup
    private static final String BUTTON_WFC_MODE = "wifi_calling_mode";
    private static final String BUTTON_WFC_ROAMING_MODE = "wifi_calling_roaming_mode";
    private static final String PREFERENCE_EMERGENCY_ADDRESS = "emergency_address_key";

    private static final int REQUEST_CHECK_WFC_EMERGENCY_ADDRESS = 1;
@@ -69,11 +70,13 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
    private SwitchBar mSwitchBar;
    private Switch mSwitch;
    private ListPreference mButtonWfcMode;
    private ListPreference mButtonWfcRoamingMode;
    private Preference mUpdateAddress;
    private TextView mEmptyView;

    private boolean mValidListener = false;
    private boolean mEditableWfcMode = true;
    private boolean mEditableWfcRoamingMode = true;

    private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
        /*
@@ -94,25 +97,32 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
            switchBar.setEnabled((state == TelephonyManager.CALL_STATE_IDLE)
                    && isNonTtyOrTtyOnVolteEnabled);

            Preference pref = getPreferenceScreen().findPreference(BUTTON_WFC_MODE);
            if (pref != null) {
                pref.setEnabled(isWfcEnabled && getEditableWfcMode(activity)
                        && (state == TelephonyManager.CALL_STATE_IDLE));
            }
        }
    };

    private static boolean getEditableWfcMode(Context context) {
        CarrierConfigManager configManager = (CarrierConfigManager)
                context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
            boolean isWfcModeEditable = true;
            boolean isWfcRoamingModeEditable = false;
            final CarrierConfigManager configManager = (CarrierConfigManager)
                    activity.getSystemService(Context.CARRIER_CONFIG_SERVICE);
            if (configManager != null) {
                PersistableBundle b = configManager.getConfig();
                if (b != null) {
                return b.getBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL);
                    isWfcModeEditable = b.getBoolean(
                            CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL);
                    isWfcRoamingModeEditable = b.getBoolean(
                            CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL);
                }
            }
        return true;

            Preference pref = getPreferenceScreen().findPreference(BUTTON_WFC_MODE);
            if (pref != null) {
                pref.setEnabled(isWfcEnabled && isWfcModeEditable
                        && (state == TelephonyManager.CALL_STATE_IDLE));
            }
            Preference pref_roam = getPreferenceScreen().findPreference(BUTTON_WFC_ROAMING_MODE);
            if (pref_roam != null) {
                pref_roam.setEnabled(isWfcEnabled && isWfcRoamingModeEditable
                        && (state == TelephonyManager.CALL_STATE_IDLE));
            }
        }
    };

    private final OnPreferenceClickListener mUpdateAddressListener =
            new OnPreferenceClickListener() {
@@ -204,6 +214,9 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
        mButtonWfcMode = (ListPreference) findPreference(BUTTON_WFC_MODE);
        mButtonWfcMode.setOnPreferenceChangeListener(this);

        mButtonWfcRoamingMode = (ListPreference) findPreference(BUTTON_WFC_ROAMING_MODE);
        mButtonWfcRoamingMode.setOnPreferenceChangeListener(this);

        mUpdateAddress = (Preference) findPreference(PREFERENCE_EMERGENCY_ADDRESS);
        mUpdateAddress.setOnPreferenceClickListener(mUpdateAddressListener);

@@ -217,6 +230,8 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
            PersistableBundle b = configManager.getConfig();
            if (b != null) {
                mEditableWfcMode = b.getBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL);
                mEditableWfcRoamingMode = b.getBoolean(
                        CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL);
                isWifiOnlySupported = b.getBoolean(
                        CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, true);
            }
@@ -225,6 +240,10 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
        if (!isWifiOnlySupported) {
            mButtonWfcMode.setEntries(R.array.wifi_calling_mode_choices_without_wifi_only);
            mButtonWfcMode.setEntryValues(R.array.wifi_calling_mode_values_without_wifi_only);
            mButtonWfcRoamingMode.setEntries(
                    R.array.wifi_calling_mode_choices_v2_without_wifi_only);
            mButtonWfcRoamingMode.setEntryValues(
                    R.array.wifi_calling_mode_values_without_wifi_only);
        }
    }

@@ -247,9 +266,11 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
        boolean wfcEnabled = ImsManager.isWfcEnabledByUser(context)
                && ImsManager.isNonTtyOrTtyOnVolteEnabled(context);
        mSwitch.setChecked(wfcEnabled);
        int wfcMode = ImsManager.getWfcMode(context);
        int wfcMode = ImsManager.getWfcMode(context, false);
        int wfcRoamingMode = ImsManager.getWfcMode(context, true);
        mButtonWfcMode.setValue(Integer.toString(wfcMode));
        updateButtonWfcMode(context, wfcEnabled, wfcMode);
        mButtonWfcRoamingMode.setValue(Integer.toString(wfcRoamingMode));
        updateButtonWfcMode(context, wfcEnabled, wfcMode, wfcRoamingMode);

        context.registerReceiver(mIntentReceiver, mIntentFilter);

@@ -332,8 +353,9 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
        Log.i(TAG, "updateWfcMode(" + wfcEnabled + ")");
        ImsManager.setWfcSetting(context, wfcEnabled);

        int wfcMode = ImsManager.getWfcMode(context);
        updateButtonWfcMode(context, wfcEnabled, wfcMode);
        int wfcMode = ImsManager.getWfcMode(context, false);
        int wfcRoamingMode = ImsManager.getWfcMode(context, true);
        updateButtonWfcMode(context, wfcEnabled, wfcMode, wfcRoamingMode);
        if (wfcEnabled) {
            MetricsLogger.action(getActivity(), getMetricsCategory(), wfcMode);
        } else {
@@ -356,9 +378,12 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
        }
    }

    private void updateButtonWfcMode(Context context, boolean wfcEnabled, int wfcMode) {
    private void updateButtonWfcMode(Context context, boolean wfcEnabled,
                                     int wfcMode, int wfcRoamingMode) {
        mButtonWfcMode.setSummary(getWfcModeSummary(context, wfcMode));
        mButtonWfcMode.setEnabled(wfcEnabled && mEditableWfcMode);
        // mButtonWfcRoamingMode.setSummary is not needed; summary is just selected value.
        mButtonWfcRoamingMode.setEnabled(wfcEnabled && mEditableWfcRoamingMode);

        final PreferenceScreen preferenceScreen = getPreferenceScreen();
        boolean updateAddressEnabled = (getCarrierActivityIntent(context) != null);
@@ -366,9 +391,15 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
            if (mEditableWfcMode) {
                preferenceScreen.addPreference(mButtonWfcMode);
            } else {
                // Don't show WFC mode preference if it's not editable.
                // Don't show WFC (home) preference if it's not editable.
                preferenceScreen.removePreference(mButtonWfcMode);
            }
            if (mEditableWfcRoamingMode) {
                preferenceScreen.addPreference(mButtonWfcRoamingMode);
            } else {
                // Don't show WFC roaming preference if it's not editable.
                preferenceScreen.removePreference(mButtonWfcRoamingMode);
            }
            if (updateAddressEnabled) {
                preferenceScreen.addPreference(mUpdateAddress);
            } else {
@@ -376,6 +407,7 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
            }
        } else {
            preferenceScreen.removePreference(mButtonWfcMode);
            preferenceScreen.removePreference(mButtonWfcRoamingMode);
            preferenceScreen.removePreference(mUpdateAddress);
        }
    }
@@ -386,12 +418,28 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
        if (preference == mButtonWfcMode) {
            mButtonWfcMode.setValue((String) newValue);
            int buttonMode = Integer.valueOf((String) newValue);
            int currentMode = ImsManager.getWfcMode(context);
            if (buttonMode != currentMode) {
                ImsManager.setWfcMode(context, buttonMode);
            int currentWfcMode = ImsManager.getWfcMode(context, false);
            if (buttonMode != currentWfcMode) {
                ImsManager.setWfcMode(context, buttonMode, false);
                mButtonWfcMode.setSummary(getWfcModeSummary(context, buttonMode));
                MetricsLogger.action(getActivity(), getMetricsCategory(), buttonMode);
            }
            if (!mEditableWfcRoamingMode) {
                int currentWfcRoamingMode = ImsManager.getWfcMode(context, true);
                if (buttonMode != currentWfcRoamingMode) {
                    ImsManager.setWfcMode(context, buttonMode, true);
                    // mButtonWfcRoamingMode.setSummary is not needed; summary is selected value
                }
            }
        } else if (preference == mButtonWfcRoamingMode) {
            mButtonWfcRoamingMode.setValue((String) newValue);
            int buttonMode = Integer.valueOf((String) newValue);
            int currentMode = ImsManager.getWfcMode(context, true);
            if (buttonMode != currentMode) {
                ImsManager.setWfcMode(context, buttonMode, true);
                // mButtonWfcRoamingMode.setSummary is not needed; summary is just selected value.
                MetricsLogger.action(getActivity(), getMetricsCategory(), buttonMode);
            }
        }
        return true;
    }
+1 −1
Original line number Diff line number Diff line
@@ -362,7 +362,7 @@ public class WirelessSettings extends SettingsPreferenceFragment implements Inde
            getPreferenceScreen().addPreference(mButtonWfc);

            mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
                    context, ImsManager.getWfcMode(context)));
                    context, ImsManager.getWfcMode(context, mTm.isNetworkRoaming())));
        } else {
            removePreference(KEY_WFC_SETTINGS);
        }