Merge "Make ApnEditor can show the customized default value on UI." into rvc-dev am: 49b82f8532

Change-Id: I46f5143cde953050041a7b238cb0fa9a856978d7
This commit is contained in:
Tom Hsu
2020-04-22 12:23:04 +00:00
committed by Automerger Merge Worker
2 changed files with 53 additions and 47 deletions

View File

@@ -68,6 +68,7 @@ public class ApnEditor extends SettingsPreferenceFragment
private final static boolean VDBG = false; // STOPSHIP if true
private final static String KEY_AUTH_TYPE = "auth_type";
private static final String KEY_APN_TYPE = "apn_type";
private final static String KEY_PROTOCOL = "apn_protocol";
private final static String KEY_ROAMING_PROTOCOL = "apn_roaming_protocol";
private final static String KEY_CARRIER_ENABLED = "carrier_enabled";
@@ -344,6 +345,7 @@ public class ApnEditor extends SettingsPreferenceFragment
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
fillUI(savedInstanceState == null);
setCarrierCustomizedConfigToUi();
}
@VisibleForTesting
@@ -645,7 +647,9 @@ public class ApnEditor extends SettingsPreferenceFragment
* return null.
*/
private String protocolDescription(String raw, ListPreference protocol) {
final int protocolIndex = protocol.findIndexOfValue(raw);
String uRaw = checkNull(raw).toUpperCase();
uRaw = uRaw.equals("IPV4") ? "IP" : uRaw;
final int protocolIndex = protocol.findIndexOfValue(uRaw);
if (protocolIndex == -1) {
return null;
} else {
@@ -745,6 +749,13 @@ public class ApnEditor extends SettingsPreferenceFragment
} catch (NumberFormatException e) {
return false;
}
} else if (KEY_APN_TYPE.equals(key)) {
String data = (TextUtils.isEmpty((String) newValue)
&& !ArrayUtils.isEmpty(mDefaultApnTypes))
? getEditableApnType(mDefaultApnTypes) : (String) newValue;
if (!TextUtils.isEmpty(data)) {
mApnType.setSummary(data);
}
} else if (KEY_PROTOCOL.equals(key)) {
final String protocol = protocolDescription((String) newValue, mProtocol);
if (protocol == null) {
@@ -780,7 +791,6 @@ public class ApnEditor extends SettingsPreferenceFragment
} else {
preference.setSummary(checkNull(newValue != null ? String.valueOf(newValue) : null));
}
return true;
}
@@ -1002,13 +1012,13 @@ public class ApnEditor extends SettingsPreferenceFragment
callUpdate = setStringValueAndCheckIfDiff(values,
Telephony.Carriers.PROTOCOL,
getUserEnteredApnProtocol(mProtocol, mDefaultApnProtocol),
checkNotSet(mProtocol.getValue()),
callUpdate,
PROTOCOL_INDEX);
callUpdate = setStringValueAndCheckIfDiff(values,
Telephony.Carriers.ROAMING_PROTOCOL,
getUserEnteredApnProtocol(mRoamingProtocol, mDefaultApnRoamingProtocol),
checkNotSet(mRoamingProtocol.getValue()),
callUpdate,
ROAMING_PROTOCOL_INDEX);
@@ -1204,17 +1214,6 @@ public class ApnEditor extends SettingsPreferenceFragment
return sNotSet.equals(value) ? null : value;
}
@VisibleForTesting
String getUserEnteredApnProtocol(ListPreference preference, String defaultApnProtocol) {
// if user has not specified a protocol or enter empty type, map it just for default
final String userEnteredApnProtocol = checkNotSet(
((preference == null) ? null : preference.getValue()));
if (TextUtils.isEmpty(userEnteredApnProtocol)) {
return defaultApnProtocol;
}
return userEnteredApnProtocol.trim();
}
@VisibleForTesting
String getUserEnteredApnType() {
// if user has not specified a type, map it to "ALL APN TYPES THAT ARE NOT READ-ONLY"
@@ -1222,16 +1221,11 @@ public class ApnEditor extends SettingsPreferenceFragment
String userEnteredApnType = mApnType.getText();
if (userEnteredApnType != null) userEnteredApnType = userEnteredApnType.trim();
if ((TextUtils.isEmpty(userEnteredApnType)
|| APN_TYPE_ALL.equals(userEnteredApnType))
&& !ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
String[] apnTypeList = APN_TYPES;
if (TextUtils.isEmpty(userEnteredApnType) && !ArrayUtils.isEmpty(mDefaultApnTypes)) {
apnTypeList = mDefaultApnTypes;
}
userEnteredApnType = getEditableApnType(apnTypeList);
Log.d(TAG, "getUserEnteredApnType: changed apn type to editable apn types: "
+ userEnteredApnType);
|| APN_TYPE_ALL.equals(userEnteredApnType))) {
userEnteredApnType = getEditableApnType(APN_TYPES);
}
Log.d(TAG, "getUserEnteredApnType: changed apn type to editable apn types: "
+ userEnteredApnType);
return userEnteredApnType;
}
@@ -1324,6 +1318,26 @@ public class ApnEditor extends SettingsPreferenceFragment
}
}
private void setCarrierCustomizedConfigToUi() {
if (TextUtils.isEmpty(mApnType.getText()) && !ArrayUtils.isEmpty(mDefaultApnTypes)) {
String value = getEditableApnType(mDefaultApnTypes);
mApnType.setText(value);
mApnType.setSummary(value);
}
String protocol = protocolDescription(mDefaultApnProtocol, mProtocol);
if (TextUtils.isEmpty(mProtocol.getValue()) && !TextUtils.isEmpty(protocol)) {
mProtocol.setValue(mDefaultApnProtocol);
mProtocol.setSummary(protocol);
}
String roamingProtocol = protocolDescription(mDefaultApnRoamingProtocol, mRoamingProtocol);
if (TextUtils.isEmpty(mRoamingProtocol.getValue()) && !TextUtils.isEmpty(roamingProtocol)) {
mRoamingProtocol.setValue(mDefaultApnRoamingProtocol);
mRoamingProtocol.setSummary(roamingProtocol);
}
}
public static class ErrorDialog extends InstrumentedDialogFragment {
public static void showError(ApnEditor editor) {