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

This commit is contained in:
SongFerng Wang
2023-10-24 06:40:24 +00:00
committed by Android (Google) Code Review
3 changed files with 104 additions and 30 deletions

View File

@@ -61,6 +61,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
PhoneAccountHandle mSimCallManager; PhoneAccountHandle mSimCallManager;
private PhoneTelephonyCallback mTelephonyCallback; private PhoneTelephonyCallback mTelephonyCallback;
private Preference mPreference; private Preference mPreference;
private boolean mHasException;
public WifiCallingPreferenceController(Context context, String key) { public WifiCallingPreferenceController(Context context, String key) {
super(context, key); super(context, key);
@@ -103,6 +104,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
Log.d(TAG, "Skip update under mCallState=" + mCallState); Log.d(TAG, "Skip update under mCallState=" + mCallState);
return; return;
} }
mHasException = false;
CharSequence summaryText = null; CharSequence summaryText = null;
if (mSimCallManager != null) { if (mSimCallManager != null) {
final Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext, final Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
@@ -122,7 +124,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
summaryText = getResourceIdForWfcMode(mSubId); summaryText = getResourceIdForWfcMode(mSubId);
} }
preference.setSummary(summaryText); preference.setSummary(summaryText);
preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE); preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE && !mHasException);
} }
private CharSequence getResourceIdForWfcMode(int subId) { private CharSequence getResourceIdForWfcMode(int subId) {
@@ -140,9 +142,16 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
} }
final boolean isRoaming = getTelephonyManager(mContext, subId) final boolean isRoaming = getTelephonyManager(mContext, subId)
.isNetworkRoaming(); .isNetworkRoaming();
final int wfcMode = (isRoaming && !useWfcHomeModeForRoaming) int wfcMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
? mImsMmTelManager.getVoWiFiRoamingModeSetting() : try {
mImsMmTelManager.getVoWiFiModeSetting(); wfcMode = (isRoaming && !useWfcHomeModeForRoaming)
? mImsMmTelManager.getVoWiFiRoamingModeSetting() :
mImsMmTelManager.getVoWiFiModeSetting();
} catch (IllegalArgumentException e) {
mHasException = true;
Log.e(TAG, "getResourceIdForWfcMode: Exception", e);
}
switch (wfcMode) { switch (wfcMode) {
case ImsMmTelManager.WIFI_MODE_WIFI_ONLY: case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
resId = com.android.internal.R.string.wfc_mode_wifi_only_summary; resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;

View File

@@ -409,11 +409,19 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
final boolean wfcEnabled = queryIms.isEnabledByUser() final boolean wfcEnabled = queryIms.isEnabledByUser()
&& queryIms.isAllowUserControl(); && queryIms.isAllowUserControl();
mSwitchBar.setChecked(wfcEnabled); mSwitchBar.setChecked(wfcEnabled);
final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting(); int wfcMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting(); 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)); mButtonWfcMode.setValue(Integer.toString(wfcMode));
mButtonWfcRoamingMode.setValue(Integer.toString(wfcRoamingMode)); mButtonWfcRoamingMode.setValue(Integer.toString(wfcRoamingMode));
updateButtonWfcMode(wfcEnabled, wfcMode, wfcRoamingMode); updateButtonWfcMode(wfcEnabled && !hasException, wfcMode, wfcRoamingMode);
} }
@Override @Override
@@ -508,11 +516,26 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
*/ */
private void updateWfcMode(boolean wfcEnabled) { private void updateWfcMode(boolean wfcEnabled) {
Log.i(TAG, "updateWfcMode(" + wfcEnabled + ")"); Log.i(TAG, "updateWfcMode(" + wfcEnabled + ")");
mImsMmTelManager.setVoWiFiSettingEnabled(wfcEnabled); boolean hasException = false;
try {
mImsMmTelManager.setVoWiFiSettingEnabled(wfcEnabled);
} catch (IllegalArgumentException e) {
Log.e(TAG, "updateWfcMode: Exception", e);
hasException = true;
}
final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting(); int wfcMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting(); int wfcRoamingMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
updateButtonWfcMode(wfcEnabled, wfcMode, wfcRoamingMode); 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) { if (wfcEnabled) {
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), wfcMode); mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), wfcMode);
} else { } else {
@@ -523,9 +546,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "WFC activity request = " + requestCode + " result = " + resultCode); Log.d(TAG, "WFC activity request = " + requestCode + " result = " + resultCode);
switch (requestCode) { switch (requestCode) {
case REQUEST_CHECK_WFC_EMERGENCY_ADDRESS: case REQUEST_CHECK_WFC_EMERGENCY_ADDRESS:
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
@@ -594,29 +615,52 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean hasException = false;
if (preference == mButtonWfcMode) { if (preference == mButtonWfcMode) {
Log.d(TAG, "onPreferenceChange mButtonWfcMode " + newValue); Log.d(TAG, "onPreferenceChange mButtonWfcMode " + newValue);
mButtonWfcMode.setValue((String) newValue); mButtonWfcMode.setValue((String) newValue);
final int buttonMode = Integer.valueOf((String) newValue); final int buttonMode = Integer.valueOf((String) newValue);
final int currentWfcMode = mImsMmTelManager.getVoWiFiModeSetting(); int currentWfcMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
if (buttonMode != currentWfcMode) { try {
mImsMmTelManager.setVoWiFiModeSetting(buttonMode); currentWfcMode = mImsMmTelManager.getVoWiFiModeSetting();
mButtonWfcMode.setSummary(getWfcModeSummary(buttonMode)); } catch (IllegalArgumentException e) {
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode); 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);
if (mUseWfcHomeModeForRoaming) { if (mUseWfcHomeModeForRoaming) {
mImsMmTelManager.setVoWiFiRoamingModeSetting(buttonMode); mImsMmTelManager.setVoWiFiRoamingModeSetting(buttonMode);
// mButtonWfcRoamingMode.setSummary is not needed; summary is selected value // mButtonWfcRoamingMode.setSummary is not needed; summary is selected value
}
} catch (IllegalArgumentException e) {
Log.e(TAG, "onPreferenceChange: Exception", e);
} }
} }
} else if (preference == mButtonWfcRoamingMode) { } else if (preference == mButtonWfcRoamingMode) {
mButtonWfcRoamingMode.setValue((String) newValue); mButtonWfcRoamingMode.setValue((String) newValue);
final int buttonMode = Integer.valueOf((String) newValue); final int buttonMode = Integer.valueOf((String) newValue);
final int currentMode = mImsMmTelManager.getVoWiFiRoamingModeSetting(); int currentMode = ImsMmTelManager.WIFI_MODE_UNKNOWN;
if (buttonMode != currentMode) { try {
mImsMmTelManager.setVoWiFiRoamingModeSetting(buttonMode); currentMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();
// mButtonWfcRoamingMode.setSummary is not needed; summary is just selected value. } catch (IllegalArgumentException e) {
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode); 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.
mMetricsFeatureProvider.action(getActivity(), getMetricsCategory(), buttonMode);
} catch (IllegalArgumentException e) {
Log.e(TAG, "onPreferenceChange: Exception", e);
}
} }
} }
return true; return true;

