Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49e3b372 authored by Kenny Root's avatar Kenny Root
Browse files

Fix crash determining direction of invalid locale

The layoutlib is used in the SDK which might not have a default Locale,
so the language string will be some kind of junk. This causes a crash in
the new LocaleUtils

Change-Id: I24e5115c56e39d394dcf89ec6cff609525b3c73e
parent fb2f3a53
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -71,8 +71,9 @@ public class LocaleUtil {
        if (localeWithSubtags == null) return getLayoutDirectionFromFirstChar(locale);

        // Need to check if we can extract the script subtag. For example, "Latn" in  "en_Latn_US"
        if (localeWithSubtags.charAt(2) != UNDERSCORE_CHAR ||
                localeWithSubtags.charAt(7) != UNDERSCORE_CHAR) {
        if (localeWithSubtags.length() <= 7
                || localeWithSubtags.charAt(2) != UNDERSCORE_CHAR
                || localeWithSubtags.charAt(7) != UNDERSCORE_CHAR) {
            return getLayoutDirectionFromFirstChar(locale);
        }
        // Extract the script subtag
+5 −0
Original line number Diff line number Diff line
@@ -193,5 +193,10 @@ public class LocaleUtilTest extends AndroidTestCase {
        locale = new Locale("uz_Arab", "AF");
        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE,
            LocaleUtil.getLayoutDirectionFromLocale(locale));

        // Locale without a real language
        locale = new Locale("zz");
        assertEquals(LocaleUtil.TEXT_LAYOUT_DIRECTION_LTR_DO_NOT_USE,
            LocaleUtil.getLayoutDirectionFromLocale(locale));
    }
}