Use supported locale replace the result from sim info.

 - Current sim locale use Sim info to get corresponding sim locale, but
   it may not completely match current supported locale.
   e.g.
   The result of TelephonyManager#getSimLocale is zh-TW.
   Supported lcoale only has zh-Hant-TW.

 - Hence, when SetupWizard use TelephonyManager#getSimLocale, it will
   set a non-matched locale to device and make user confuse.

Bug: b/244017408
Test: atest passed
Test: Maunal test passed
Change-Id: Id29bd66c14d7a5415b3d5b2905a2301846780c70
diff --git a/tests/src/com/android/TelephonyTestBase.java b/tests/src/com/android/TelephonyTestBase.java
index 09abb15..ffda81b 100644
--- a/tests/src/com/android/TelephonyTestBase.java
+++ b/tests/src/com/android/TelephonyTestBase.java
@@ -24,7 +24,9 @@
 
 import com.android.internal.telephony.PhoneConfigurationManager;
 
-import org.mockito.MockitoAnnotations;
+import org.junit.Rule;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
 
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Executor;
@@ -34,11 +36,11 @@
  * Helper class to load Mockito Resources into a test.
  */
 public class TelephonyTestBase {
+    @Rule public final MockitoRule mocks = MockitoJUnit.rule();
 
     protected TestContext mContext;
 
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
         mContext = spy(new TestContext());
         // Set up the looper if it does not exist on the test thread.
         if (Looper.myLooper() == null) {
diff --git a/tests/src/com/android/phone/PhoneInterfaceManagerTest.java b/tests/src/com/android/phone/PhoneInterfaceManagerTest.java
index fe5d013..ffc0177 100644
--- a/tests/src/com/android/phone/PhoneInterfaceManagerTest.java
+++ b/tests/src/com/android/phone/PhoneInterfaceManagerTest.java
@@ -16,6 +16,7 @@
 
 package com.android.phone;
 
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -35,6 +36,9 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.Locale;
 
 /**
  * Unit Test for CarrierConfigLoader.
@@ -54,6 +58,7 @@
     @UiThreadTest
     public void setUp() throws Exception {
         super.setUp();
+        MockitoAnnotations.initMocks(this);
         doReturn(mPackageManager).when(mPhoneGlobals).getPackageManager();
         doReturn(false).when(mPackageManager).hasSystemFeature(
                 PackageManager.FEATURE_TELEPHONY_IMS);
@@ -83,4 +88,19 @@
         verify(mPhone, never()).setAllowedNetworkTypes(
                 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, defaultNetworkType, null);
     }
+
+    @Test
+    public void matchLocaleFromSupportedLocaleList_inputLocaleChangeToSupportedLocale() {
+        // Input zh-TW, then look up the matched supported locale, zh-Hant-TW, instead.
+        String result1 = mPhoneInterfaceManager.matchLocaleFromSupportedLocaleList(
+                Locale.forLanguageTag("zh-TW"));
+
+        assertEquals(result1, "zh-Hant-TW");
+
+        // Input ff-BF, then find the matched supported locale, ff-Latn-BF, instead.
+        String result2 = mPhoneInterfaceManager.matchLocaleFromSupportedLocaleList(
+                Locale.forLanguageTag("ff-BF"));
+
+        assertEquals(result2, "ff-Latn-BF");
+    }
 }