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

Commit 7bfad681 authored by Jordan Liu's avatar Jordan Liu Committed by android-build-merger
Browse files

Merge "Preserve leading 0s in mcc mnc" am: 593d767e am: c2a5c472

am: efd3dd02

Change-Id: I3f42a20035fb2be92e98c33dd16b59870b8ed481
parents ecad8489 efd3dd02
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -313,12 +313,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.
+3 −1
Original line number Diff line number Diff line
@@ -440,6 +440,8 @@ public class ApnEditorTest {
    @Test
    public void formatInteger_shouldParseString() {
        assertThat(ApnEditor.formatInteger("42")).isEqualTo("42");
        assertThat(ApnEditor.formatInteger("01")).isEqualTo("01");
        assertThat(ApnEditor.formatInteger("001")).isEqualTo("001");
    }

    @Test