Merge "LocalePicker: Support customize the language list"
diff --git a/core/java/com/android/internal/app/LocalePicker.java b/core/java/com/android/internal/app/LocalePicker.java
index 4efefa9..939c39d 100644
--- a/core/java/com/android/internal/app/LocalePicker.java
+++ b/core/java/com/android/internal/app/LocalePicker.java
@@ -28,6 +28,7 @@
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.provider.Settings;
+import android.text.TextUtils;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -41,6 +42,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.ArrayList;
+import java.util.Arrays;
 
 public class LocalePicker extends ListFragment {
     private static final String TAG = "LocalePicker";
@@ -83,12 +85,28 @@
         }
     }
 
+    public static ArrayList<String> getLocaleArray(String[] locales, Resources resources) {
+        String localeCodes = resources.getString(R.string.locale_codes);
+        String[] localeCodesArray = null;
+        if (localeCodes != null && !TextUtils.isEmpty(localeCodes.trim())) {
+            localeCodes = localeCodes.replace('_', '-');
+            // ICU use "fil" instead of "tl"
+            localeCodes = localeCodes.replaceAll("tl-", "fil-");
+            localeCodesArray = localeCodes.split(",");
+        }
+        ArrayList<String> localeList = new ArrayList<String>(
+            Arrays.asList((localeCodesArray == null || localeCodesArray.length == 0) ? locales
+                : localeCodesArray));
+        return localeList;
+    }
+
     public static List<LocaleInfo> getAllAssetLocales(Context context, boolean isInDeveloperMode) {
         final Resources resources = context.getResources();
 
-        final String[] locales = Resources.getSystem().getAssets().getLocales();
-        List<String> localeList = new ArrayList<String>(locales.length);
-        Collections.addAll(localeList, locales);
+        String[] locales = Resources.getSystem().getAssets().getLocales();
+        // Check the locale_codes if the locales list is customized in data package overlay.
+        // If locale_codes is customized, use the customized list instead of built-in locales.
+        ArrayList<String> localeList = getLocaleArray(locales, resources);
 
         // Don't show the pseudolocales unless we're in developer mode. http://b/17190407.
         if (!isInDeveloperMode) {
@@ -142,6 +160,25 @@
                 }
             }
         }
+        // If customized to true, always show the country name
+        boolean shallShowCountry
+                = resources.getBoolean(R.bool.config_display_country_for_locale_codes);
+        if (shallShowCountry) {
+            for (LocaleInfo locale : localeInfos) {
+                Locale l = locale.locale;
+                String languageName = toTitleCase(l.getDisplayLanguage(l));
+                String displayName
+                        = toTitleCase(getDisplayName(l, specialLocaleCodes, specialLocaleNames));
+                if (locale.label.equals(languageName)) {
+                    if (displayName.equals(languageName)) {
+                        // Fix some cases where getDisplayName() not works(e.g. ar-EG).
+                        displayName = toTitleCase(String.format("%s (%s)", languageName,
+                                l.getDisplayCountry(l)));
+                    }
+                    locale.label = displayName;
+                }
+            }
+        }
 
         Collections.sort(localeInfos);
         return localeInfos;
diff --git a/core/res/res/values/customize.xml b/core/res/res/values/customize.xml
index ceb08ef..c483dab 100644
--- a/core/res/res/values/customize.xml
+++ b/core/res/res/values/customize.xml
@@ -30,6 +30,12 @@
 
 <resources>
 
+    <!-- Used in LocalePicker, default language must be contained -->
+    <string name="locale_codes" translatable="false"></string>
+
+    <!-- If configure to true, always show the country(locale) name in the language lable -->
+    <bool name="config_display_country_for_locale_codes">false</bool>
+
     <!--Fully qualified class name of the plugin which would be
          dynamically loaded by TelephonyPluginDelegate-->
     <java-symbol type="string" name="telephony_plugin_class_name" />
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 9cf9f1e..8f4c76b 100755
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2331,6 +2331,10 @@
 
   <java-symbol type="drawable" name="platlogo_m" />
 
+  <!-- language/locale picker extention feature -->
+  <java-symbol type="string" name="locale_codes" />
+  <java-symbol type="bool"   name="config_display_country_for_locale_codes" />
+
   <!-- config softap extention feature -->
   <java-symbol type="bool" name="config_softap_extention" />