View File

@@ -349,7 +349,13 @@ public class WifiCallingSliceHelper {
final FutureTask<Integer> wfcModeTask = new FutureTask<>(new Callable<Integer>() { final FutureTask<Integer> wfcModeTask = new FutureTask<>(new Callable<Integer>() {
@Override @Override
public Integer call() { 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(); final ExecutorService executor = Executors.newSingleThreadExecutor();
@@ -381,7 +387,11 @@ public class WifiCallingSliceHelper {
// If either the action is to turn off wifi calling setting // If either the action is to turn off wifi calling setting
// or there is no activation involved - Update the setting // or there is no activation involved - Update the setting
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId); final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
imsMmTelManager.setVoWiFiSettingEnabled(newValue); try {
imsMmTelManager.setVoWiFiSettingEnabled(newValue);
} catch (IllegalArgumentException e) {
Log.e(TAG, "handleWifiCallingChanged: Exception", e);
}
} else { } else {
Log.w(TAG, "action not taken: subId " + subId Log.w(TAG, "action not taken: subId " + subId
+ " from " + currentValue + " to " + newValue); + " from " + currentValue + " to " + newValue);
@@ -425,7 +435,14 @@ public class WifiCallingSliceHelper {
// Change the preference only when wifi calling is enabled // Change the preference only when wifi calling is enabled
// And when wifi calling preference is editable for the current carrier // And when wifi calling preference is editable for the current carrier
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId); 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; int newValue = errorValue;
switch (intent.getAction()) { switch (intent.getAction()) {
case ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY: case ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY:
@@ -443,7 +460,11 @@ public class WifiCallingSliceHelper {
} }
if (newValue != errorValue && newValue != currentValue) { if (newValue != errorValue && newValue != currentValue) {
// Update the setting only when there is a valid update // Update the setting only when there is a valid update
imsMmTelManager.setVoWiFiModeSetting(newValue); try {
imsMmTelManager.setVoWiFiModeSetting(newValue);
} catch (IllegalArgumentException e) {
Log.e(TAG, "handleWifiCallingPreferenceChanged: Exception", e);
}
} }
} }
} }