Fix result does not get correct locale tag.
- phone.getContext return a null in Cuttle fish ROM. It make the test
result get failed. Hence mock the Context instance to avoid this
situation.
Bug: b/254731907
Test: atest passed.
Test: Manual test passed. After FDR, check Wellcome page in SUW show
correct locale with zh-TW sim.
Change-Id: I831c425116b15814197944dc58588ec76d0c1b3a
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index bd2be12..516eef0 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -7842,7 +7842,7 @@
if (!localeFromDefaultSim.getCountry().isEmpty()) {
if (DBG) log("Using locale from subId: " + subId + " locale: "
+ localeFromDefaultSim);
- return matchLocaleFromSupportedLocaleList(localeFromDefaultSim);
+ return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
} else {
simLanguage = localeFromDefaultSim.getLanguage();
}
@@ -7855,7 +7855,7 @@
final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
if (mccLocale != null) {
if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
- return matchLocaleFromSupportedLocaleList(mccLocale);
+ return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
}
if (DBG) log("No locale found - returning null");
@@ -7866,9 +7866,9 @@
}
@VisibleForTesting
- String matchLocaleFromSupportedLocaleList(@NonNull Locale inputLocale) {
+ String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
- getDefaultPhone().getContext());
+ phone.getContext());
for (String localeTag : supportedLocale) {
if (LocaleList.matchesLanguageAndScript(
inputLocale, Locale.forLanguageTag(localeTag))
diff --git a/tests/src/com/android/phone/PhoneInterfaceManagerTest.java b/tests/src/com/android/phone/PhoneInterfaceManagerTest.java
index ffc0177..b623bd0 100644
--- a/tests/src/com/android/phone/PhoneInterfaceManagerTest.java
+++ b/tests/src/com/android/phone/PhoneInterfaceManagerTest.java
@@ -17,11 +17,16 @@
package com.android.phone;
import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import android.content.Context;
import android.content.pm.PackageManager;
+import android.content.res.Resources;
import android.telephony.RadioAccessFamily;
import android.telephony.TelephonyManager;
@@ -91,14 +96,22 @@
@Test
public void matchLocaleFromSupportedLocaleList_inputLocaleChangeToSupportedLocale() {
+ Context context = mock(Context.class);
+ Resources resources = mock(Resources.class);
+ when(mPhone.getContext()).thenReturn(context);
+ when(context.getResources()).thenReturn(resources);
+ when(resources.getStringArray(anyInt())).thenReturn(new String[]{"zh-Hant-TW"});
// Input zh-TW, then look up the matched supported locale, zh-Hant-TW, instead.
- String result1 = mPhoneInterfaceManager.matchLocaleFromSupportedLocaleList(
+ String result1 = mPhoneInterfaceManager.matchLocaleFromSupportedLocaleList(mPhone,
Locale.forLanguageTag("zh-TW"));
assertEquals(result1, "zh-Hant-TW");
+ when(resources.getStringArray(anyInt())).thenReturn(
+ new String[]{"fi-FI", "ff-Adlm-BF", "ff-Latn-BF"});
+
// Input ff-BF, then find the matched supported locale, ff-Latn-BF, instead.
- String result2 = mPhoneInterfaceManager.matchLocaleFromSupportedLocaleList(
+ String result2 = mPhoneInterfaceManager.matchLocaleFromSupportedLocaleList(mPhone,
Locale.forLanguageTag("ff-BF"));
assertEquals(result2, "ff-Latn-BF");