Reformat local numbers that are placing calls in Singapore to not show
the country code.

Due to local regulations and recommendations about only showing the +65
country code when being called by international numbers as a means to
combat international spam calls.

This change also restructures the check so that other countries can be
added if needed later on.

Flag: telephony.remove_country_code_from_local_singapore_calls

Bug: 284416645
Test: atest PhoneNumberUtilsTest, atest PhoneNumberUtilsTest#testFormatSingaporeInternational, atest PhoneNumberUtilsTest#testFormatSingaporeNational
Test2: manual validity checks on call/sms/data
Change-Id: I3139639272115cfb868acc1f9ea94fcc0730bc5d
diff --git a/flags/calling.aconfig b/flags/calling.aconfig
index f121169..c1dc7e7 100644
--- a/flags/calling.aconfig
+++ b/flags/calling.aconfig
@@ -17,4 +17,15 @@
   namespace: "telephony"
   description: "Used in DisconnectCause and TelephonyConnection if a non-emergency call fails on a device with no 2G, to guard whether a user can see an updated error message reminding the 2G is disabled and potentially disrupting their call connectivity"
   bug: "300142897"
-}
\ No newline at end of file
+}
+
+# OWNER=stevestatia TARGET=24Q4
+flag {
+    name: "remove_country_code_from_local_singapore_calls"
+    namespace: "telephony"
+    description: "Fix bug where the country code is being shown when merging in local Singapore numbers to conference calls."
+    bug:"284416645"
+    metadata {
+        purpose: PURPOSE_BUGFIX
+    }
+}
diff --git a/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java b/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
index 1c4e43d..bf9ced3 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
@@ -21,7 +21,10 @@
 import static junit.framework.Assert.assertNull;
 import static junit.framework.Assert.assertTrue;
 
+import com.android.internal.telephony.flags.Flags;
+
 import android.net.Uri;
+import android.platform.test.flag.junit.SetFlagsRule;
 import android.telephony.PhoneNumberUtils;
 import android.text.SpannableStringBuilder;
 import android.text.style.TtsSpan;
@@ -32,6 +35,7 @@
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 
 public class PhoneNumberUtilsTest {
@@ -40,6 +44,8 @@
 
     private int mOldMinMatch;
 
+    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
     @Before
     public void setUp() throws Exception {
         mOldMinMatch = PhoneNumberUtils.getMinMatchForTest();
@@ -613,6 +619,60 @@
         assertEquals("+1 650-555-1212", PhoneNumberUtils.formatNumber("+16505551212", "jp"));
     }
 
+    /**
+     * Test to ensure that when international calls to Singapore are being placed the country
+     * code is present with and without the feature flag enabled.
+     */
+    @SmallTest
+    @Test
+    public void testFormatSingaporeInternational() {
+        // Disable feature flag.
+        mSetFlagsRule.disableFlags(Flags.FLAG_REMOVE_COUNTRY_CODE_FROM_LOCAL_SINGAPORE_CALLS);
+
+        // International call from a US iso
+        assertEquals("+65 6521 8000", PhoneNumberUtils.formatNumber("+6565218000", "US"));
+
+        // Lowercase country iso
+        assertEquals("+65 6521 8000", PhoneNumberUtils.formatNumber("+6565218000", "us"));
+
+        // Enable feature flag
+        mSetFlagsRule.enableFlags(Flags.FLAG_REMOVE_COUNTRY_CODE_FROM_LOCAL_SINGAPORE_CALLS);
+
+        // Internal call from a US iso
+        assertEquals("+65 6521 8000", PhoneNumberUtils.formatNumber("+6565218000", "US"));
+
+        // Lowercase country iso
+        assertEquals("+65 6521 8000", PhoneNumberUtils.formatNumber("+6565218000", "us"));
+        mSetFlagsRule.disableFlags(Flags.FLAG_REMOVE_COUNTRY_CODE_FROM_LOCAL_SINGAPORE_CALLS);
+    }
+
+    /**
+     * Test to ensure that when local calls from Singaporean numbers are being placed to other
+     * Singaporean numbers the country code +65 is not being shown.
+     */
+    @SmallTest
+    @Test
+    public void testFormatSingaporeNational() {
+        // Disable feature flag.
+        mSetFlagsRule.disableFlags(Flags.FLAG_REMOVE_COUNTRY_CODE_FROM_LOCAL_SINGAPORE_CALLS);
+
+        // Local call from a Singaporean number to a Singaporean number
+        assertEquals("+65 6521 8000", PhoneNumberUtils.formatNumber("+6565218000", "SG"));
+
+        // Lowercase country iso.
+        assertEquals("+65 6521 8000", PhoneNumberUtils.formatNumber("+6565218000", "sg"));
+
+        // Enable feature flag.
+        mSetFlagsRule.enableFlags(Flags.FLAG_REMOVE_COUNTRY_CODE_FROM_LOCAL_SINGAPORE_CALLS);
+
+        // Local call from a Singaporean number to a Singaporean number.
+        assertEquals("6521 8000", PhoneNumberUtils.formatNumber("+6565218000", "SG"));
+
+        // Lowercase country iso.
+        assertEquals("6521 8000", PhoneNumberUtils.formatNumber("+6565218000", "sg"));
+        mSetFlagsRule.disableFlags(Flags.FLAG_REMOVE_COUNTRY_CODE_FROM_LOCAL_SINGAPORE_CALLS);
+    }
+
     @SmallTest
     @Test
     public void testFormatNumber_LeadingStarAndHash() {