Merge "[MEP] Refactor SlotSidecar API for all of sim page."
diff --git a/src/com/android/settings/FallbackHome.java b/src/com/android/settings/FallbackHome.java
index 40867aa..b70470b 100644
--- a/src/com/android/settings/FallbackHome.java
+++ b/src/com/android/settings/FallbackHome.java
@@ -42,7 +42,7 @@
 
 public class FallbackHome extends Activity {
     private static final String TAG = "FallbackHome";
-    private static final int PROGRESS_TIMEOUT = 2000;
+    private int mProgressTimeout;
 
     private boolean mProvisioned;
     private WallpaperManager mWallManager;
@@ -76,6 +76,12 @@
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        mProgressTimeout = getResources().getInteger(
+            com.android.internal.R.integer.config_progressTimeoutFallbackHome);
+
+        if (mProgressTimeout <= 0) {
+            mProgressTimeout = 0;
+        }
 
         // Set ourselves totally black before the device is provisioned so that
         // we don't flash the wallpaper before SUW
@@ -107,7 +113,7 @@
     protected void onResume() {
         super.onResume();
         if (mProvisioned) {
-            mHandler.postDelayed(mProgressTimeoutRunnable, PROGRESS_TIMEOUT);
+            mHandler.postDelayed(mProgressTimeoutRunnable, mProgressTimeout);
         }
     }
 
diff --git a/src/com/android/settings/applications/appinfo/AppLocaleDetails.java b/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
index aee360e..164cfd9 100644
--- a/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
+++ b/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
@@ -18,6 +18,7 @@
 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;
@@ -289,12 +290,18 @@
 
         @VisibleForTesting
         void handleSupportedLocales() {
-            //TODO Waiting for PackageManager api
-            String[] languages = getAssetSystemLocales();
-
-            for (String language : languages) {
-                mSupportedLocales.add(Locale.forLanguageTag(language));
+            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);
             }
@@ -349,9 +356,23 @@
                         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;
+        }
     }
 }
diff --git a/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java b/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java
index 1042a6a..ed4c127 100644
--- a/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java
+++ b/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java
@@ -55,6 +55,7 @@
     private LocaleList mSystemLocales;
     private LocaleList mAppLocale;
     private String[] mAssetLocales;
+    private LocaleList mPackageLocales;
 
     @Before
     @UiThreadTest
@@ -67,11 +68,13 @@
         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
@@ -105,11 +108,13 @@
     @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);
 
@@ -124,11 +129,13 @@
     @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);
 
@@ -142,11 +149,32 @@
     @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);
 
@@ -204,6 +232,11 @@
      *
      * @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"}
@@ -212,10 +245,12 @@
             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);
@@ -237,6 +272,10 @@
         LocaleList getCurrentSystemLocales() {
             return mSystemLocales;
         }
-    }
 
+        @Override
+        LocaleList getPackageLocales() {
+            return mPackageLocales;
+        }
+    }
 }