From e5700a7c49ea56c1e737e45860b4f19204204ef3 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Mon, 19 Aug 2019 20:27:45 +0100 Subject: [PATCH] Simplify APIs exposed for time zone lookups The libcore.timezone APIs may form the basis for some new SystemApis. Before starting that process the API surface is being rationalized to establish the core use cases. Test: Treehugger Bug: 139091367 Change-Id: Ib615976fae76ceb98873a33e1e995542e691c9d0 Merged-In: Ib615976fae76ceb98873a33e1e995542e691c9d0 (cherry picked from commit babab5cd6aa2ef4551c249aa861f5583b8ddde6f) --- .../settingslib/datetime/ZoneGetter.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java b/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java index 6157fec3441f7..f1e997bf5a1bd 100644 --- a/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java +++ b/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java @@ -33,11 +33,14 @@ import android.view.View; import com.android.settingslib.R; +import libcore.timezone.CountryTimeZones; +import libcore.timezone.CountryTimeZones.TimeZoneMapping; import libcore.timezone.TimeZoneFinder; import org.xmlpull.v1.XmlPullParserException; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -386,7 +389,21 @@ public class ZoneGetter { @VisibleForTesting public List lookupTimeZoneIdsByCountry(String country) { - return TimeZoneFinder.getInstance().lookupTimeZoneIdsByCountry(country); + final CountryTimeZones countryTimeZones = + TimeZoneFinder.getInstance().lookupCountryTimeZones(country); + if (countryTimeZones == null) { + return null; + } + final List mappings = countryTimeZones.getTimeZoneMappings(); + return extractTimeZoneIds(mappings); + } + + private static List extractTimeZoneIds(List timeZoneMappings) { + final List zoneIds = new ArrayList<>(timeZoneMappings.size()); + for (TimeZoneMapping timeZoneMapping : timeZoneMappings) { + zoneIds.add(timeZoneMapping.timeZoneId); + } + return Collections.unmodifiableList(zoneIds); } } }