From a21962b3c926a97b03bf61ed76477af6091024c0 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Wed, 29 Apr 2020 10:16:19 +0100 Subject: [PATCH] Fix missing zone strings in some cases ICU's TimeZoneNames requires a "canonical" zone ID, otherwise it will return no data. Usually the ID being used is the same as the canonical ID so there's no problem. TZDB version 2020a switched the ID of one of Greenland's zones from America/Godthab to America/Nuuk, and ICU/CLDR hold their translation data against America/Godthab in the current version of ICU on Android. Bug: 155167041 Test: Manual - viewed settings on a device with the tzdb 2020a update Merged-In: Ia89c777a832f8b41c8d56d3327a9b7370ba44b52 Change-Id: Ia89c777a832f8b41c8d56d3327a9b7370ba44b52 (cherry picked from commit eafec7a2440b934694a611a50b0541cf51c61a74) --- .../datetime/timezone/TimeZoneInfo.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/com/android/settings/datetime/timezone/TimeZoneInfo.java b/src/com/android/settings/datetime/timezone/TimeZoneInfo.java index c036eacd4b3..f74614d7c75 100644 --- a/src/com/android/settings/datetime/timezone/TimeZoneInfo.java +++ b/src/com/android/settings/datetime/timezone/TimeZoneInfo.java @@ -149,22 +149,31 @@ public class TimeZoneInfo { * @return TimeZoneInfo containing time zone names, exemplar locations and GMT offset */ public TimeZoneInfo format(TimeZone timeZone) { - final String id = timeZone.getID(); + String canonicalZoneId = getCanonicalZoneId(timeZone); final TimeZoneNames timeZoneNames = mTimeZoneFormat.getTimeZoneNames(); - final java.util.TimeZone javaTimeZone = java.util.TimeZone.getTimeZone(id); + final java.util.TimeZone javaTimeZone = java.util.TimeZone.getTimeZone(canonicalZoneId); final CharSequence gmtOffset = ZoneGetter.getGmtOffsetText(mTimeZoneFormat, mLocale, javaTimeZone, mNow); return new TimeZoneInfo.Builder(timeZone) - .setGenericName(timeZoneNames.getDisplayName(id, + .setGenericName(timeZoneNames.getDisplayName(canonicalZoneId, TimeZoneNames.NameType.LONG_GENERIC, mNow.getTime())) - .setStandardName(timeZoneNames.getDisplayName(id, + .setStandardName(timeZoneNames.getDisplayName(canonicalZoneId, TimeZoneNames.NameType.LONG_STANDARD, mNow.getTime())) - .setDaylightName(timeZoneNames.getDisplayName(id, + .setDaylightName(timeZoneNames.getDisplayName(canonicalZoneId, TimeZoneNames.NameType.LONG_DAYLIGHT, mNow.getTime())) - .setExemplarLocation(timeZoneNames.getExemplarLocationName(id)) + .setExemplarLocation(timeZoneNames.getExemplarLocationName(canonicalZoneId)) .setGmtOffset(gmtOffset) .build(); } + + private static String getCanonicalZoneId(TimeZone timeZone) { + final String id = timeZone.getID(); + final String canonicalId = TimeZone.getCanonicalID(id); + if (canonicalId != null) { + return canonicalId; + } + return id; + } } }