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

Commit 117f161f authored by Narayan Kamath's avatar Narayan Kamath Committed by android-build-merger
Browse files

Merge "Add support for persist.sys.locale."

automerge: dca23321

* commit 'dca23321':
  Add support for persist.sys.locale.
parents b73f431d dca23321
Loading
Loading
Loading
Loading
+32 −20
Original line number Original line Diff line number Diff line
@@ -357,22 +357,37 @@ static bool hasFile(const char* file) {
}
}


/*
/*
 * Read the persistent locale.
 * Read the persistent locale. Attempts to read to persist.sys.locale
 * and falls back to the default locale (ro.product.locale) if
 * persist.sys.locale is empty.
 */
 */
static void readLocale(char* language, char* region)
static void readLocale(char* locale)
{
{
    char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX];
    // Allocate 4 extra bytes because we might read a property into
    // this array at offset 4.
    char propLocale[PROPERTY_VALUE_MAX + 4];


    property_get("persist.sys.language", propLang, "");
    property_get("persist.sys.locale", propLocale, "");
    property_get("persist.sys.country", propRegn, "");
    if (propLocale[0] == 0) {
    if (*propLang == 0 && *propRegn == 0) {
        property_get("ro.product.locale", propLocale, "");
        /* Set to ro properties, default is en_US */

        property_get("ro.product.locale.language", propLang, "en");
        if (propLocale[0] == 0) {
        property_get("ro.product.locale.region", propRegn, "US");
            // If persist.sys.locale and ro.product.locale are missing,
            // construct a locale value from the individual locale components.
            property_get("ro.product.locale.language", propLocale, "en");

            // The language code is either two or three chars in length. If it
            // isn't 2 chars long, assume three. Anything else is an error
            // anyway.
            const int offset = (propLocale[2] == 0) ? 2 : 3;
            propLocale[offset] = '-';

            property_get("ro.product.locale.region", propLocale + offset + 1, "US");
        }
        }
    strncat(language, propLang, 3);
    }
    strncat(region, propRegn, 3);

    //ALOGD("language=%s region=%s\n", language, region);
    strncat(locale, propLocale, PROPERTY_VALUE_MAX);
    // ALOGD("[DEBUG] locale=%s", locale);
}
}


void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
@@ -559,8 +574,7 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
                                    PROPERTY_VALUE_MAX];
                                    PROPERTY_VALUE_MAX];
    char profileType[sizeof("-Xprofile-type:")-1 + PROPERTY_VALUE_MAX];
    char profileType[sizeof("-Xprofile-type:")-1 + PROPERTY_VALUE_MAX];
    char profileMaxStackDepth[sizeof("-Xprofile-max-stack-depth:")-1 + PROPERTY_VALUE_MAX];
    char profileMaxStackDepth[sizeof("-Xprofile-max-stack-depth:")-1 + PROPERTY_VALUE_MAX];
    char langOption[sizeof("-Duser.language=") + 3];
    char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
    char regionOption[sizeof("-Duser.region=") + 3];
    char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
    char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
    char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
    char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];


@@ -717,11 +731,9 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)


    /* Set the properties for locale */
    /* Set the properties for locale */
    {
    {
        strcpy(langOption, "-Duser.language=");
        strcpy(localeOption, "-Duser.locale=");
        strcpy(regionOption, "-Duser.region=");
        readLocale(localeOption);
        readLocale(langOption, regionOption);
        addOption(localeOption);
        addOption(langOption);
        addOption(regionOption);
    }
    }


    /*
    /*
+4 −0
Original line number Original line Diff line number Diff line
@@ -859,6 +859,10 @@ class MountService extends IMountService.Stub


        // Temporary workaround for http://b/17945169.
        // Temporary workaround for http://b/17945169.
        Slog.d(TAG, "Setting system properties to " + systemLocale + " from mount service");
        Slog.d(TAG, "Setting system properties to " + systemLocale + " from mount service");
        SystemProperties.set("persist.sys.locale", locale.toLanguageTag());

        // TODO: Stop setting these properties once we've removed all
        // references to them.
        SystemProperties.set("persist.sys.language", locale.getLanguage());
        SystemProperties.set("persist.sys.language", locale.getLanguage());
        SystemProperties.set("persist.sys.country", locale.getCountry());
        SystemProperties.set("persist.sys.country", locale.getCountry());
    }
    }
+16 −4
Original line number Original line Diff line number Diff line
@@ -16403,12 +16403,24 @@ public final class ActivityManagerService extends ActivityManagerNative
     * Save the locale. You must be inside a synchronized (this) block.
     * Save the locale. You must be inside a synchronized (this) block.
     */
     */
    private void saveLocaleLocked(Locale l, boolean isDiff, boolean isPersist) {
    private void saveLocaleLocked(Locale l, boolean isDiff, boolean isPersist) {
        final String languageTag = l.toLanguageTag();
        if (isDiff) {
        if (isDiff) {
            SystemProperties.set("user.locale", languageTag);
            // TODO: Who uses these ? There are no references to these system
            // properties in documents or code. Did the author intend to call
            // System.setProperty() instead ? Even that wouldn't have any effect.
            SystemProperties.set("user.language", l.getLanguage());
            SystemProperties.set("user.language", l.getLanguage());
            SystemProperties.set("user.region", l.getCountry());
            SystemProperties.set("user.region", l.getCountry());
        }
        }
        if (isPersist) {
        if (isPersist) {
            SystemProperties.set("persist.sys.locale", languageTag);
            // These values are *deprecated*, use persist.sys.locale instead.
            //
            // TODO: Stop setting these values once all code that references
            // them has been removed.
            SystemProperties.set("persist.sys.language", l.getLanguage());
            SystemProperties.set("persist.sys.language", l.getLanguage());
            SystemProperties.set("persist.sys.country", l.getCountry());
            SystemProperties.set("persist.sys.country", l.getCountry());
            SystemProperties.set("persist.sys.localevar", l.getVariant());
            SystemProperties.set("persist.sys.localevar", l.getVariant());