diff options
| author | Varun Shah <varunshah@google.com> | 2019-09-10 14:41:00 -0400 |
|---|---|---|
| committer | Varun Shah <varunshah@google.com> | 2019-09-23 20:25:01 -0700 |
| commit | 36b4ca01e5bf3b7ef683b5f2e2543c47f93225e8 (patch) | |
| tree | 0564887f48baece9d254f3f36bb6131475d31873 /core/java/android | |
| parent | a59e2cd3c49e407cda708d70d25e7cfeffbbf416 (diff) | |
Use language tags to store Configuration's locale list.
Instead of storing each Locale within a Configuration object's locale
list by its language, country, variant, and script to proto, store the
entire locale list by its language tags representation which accurately
describes each locale.
Bug: 140197723
Test: atest ConfigurationTest
Test: atest UsageStatsDatabaseTest
Test: manually with bad data
Merged-In: I53946ed4e31de0ffe9c84875c391a7dec6f5375a
Change-Id: Idaae690f79a5c680ad0059a52be62160d9dfb5e7
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/content/res/Configuration.java | 11 | ||||
| -rw-r--r-- | core/java/android/os/LocaleList.java | 22 |
2 files changed, 10 insertions, 23 deletions
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java index 861ae7ba122e..1abfe7000221 100644 --- a/core/java/android/content/res/Configuration.java +++ b/core/java/android/content/res/Configuration.java @@ -23,6 +23,7 @@ import static android.content.ConfigurationProto.HARD_KEYBOARD_HIDDEN; import static android.content.ConfigurationProto.KEYBOARD; import static android.content.ConfigurationProto.KEYBOARD_HIDDEN; import static android.content.ConfigurationProto.LOCALES; +import static android.content.ConfigurationProto.LOCALE_LIST; import static android.content.ConfigurationProto.MCC; import static android.content.ConfigurationProto.MNC; import static android.content.ConfigurationProto.NAVIGATION; @@ -1111,7 +1112,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration protoOutputStream.write(MCC, mcc); protoOutputStream.write(MNC, mnc); if (mLocaleList != null) { - mLocaleList.writeToProto(protoOutputStream, LOCALES); + protoOutputStream.write(LOCALE_LIST, mLocaleList.toLanguageTags()); } protoOutputStream.write(SCREEN_LAYOUT, screenLayout); protoOutputStream.write(COLOR_MODE, colorMode); @@ -1275,6 +1276,14 @@ public final class Configuration implements Parcelable, Comparable<Configuration case (int) WINDOW_CONFIGURATION: windowConfiguration.readFromProto(protoInputStream, WINDOW_CONFIGURATION); break; + case (int) LOCALE_LIST: + try { + setLocales(LocaleList.forLanguageTags(protoInputStream.readString( + LOCALE_LIST))); + } catch (Exception e) { + Slog.e(TAG, "error parsing locale list in configuration.", e); + } + break; } } } finally { diff --git a/core/java/android/os/LocaleList.java b/core/java/android/os/LocaleList.java index 7782753e4abc..0de09efad8ea 100644 --- a/core/java/android/os/LocaleList.java +++ b/core/java/android/os/LocaleList.java @@ -21,9 +21,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Size; import android.annotation.UnsupportedAppUsage; -import android.content.LocaleProto; import android.icu.util.ULocale; -import android.util.proto.ProtoOutputStream; import com.android.internal.annotations.GuardedBy; @@ -143,26 +141,6 @@ public final class LocaleList implements Parcelable { } /** - * Helper to write LocaleList to a protocol buffer output stream. Assumes the parent - * protobuf has declared the locale as repeated. - * - * @param protoOutputStream Stream to write the locale to. - * @param fieldId Field Id of the Locale as defined in the parent message. - * @hide - */ - public void writeToProto(ProtoOutputStream protoOutputStream, long fieldId) { - for (int i = 0; i < mList.length; i++) { - final Locale locale = mList[i]; - final long token = protoOutputStream.start(fieldId); - protoOutputStream.write(LocaleProto.LANGUAGE, locale.getLanguage()); - protoOutputStream.write(LocaleProto.COUNTRY, locale.getCountry()); - protoOutputStream.write(LocaleProto.VARIANT, locale.getVariant()); - protoOutputStream.write(LocaleProto.SCRIPT, locale.getScript()); - protoOutputStream.end(token); - } - } - - /** * Retrieves a String representation of the language tags in this list. */ @NonNull |
