Replace @CorePlatformApi APIs usages in TimeZoneInfoPreferenceControllerTest

The time zone transitions can be obtained via the public API
ZoneId.getRules() instead.

Bug: 119751170
Test: atest SettingsRoboTests
     com.android.settings.datetime.timezone.TimeZoneInfoPreferenceControllerTest passes
Change-Id: I2c7864580b2a36b725ee250253e97f6cc86d72a4
This commit is contained in:
Victor Chang
2021-09-20 12:54:21 +01:00
parent 604c7a7cfa
commit fc4589448b
2 changed files with 48 additions and 28 deletions

View File

@@ -151,7 +151,7 @@ public class TimeZoneInfo {
public TimeZoneInfo format(TimeZone timeZone) {
String canonicalZoneId = getCanonicalZoneId(timeZone);
final TimeZoneNames timeZoneNames = mTimeZoneFormat.getTimeZoneNames();
final java.util.TimeZone javaTimeZone = java.util.TimeZone.getTimeZone(canonicalZoneId);
final java.util.TimeZone javaTimeZone = toJavaTimeZone(canonicalZoneId);
final CharSequence gmtOffset = ZoneGetter.getGmtOffsetText(mTimeZoneFormat, mLocale,
javaTimeZone, mNow);
return new TimeZoneInfo.Builder(timeZone)
@@ -165,15 +165,24 @@ public class TimeZoneInfo {
.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;
/* package-private */ java.util.TimeZone getJavaTimeZone() {
String canonicalZoneId = getCanonicalZoneId(mTimeZone);
return toJavaTimeZone(canonicalZoneId);
}
private static java.util.TimeZone toJavaTimeZone(String canonicalZoneId) {
return java.util.TimeZone.getTimeZone(canonicalZoneId);
}
private static String getCanonicalZoneId(TimeZone timeZone) {
final String id = timeZone.getID();
final String canonicalId = TimeZone.getCanonicalID(id);
if (canonicalId != null) {
return canonicalId;
}
return id;
}
}