summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2015-01-22 14:00:51 +0000
committerandroid-build-merger <android-build-merger@google.com>2015-01-22 14:00:51 +0000
commit56bbefccf27d3c32029121fe23f0b02c01eba338 (patch)
tree2943b2ec271a1a6b5014ada0d13d26570c1ca2f3
parent5395e8ad0e28e824d0005f5567a88f81cd4ad649 (diff)
parent1194e754a95e1fa5d4eba6d0bca109156dd4df94 (diff)
downloadframeworks_base-56bbefccf27d3c32029121fe23f0b02c01eba338.zip
frameworks_base-56bbefccf27d3c32029121fe23f0b02c01eba338.tar.gz
frameworks_base-56bbefccf27d3c32029121fe23f0b02c01eba338.tar.bz2
Merge "Add support for persist.sys.locale." automerge: dca2332 automerge: 117f161
automerge: 1194e75 * commit '1194e754a95e1fa5d4eba6d0bca109156dd4df94': Add support for persist.sys.locale.
-rw-r--r--core/jni/AndroidRuntime.cpp52
-rw-r--r--services/core/java/com/android/server/MountService.java4
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java20
3 files changed, 52 insertions, 24 deletions
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 7540c51..008f877 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -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];
-
- property_get("persist.sys.language", propLang, "");
- property_get("persist.sys.country", propRegn, "");
- if (*propLang == 0 && *propRegn == 0) {
- /* Set to ro properties, default is en_US */
- property_get("ro.product.locale.language", propLang, "en");
- property_get("ro.product.locale.region", propRegn, "US");
+ // 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.locale", propLocale, "");
+ if (propLocale[0] == 0) {
+ property_get("ro.product.locale", propLocale, "");
+
+ if (propLocale[0] == 0) {
+ // 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)
@@ -559,8 +574,7 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
PROPERTY_VALUE_MAX];
char profileType[sizeof("-Xprofile-type:")-1 + PROPERTY_VALUE_MAX];
char profileMaxStackDepth[sizeof("-Xprofile-max-stack-depth:")-1 + PROPERTY_VALUE_MAX];
- char langOption[sizeof("-Duser.language=") + 3];
- char regionOption[sizeof("-Duser.region=") + 3];
+ char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + 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 */
{
- strcpy(langOption, "-Duser.language=");
- strcpy(regionOption, "-Duser.region=");
- readLocale(langOption, regionOption);
- addOption(langOption);
- addOption(regionOption);
+ strcpy(localeOption, "-Duser.locale=");
+ readLocale(localeOption);
+ addOption(localeOption);
}
/*
diff --git a/services/core/java/com/android/server/MountService.java b/services/core/java/com/android/server/MountService.java
index 9eb70d8..1405fc1 100644
--- a/services/core/java/com/android/server/MountService.java
+++ b/services/core/java/com/android/server/MountService.java
@@ -891,6 +891,10 @@ class MountService extends IMountService.Stub
// Temporary workaround for http://b/17945169.
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.country", locale.getCountry());
}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index fe25a17..2e3e5c3 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -16254,15 +16254,27 @@ 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) {
- if(isDiff) {
+ final String languageTag = l.toLanguageTag();
+ 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.region", l.getCountry());
- }
+ }
+
+ if (isPersist) {
+ SystemProperties.set("persist.sys.locale", languageTag);
- if(isPersist) {
+ // 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.country", l.getCountry());
SystemProperties.set("persist.sys.localevar", l.getVariant());