Loading src/com/android/settings/applications/appinfo/AppLocaleDetails.java +27 −6 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settings.applications.appinfo; import static com.android.settings.widget.EntityHeaderController.ActionType; import android.app.Activity; import android.app.LocaleConfig; import android.app.LocaleManager; import android.app.settings.SettingsEnums; import android.content.Context; Loading Loading @@ -289,12 +290,18 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen @VisibleForTesting void handleSupportedLocales() { //TODO Waiting for PackageManager api LocaleList localeList = getPackageLocales(); if (localeList == null) { String[] languages = getAssetSystemLocales(); for (String language : languages) { mSupportedLocales.add(Locale.forLanguageTag(language)); } } else { for (int i = 0; i < localeList.size(); i++) { mSupportedLocales.add(localeList.get(i)); } } if (mSuggestedLocales != null || !mSuggestedLocales.isEmpty()) { mSupportedLocales.removeAll(mSuggestedLocales); } Loading Loading @@ -349,9 +356,23 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen packageManager.getPackageInfo(mPackageName, PackageManager.MATCH_ALL) .applicationInfo).getAssets().getNonSystemLocales(); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Can not found the package name : " + e); Log.w(TAG, "Can not found the package name : " + mPackageName + " / " + e); } return new String[0]; } @VisibleForTesting LocaleList getPackageLocales() { try { LocaleConfig localeConfig = new LocaleConfig(mContext.createPackageContext(mPackageName, 0)); if (localeConfig.getStatus() == LocaleConfig.STATUS_SUCCESS) { return localeConfig.getSupportedLocales(); } } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Can not found the package name : " + mPackageName + " / " + e); } return null; } } } tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java +60 −21 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ public class AppLocaleDetailsTest { private LocaleList mSystemLocales; private LocaleList mAppLocale; private String[] mAssetLocales; private LocaleList mPackageLocales; @Before @UiThreadTest Loading @@ -67,11 +68,13 @@ public class AppLocaleDetailsTest { when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); when(mContext.getSystemService(LocaleManager.class)).thenReturn(mLocaleManager); setupInitialLocales("en", "tw", "jp", "en, uk, jp, ne", new String[]{"en", "ne", "ms", "pa"}); setupInitialLocales( /* appLocale= */ "en", /* simCountry= */ "tw", /* networkCountry= */ "jp", /* systemLocales= */ "en, uk, jp, ne", /* packageLocales= */ "pa, cn, tw, en", /* assetLocales= */ new String[]{"en", "ne", "ms", "pa"}); } @Test Loading Loading @@ -105,11 +108,13 @@ public class AppLocaleDetailsTest { @UiThreadTest public void handleAllLocalesData_withoutAppLocale_1stSuggestedLocaleIsSimCountryLocale() { Locale simCountryLocale = new Locale("zh", "TW"); setupInitialLocales("", "tw", "", "en, uk, jp, ne", new String[]{"en", "ne", "ms", "pa"}); setupInitialLocales( /* appLocale= */ "", /* simCountry= */ "tw", /* networkCountry= */ "", /* systemLocales= */ "en, uk, jp, ne", /* packageLocales= */ "", /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); Loading @@ -124,11 +129,13 @@ public class AppLocaleDetailsTest { @UiThreadTest public void handleAllLocalesData_withoutAppLocale_1stSuggestedLocaleIsNetworkCountryLocale() { Locale networkCountryLocale = new Locale("en", "GB"); setupInitialLocales("", "", "gb", "en, uk, jp, ne", new String[]{"en", "ne", "ms", "pa"}); setupInitialLocales( /* appLocale= */ "", /* simCountry= */ "", /* networkCountry= */ "gb", /* systemLocales= */ "en, uk, jp, ne", /* packageLocales= */ "", /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); Loading @@ -142,11 +149,32 @@ public class AppLocaleDetailsTest { @Test @UiThreadTest public void handleAllLocalesData_noAppAndSimNetworkLocale_1stLocaleIsFirstOneInSystemLocales() { setupInitialLocales("", "", "", "en, uk, jp, ne", new String[]{"en", "ne", "ms", "pa"}); setupInitialLocales( /* appLocale= */ "", /* simCountry= */ "", /* networkCountry= */ "", /* systemLocales= */ "en, uk, jp, ne", /* packageLocales= */ "", /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); helper.handleAllLocalesData(); Locale locale = Iterables.get(helper.getSuggestedLocales(), 0); assertTrue(locale.equals(mSystemLocales.get(0))); } @Test @UiThreadTest public void handleAllLocalesData_hasPackageAndSystemLocales_1stLocaleIs1stOneInSystemLocales() { setupInitialLocales( /* appLocale= */ "", /* simCountry= */ "", /* networkCountry= */ "", /* systemLocales= */ "en, uk, jp, ne", /* packageLocales= */ "pa, cn, tw, en", /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); Loading Loading @@ -204,6 +232,11 @@ public class AppLocaleDetailsTest { * * @param systemLocales System locales, a locale list by a multiple language tags with comma. * example: "en, uk, jp" * * @param packageLocales PackageManager locales, a locale list by a multiple language tags with * comma. * example: "en, uk, jp" * * @param assetLocales Asset locales, a locale list by a multiple language tags with String * array. * example: new String[] {"en", "ne", "ms", "pa"} Loading @@ -212,10 +245,12 @@ public class AppLocaleDetailsTest { String simCountry, String networkCountry, String systemLocales, String packageLocales, String[] assetLocales) { mAppLocale = LocaleList.forLanguageTags(appLocale); mSystemLocales = LocaleList.forLanguageTags(systemLocales); mAssetLocales = assetLocales; mPackageLocales = LocaleList.forLanguageTags(packageLocales); when(mTelephonyManager.getSimCountryIso()).thenReturn(simCountry); when(mTelephonyManager.getNetworkCountryIso()).thenReturn(networkCountry); when(mLocaleManager.getApplicationLocales(anyString())).thenReturn(mAppLocale); Loading @@ -237,6 +272,10 @@ public class AppLocaleDetailsTest { LocaleList getCurrentSystemLocales() { return mSystemLocales; } } @Override LocaleList getPackageLocales() { return mPackageLocales; } } } Loading
src/com/android/settings/applications/appinfo/AppLocaleDetails.java +27 −6 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settings.applications.appinfo; import static com.android.settings.widget.EntityHeaderController.ActionType; import android.app.Activity; import android.app.LocaleConfig; import android.app.LocaleManager; import android.app.settings.SettingsEnums; import android.content.Context; Loading Loading @@ -289,12 +290,18 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen @VisibleForTesting void handleSupportedLocales() { //TODO Waiting for PackageManager api LocaleList localeList = getPackageLocales(); if (localeList == null) { String[] languages = getAssetSystemLocales(); for (String language : languages) { mSupportedLocales.add(Locale.forLanguageTag(language)); } } else { for (int i = 0; i < localeList.size(); i++) { mSupportedLocales.add(localeList.get(i)); } } if (mSuggestedLocales != null || !mSuggestedLocales.isEmpty()) { mSupportedLocales.removeAll(mSuggestedLocales); } Loading Loading @@ -349,9 +356,23 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen packageManager.getPackageInfo(mPackageName, PackageManager.MATCH_ALL) .applicationInfo).getAssets().getNonSystemLocales(); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Can not found the package name : " + e); Log.w(TAG, "Can not found the package name : " + mPackageName + " / " + e); } return new String[0]; } @VisibleForTesting LocaleList getPackageLocales() { try { LocaleConfig localeConfig = new LocaleConfig(mContext.createPackageContext(mPackageName, 0)); if (localeConfig.getStatus() == LocaleConfig.STATUS_SUCCESS) { return localeConfig.getSupportedLocales(); } } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Can not found the package name : " + mPackageName + " / " + e); } return null; } } }
tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java +60 −21 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ public class AppLocaleDetailsTest { private LocaleList mSystemLocales; private LocaleList mAppLocale; private String[] mAssetLocales; private LocaleList mPackageLocales; @Before @UiThreadTest Loading @@ -67,11 +68,13 @@ public class AppLocaleDetailsTest { when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); when(mContext.getSystemService(LocaleManager.class)).thenReturn(mLocaleManager); setupInitialLocales("en", "tw", "jp", "en, uk, jp, ne", new String[]{"en", "ne", "ms", "pa"}); setupInitialLocales( /* appLocale= */ "en", /* simCountry= */ "tw", /* networkCountry= */ "jp", /* systemLocales= */ "en, uk, jp, ne", /* packageLocales= */ "pa, cn, tw, en", /* assetLocales= */ new String[]{"en", "ne", "ms", "pa"}); } @Test Loading Loading @@ -105,11 +108,13 @@ public class AppLocaleDetailsTest { @UiThreadTest public void handleAllLocalesData_withoutAppLocale_1stSuggestedLocaleIsSimCountryLocale() { Locale simCountryLocale = new Locale("zh", "TW"); setupInitialLocales("", "tw", "", "en, uk, jp, ne", new String[]{"en", "ne", "ms", "pa"}); setupInitialLocales( /* appLocale= */ "", /* simCountry= */ "tw", /* networkCountry= */ "", /* systemLocales= */ "en, uk, jp, ne", /* packageLocales= */ "", /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); Loading @@ -124,11 +129,13 @@ public class AppLocaleDetailsTest { @UiThreadTest public void handleAllLocalesData_withoutAppLocale_1stSuggestedLocaleIsNetworkCountryLocale() { Locale networkCountryLocale = new Locale("en", "GB"); setupInitialLocales("", "", "gb", "en, uk, jp, ne", new String[]{"en", "ne", "ms", "pa"}); setupInitialLocales( /* appLocale= */ "", /* simCountry= */ "", /* networkCountry= */ "gb", /* systemLocales= */ "en, uk, jp, ne", /* packageLocales= */ "", /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); Loading @@ -142,11 +149,32 @@ public class AppLocaleDetailsTest { @Test @UiThreadTest public void handleAllLocalesData_noAppAndSimNetworkLocale_1stLocaleIsFirstOneInSystemLocales() { setupInitialLocales("", "", "", "en, uk, jp, ne", new String[]{"en", "ne", "ms", "pa"}); setupInitialLocales( /* appLocale= */ "", /* simCountry= */ "", /* networkCountry= */ "", /* systemLocales= */ "en, uk, jp, ne", /* packageLocales= */ "", /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); helper.handleAllLocalesData(); Locale locale = Iterables.get(helper.getSuggestedLocales(), 0); assertTrue(locale.equals(mSystemLocales.get(0))); } @Test @UiThreadTest public void handleAllLocalesData_hasPackageAndSystemLocales_1stLocaleIs1stOneInSystemLocales() { setupInitialLocales( /* appLocale= */ "", /* simCountry= */ "", /* networkCountry= */ "", /* systemLocales= */ "en, uk, jp, ne", /* packageLocales= */ "pa, cn, tw, en", /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); Loading Loading @@ -204,6 +232,11 @@ public class AppLocaleDetailsTest { * * @param systemLocales System locales, a locale list by a multiple language tags with comma. * example: "en, uk, jp" * * @param packageLocales PackageManager locales, a locale list by a multiple language tags with * comma. * example: "en, uk, jp" * * @param assetLocales Asset locales, a locale list by a multiple language tags with String * array. * example: new String[] {"en", "ne", "ms", "pa"} Loading @@ -212,10 +245,12 @@ public class AppLocaleDetailsTest { String simCountry, String networkCountry, String systemLocales, String packageLocales, String[] assetLocales) { mAppLocale = LocaleList.forLanguageTags(appLocale); mSystemLocales = LocaleList.forLanguageTags(systemLocales); mAssetLocales = assetLocales; mPackageLocales = LocaleList.forLanguageTags(packageLocales); when(mTelephonyManager.getSimCountryIso()).thenReturn(simCountry); when(mTelephonyManager.getNetworkCountryIso()).thenReturn(networkCountry); when(mLocaleManager.getApplicationLocales(anyString())).thenReturn(mAppLocale); Loading @@ -237,6 +272,10 @@ public class AppLocaleDetailsTest { LocaleList getCurrentSystemLocales() { return mSystemLocales; } } @Override LocaleList getPackageLocales() { return mPackageLocales; } } }