Merge "Preserve leading 0s in mcc mnc"

This commit is contained in:
Jordan Liu
2018-07-13 20:57:52 +00:00
committed by Android (Google) Code Review
2 changed files with 14 additions and 2 deletions

View File

@@ -314,12 +314,22 @@ public class ApnEditor extends SettingsPreferenceFragment
static String formatInteger(String value) {
try {
final int intValue = Integer.parseInt(value);
return String.format("%d", intValue);
return String.format(getCorrectDigitsFormat(value), intValue);
} catch (NumberFormatException e) {
return value;
}
}
/**
* Get the digits format so we preserve leading 0's.
* MCCs are 3 digits and MNCs are either 2 or 3.
*/
static String getCorrectDigitsFormat(String value) {
if (value.length() == 2) return "%02d";
else return "%03d";
}
/**
* Check if passed in array of APN types indicates all APN types
* @param apnTypes array of APN types. "*" indicates all types.