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

Commit ae7b0b09 authored by SongFerng Wang's avatar SongFerng Wang Committed by Android (Google) Code Review
Browse files

Merge "Add try-catch for set/get wifiCalling mode" into main

parents 5036a9cb 5ce87cb0
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
    PhoneAccountHandle mSimCallManager;
    private PhoneTelephonyCallback mTelephonyCallback;
    private Preference mPreference;
    private boolean mHasException;

    public WifiCallingPreferenceController(Context context, String key) {
        super(context, key);
@@ -103,6 +104,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
            Log.d(TAG, "Skip update under mCallState=" + mCallState);
            return;
        }
        mHasException = false;
        CharSequence summaryText = null;
        if (mSimCallManager != null) {
            final Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
@@ -122,7 +124,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
            summaryText = getResourceIdForWfcMode(mSubId);
        }
        preference.setSummary(summaryText);
        preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE);
        preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE && !mHasException);
    }

    private CharSequence getResourceIdForWfcMode(int subId) {
@@ -140,9 +142,16 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
            }
            final boolean isRoaming = getTelephonyManager(mContext, subId)
                    .isNetworkRoaming();
            final int wfcMode = (isRoaming && !useWfcHomeModeForRoaming)
            int wfcMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
            try {
                wfcMode = (isRoaming && !useWfcHomeModeForRoaming)
                        ? mImsMmTelManager.getVoWiFiRoamingModeSetting() :
                        mImsMmTelManager.getVoWiFiModeSetting();
            } catch (IllegalArgumentException e) {
                mHasException = true;
                Log.e(TAG, "getResourceIdForWfcMode: Exception", e);
            }

            switch (wfcMode) {
                case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
                    resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
+67 −23
Original line number Diff line number Diff line
@@ -409,11 +409,19 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
        final boolean wfcEnabled = queryIms.isEnabledByUser()
                && queryIms.isAllowUserControl();
        mSwitchBar.setChecked(wfcEnabled);
        final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting();
        final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
        int wfcMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
        int wfcRoamingMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
        boolean hasException = false;
        try {
            wfcMode = mImsMmTelManager.getVoWiFiModeSetting();
            wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
        } catch (IllegalArgumentException e) {
            hasException = true;
            Log.e(TAG, "getResourceIdForWfcMode: Exception", e);
        }
        mButtonWfcMode.setValue(Integer.toString(wfcMode));
        mButtonWfcRoamingMode.setValue(Integer.toString(wfcRoamingMode));
        updateButtonWfcMode(wfcEnabled, wfcMode, wfcRoamingMode);
        updateButtonWfcMode(wfcEnabled && !hasException, wfcMode, wfcRoamingMode);
    }

    @Override
