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

Commit 83da7b8d authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Support different formats of SMSC during FDN check.

Bug: 287182614
Bug: 290206662
Test: atest FdnUtilsTest, Flashed device on raven-userdebug and
performed basic functionality tests.

Change-Id: If6d305aa40d97a1f0ba77f2d567b49a1c60607fa
Merged-In: If6d305aa40d97a1f0ba77f2d567b49a1c60607fa
parent 13cf841a
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.internal.telephony.uicc.UiccProfile;
import com.android.telephony.Rlog;

import java.util.ArrayList;
import java.util.regex.PatternSyntaxException;

/**
 * This is a basic utility class for common functions related to Fixed Dialing Numbers
@@ -123,6 +124,7 @@ public class FdnUtils {
            dialStrNational = String.valueOf(phoneNumber.getNationalNumber());
        } catch (NumberParseException ignored) {
            Rlog.w(LOG_TAG, "isFDN: could not parse dialStr");
            dialStr = extractSMSC(dialStr);
        }

        /**
@@ -187,4 +189,37 @@ public class FdnUtils {

        return uiccProfile.getApplication(UiccController.APP_FAM_3GPP);
    }

    private static String extractSMSC(String dialStr) {
        try {
            String[] dialStrParts = null;
            if (dialStr.contains(",")) {
                // SMSC can be in the format of ""+123456789123",123"
                // Split into two parts using comma as delimiter
                // and first part of the string is used as smsc address
                dialStrParts = dialStr.split(",");
            } else if (dialStr.contains("@")) {
                // SMSC can be in the format of "+123456789123@ims.mnc.org"
                // Split into two parts using @ as delimiter
                // and first part of the string is used as smsc address
                dialStrParts = dialStr.split("@");
            }

            if (dialStrParts != null && dialStrParts.length >= 1) {
                if (dialStrParts[0].contains("\"")) {
                    // If SMSC is in this format: ""+123456789123",123", after performing above
                    // split we get string with double-quotation marks in it
                    // dialStrParts[0] = ""+123456789123"".
                    // Here, we remove double-quotation marks from the string.
                    dialStrParts[0] = dialStrParts[0].replaceAll("\"", "");
                }
                return dialStrParts[0];
            }
        } catch (PatternSyntaxException ex) {
            Rlog.w(LOG_TAG, "extractSMSC: Could not extract number from dialStr " + ex);
        }

        // Return original dialStr if it is not in any of the formats mentions above.
        return dialStr;
    }
}
 No newline at end of file
+18 −0
Original line number Diff line number Diff line
@@ -163,4 +163,22 @@ public class FdnUtilsTest {

        assertFalse(FdnUtils.isFDN("6502910000", "", fdnList));
    }

    @Test
    public void smscAddrInTwoStringsFormat_returnsTrue() {
        ArrayList<AdnRecord> fdnList = initializeFdnList();
        AdnRecord adnRecord = new AdnRecord(null, "1234560000");
        fdnList.add(7, adnRecord);

        assertTrue(FdnUtils.isFDN("\"1234560000\",124", "US", fdnList));
    }

    @Test
    public void smscAddrInEmailIdFormat_returnsTrue() {
        ArrayList<AdnRecord> fdnList = initializeFdnList();
        AdnRecord adnRecord = new AdnRecord(null, "1234560000");
        fdnList.add(8, adnRecord);

        assertTrue(FdnUtils.isFDN("1234560000@ims.mnc.org", "US", fdnList));
    }
}
 No newline at end of file