Make ApnEditor can show the customized default value on UI.
- Edittext on edittextpreference - Summary on edittextpreference Bug: 142440775 Test: make RunSettingsRoboTests ROBOTEST_FILTER=ApnEditorTest -j Test: Sanity test pass with customized carrier data - data in summary and text of edittext preference correctly correctly display on. Change-Id: I3162de19659df79c5873c730d7d32e4ed998bcbe
This commit is contained in:
@@ -68,6 +68,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
private final static boolean VDBG = false; // STOPSHIP if true
|
private final static boolean VDBG = false; // STOPSHIP if true
|
||||||
|
|
||||||
private final static String KEY_AUTH_TYPE = "auth_type";
|
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_PROTOCOL = "apn_protocol";
|
||||||
private final static String KEY_ROAMING_PROTOCOL = "apn_roaming_protocol";
|
private final static String KEY_ROAMING_PROTOCOL = "apn_roaming_protocol";
|
||||||
private final static String KEY_CARRIER_ENABLED = "carrier_enabled";
|
private final static String KEY_CARRIER_ENABLED = "carrier_enabled";
|
||||||
@@ -344,6 +345,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
|
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
|
||||||
super.onViewStateRestored(savedInstanceState);
|
super.onViewStateRestored(savedInstanceState);
|
||||||
fillUI(savedInstanceState == null);
|
fillUI(savedInstanceState == null);
|
||||||
|
setCarrierCustomizedConfigToUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -645,7 +647,9 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
* return null.
|
* return null.
|
||||||
*/
|
*/
|
||||||
private String protocolDescription(String raw, ListPreference protocol) {
|
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) {
|
if (protocolIndex == -1) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
@@ -745,6 +749,13 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
return false;
|
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)) {
|
} else if (KEY_PROTOCOL.equals(key)) {
|
||||||
final String protocol = protocolDescription((String) newValue, mProtocol);
|
final String protocol = protocolDescription((String) newValue, mProtocol);
|
||||||
if (protocol == null) {
|
if (protocol == null) {
|
||||||
@@ -780,7 +791,6 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
} else {
|
} else {
|
||||||
preference.setSummary(checkNull(newValue != null ? String.valueOf(newValue) : null));
|
preference.setSummary(checkNull(newValue != null ? String.valueOf(newValue) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1002,13 +1012,13 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
callUpdate = setStringValueAndCheckIfDiff(values,
|
callUpdate = setStringValueAndCheckIfDiff(values,
|
||||||
Telephony.Carriers.PROTOCOL,
|
Telephony.Carriers.PROTOCOL,
|
||||||
getUserEnteredApnProtocol(mProtocol, mDefaultApnProtocol),
|
checkNotSet(mProtocol.getValue()),
|
||||||
callUpdate,
|
callUpdate,
|
||||||
PROTOCOL_INDEX);
|
PROTOCOL_INDEX);
|
||||||
|
|
||||||
callUpdate = setStringValueAndCheckIfDiff(values,
|
callUpdate = setStringValueAndCheckIfDiff(values,
|
||||||
Telephony.Carriers.ROAMING_PROTOCOL,
|
Telephony.Carriers.ROAMING_PROTOCOL,
|
||||||
getUserEnteredApnProtocol(mRoamingProtocol, mDefaultApnRoamingProtocol),
|
checkNotSet(mRoamingProtocol.getValue()),
|
||||||
callUpdate,
|
callUpdate,
|
||||||
ROAMING_PROTOCOL_INDEX);
|
ROAMING_PROTOCOL_INDEX);
|
||||||
|
|
||||||
@@ -1204,17 +1214,6 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
return sNotSet.equals(value) ? null : value;
|
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
|
@VisibleForTesting
|
||||||
String getUserEnteredApnType() {
|
String getUserEnteredApnType() {
|
||||||
// if user has not specified a type, map it to "ALL APN TYPES THAT ARE NOT READ-ONLY"
|
// 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();
|
String userEnteredApnType = mApnType.getText();
|
||||||
if (userEnteredApnType != null) userEnteredApnType = userEnteredApnType.trim();
|
if (userEnteredApnType != null) userEnteredApnType = userEnteredApnType.trim();
|
||||||
if ((TextUtils.isEmpty(userEnteredApnType)
|
if ((TextUtils.isEmpty(userEnteredApnType)
|
||||||
|| APN_TYPE_ALL.equals(userEnteredApnType))
|
|| APN_TYPE_ALL.equals(userEnteredApnType))) {
|
||||||
&& !ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
|
userEnteredApnType = getEditableApnType(APN_TYPES);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
Log.d(TAG, "getUserEnteredApnType: changed apn type to editable apn types: "
|
||||||
|
+ userEnteredApnType);
|
||||||
return 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 class ErrorDialog extends InstrumentedDialogFragment {
|
||||||
|
|
||||||
public static void showError(ApnEditor editor) {
|
public static void showError(ApnEditor editor) {
|
||||||
|
@@ -81,11 +81,11 @@ public class ApnEditorTest {
|
|||||||
"" /* MMS port */,
|
"" /* MMS port */,
|
||||||
0 /* Authentication type */,
|
0 /* Authentication type */,
|
||||||
"default,supl,ia" /* APN type */,
|
"default,supl,ia" /* APN type */,
|
||||||
"IPv6" /* APN protocol */,
|
"IP" /* APN protocol */,
|
||||||
1 /* APN enable/disable */,
|
1 /* APN enable/disable */,
|
||||||
0 /* Bearer */,
|
0 /* Bearer */,
|
||||||
0 /* Bearer BITMASK*/,
|
0 /* Bearer BITMASK*/,
|
||||||
"IPv4" /* APN roaming protocol */,
|
"IPV6" /* APN roaming protocol */,
|
||||||
"None" /* MVNO type */,
|
"None" /* MVNO type */,
|
||||||
"", /* MVNO value */
|
"", /* MVNO value */
|
||||||
};
|
};
|
||||||
@@ -464,33 +464,25 @@ public class ApnEditorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getUserEnteredApnProtocol_emptyApnProtocol_shouldReturnDefaultIPv4v6() {
|
public void testOnViewStateRestored_customizedValueWithoutDefault_shouldShowCustomized() {
|
||||||
// GIVEN read default APN protocol with IPV4V6
|
mApnEditorUT.mDefaultApnProtocol = "IP";
|
||||||
mApnEditorUT.mDefaultApnProtocol = "IPV4V6";
|
mApnEditorUT.mApnData.mData[ApnEditor.PROTOCOL_INDEX] = null;
|
||||||
|
mApnEditorUT.mProtocol.setEntryValues(new CharSequence[]{"IP", "IPV6", "IPV4V6"});
|
||||||
|
|
||||||
// Input empty in TYPE
|
mApnEditorUT.onViewStateRestored(null);
|
||||||
mApnEditorUT.mApnData.mData[ApnEditor.PROTOCOL_INDEX] = "";
|
|
||||||
mApnEditorUT.fillUI(true /* firstTime */);
|
|
||||||
|
|
||||||
// THEN APN type should be IPV4V6
|
assertThat(mApnEditorUT.mProtocol.getSummary()).isEqualTo("IPv4");
|
||||||
assertThat(mApnEditorUT.getUserEnteredApnProtocol(
|
|
||||||
mApnEditorUT.mProtocol, mApnEditorUT.mDefaultApnProtocol))
|
|
||||||
.isEqualTo("IPV4V6");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getUserEnteredApnProtocol_emptyApnProtocol_shouldReturnDefaultIP() {
|
public void testOnViewStateRestored_customizedValueWithDefault_shouldShowDefault() {
|
||||||
// GIVEN read default APN protocol with IP
|
|
||||||
mApnEditorUT.mDefaultApnProtocol = "IP";
|
mApnEditorUT.mDefaultApnProtocol = "IP";
|
||||||
|
mApnEditorUT.mApnData.mData[ApnEditor.PROTOCOL_INDEX] = "IPV6";
|
||||||
|
mApnEditorUT.mProtocol.setEntryValues(new CharSequence[]{"IP", "IPV6", "IPV4V6"});
|
||||||
|
|
||||||
// Input empty in TYPE
|
mApnEditorUT.onViewStateRestored(null);
|
||||||
mApnEditorUT.mApnData.mData[ApnEditor.PROTOCOL_INDEX] = "";
|
|
||||||
mApnEditorUT.fillUI(true /* firstTime */);
|
|
||||||
|
|
||||||
// THEN APN type should be IPV4V6
|
assertThat(mApnEditorUT.mProtocol.getSummary()).isEqualTo("IPv6");
|
||||||
assertThat(mApnEditorUT.getUserEnteredApnProtocol(
|
|
||||||
mApnEditorUT.mProtocol, mApnEditorUT.mDefaultApnProtocol))
|
|
||||||
.isEqualTo("IP");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -503,7 +495,7 @@ public class ApnEditorTest {
|
|||||||
|
|
||||||
// Input empty in TYPE
|
// Input empty in TYPE
|
||||||
mApnEditorUT.mApnData.mData[ApnEditor.TYPE_INDEX] = "";
|
mApnEditorUT.mApnData.mData[ApnEditor.TYPE_INDEX] = "";
|
||||||
mApnEditorUT.fillUI(true /* firstTime */);
|
mApnEditorUT.onViewStateRestored(null);
|
||||||
|
|
||||||
// THEN APN type should be default
|
// THEN APN type should be default
|
||||||
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
|
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
|
||||||
@@ -516,7 +508,7 @@ public class ApnEditorTest {
|
|||||||
|
|
||||||
// Input empty in TYPE
|
// Input empty in TYPE
|
||||||
mApnEditorUT.mApnData.mData[ApnEditor.TYPE_INDEX] = "";
|
mApnEditorUT.mApnData.mData[ApnEditor.TYPE_INDEX] = "";
|
||||||
mApnEditorUT.fillUI(true /* firstTime */);
|
mApnEditorUT.onViewStateRestored(null);
|
||||||
|
|
||||||
// THEN APN type should be default
|
// THEN APN type should be default
|
||||||
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
|
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
|
||||||
|
Reference in New Issue
Block a user