@@ -508,11 +516,26 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
     */
    private void updateWfcMode(boolean wfcEnabled) {
        Log.i(TAG, "updateWfcMode(" + wfcEnabled + ")");
        boolean hasException = false;
        try {
            mImsMmTelManager.setVoWiFiSettingEnabled(wfcEnabled);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "updateWfcMode: Exception", e);
            hasException = true;
        }

        final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting();
        final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
        updateButtonWfcMode(wfcEnabled, wfcMode, wfcRoamingMode);
        int wfcMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
        int wfcRoamingMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
        if (!hasException) {
            try {
                wfcMode = mImsMmTelManager.getVoWiFiModeSetting();
                wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
            } catch (IllegalArgumentException e) {
                hasException = true;
                Log.e(TAG, "updateWfcMode: Exception", e);
            }
        }
        updateButtonWfcMode(wfcEnabled && !hasException, wfcMode, wfcRoamingMode);
        if (wfcEnabled) {
            mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), wfcMode);
        } else {
@@ -523,9 +546,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        Log.d(TAG, "WFC activity request = " + requestCode + " result = " + resultCode);

        switch (requestCode) {
            case REQUEST_CHECK_WFC_EMERGENCY_ADDRESS:
                if (resultCode == Activity.RESULT_OK) {
@@ -594,12 +615,21 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        boolean hasException = false;

        if (preference == mButtonWfcMode) {
            Log.d(TAG, "onPreferenceChange mButtonWfcMode " + newValue);
            mButtonWfcMode.setValue((String) newValue);
            final int buttonMode = Integer.valueOf((String) newValue);
            final int currentWfcMode = mImsMmTelManager.getVoWiFiModeSetting();
            if (buttonMode != currentWfcMode) {
            int currentWfcMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
            try {
                currentWfcMode = mImsMmTelManager.getVoWiFiModeSetting();
            } catch (IllegalArgumentException e) {
                hasException = true;
                Log.e(TAG, "onPreferenceChange: Exception", e);
            }
            if (buttonMode != currentWfcMode && !hasException) {
                try {
                    mImsMmTelManager.setVoWiFiModeSetting(buttonMode);
                    mButtonWfcMode.setSummary(getWfcModeSummary(buttonMode));
                    mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode);
@@ -608,15 +638,29 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
                        mImsMmTelManager.setVoWiFiRoamingModeSetting(buttonMode);
                        // mButtonWfcRoamingMode.setSummary is not needed; summary is selected value
                    }
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "onPreferenceChange: Exception", e);
                }
            }
        } else if (preference == mButtonWfcRoamingMode) {
            mButtonWfcRoamingMode.setValue((String) newValue);
            final int buttonMode = Integer.valueOf((String) newValue);
            final int currentMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
            if (buttonMode != currentMode) {
            int currentMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
            try {
                currentMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
            } catch (IllegalArgumentException e) {
                hasException = true;
                Log.e(TAG, "updateWfcMode: Exception", e);
            }
            if (buttonMode != currentMode && !hasException) {
                try {
                    mImsMmTelManager.setVoWiFiRoamingModeSetting(buttonMode);
                // mButtonWfcRoamingMode.setSummary is not needed; summary is just selected value.
                    // mButtonWfcRoamingMode.setSummary is not needed; summary is just selected
                    // value.
                    mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode);
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "onPreferenceChange: Exception", e);
                }
            }
        }
        return true;
+25 −4
Original line number Diff line number Diff line
@@ -349,7 +349,13 @@ public class WifiCallingSliceHelper {
        final FutureTask<Integer> wfcModeTask = new FutureTask<>(new Callable<Integer>() {
            @Override
            public Integer call() {
                return imsMmTelManager.getVoWiFiModeSetting();
                int wfcMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
                try {
                    wfcMode = imsMmTelManager.getVoWiFiModeSetting();
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "getResourceIdForWfcMode: Exception", e);
                }
                return wfcMode;
            }
        });
        final ExecutorService executor = Executors.newSingleThreadExecutor();
@@ -381,7 +387,11 @@ public class WifiCallingSliceHelper {
                    // If either the action is to turn off wifi calling setting
                    // or there is no activation involved - Update the setting
                    final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
                    try {
                        imsMmTelManager.setVoWiFiSettingEnabled(newValue);
                    } catch (IllegalArgumentException e) {
                        Log.e(TAG, "handleWifiCallingChanged: Exception", e);
                    }
                } else {
                    Log.w(TAG, "action not taken: subId " + subId
                            + " from " + currentValue + " to " + newValue);
@@ -425,7 +435,14 @@ public class WifiCallingSliceHelper {
                // Change the preference only when wifi calling is enabled
                // And when wifi calling preference is editable for the current carrier
                final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
                final int currentValue = imsMmTelManager.getVoWiFiModeSetting();
                int currentValue = ImsMmTelManager.WIFI_MODE_UNKNOWN;
                try {
                    currentValue = imsMmTelManager.getVoWiFiModeSetting();
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "handleWifiCallingPreferenceChanged: Exception", e);
                    return;
                }

                int newValue = errorValue;
                switch (intent.getAction()) {
                    case ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY:
@@ -443,7 +460,11 @@ public class WifiCallingSliceHelper {
                }
                if (newValue != errorValue && newValue != currentValue) {
                    // Update the setting only when there is a valid update
                    try {
                        imsMmTelManager.setVoWiFiModeSetting(newValue);
                    } catch (IllegalArgumentException e) {
                        Log.e(TAG, "handleWifiCallingPreferenceChanged: Exception", e);
                    }
                }
            }
        }