Merge "Use new package name for ZoneInfo and libcore.timezone"

This commit is contained in:
vichang
2020-06-30 16:51:05 +00:00
committed by Gerrit Code Review
10 changed files with 69 additions and 66 deletions

View File

@@ -35,7 +35,7 @@ import android.util.ArrayMap;
import android.util.Log; import android.util.Log;
import android.util.proto.ProtoOutputStream; import android.util.proto.ProtoOutputStream;
import libcore.timezone.ZoneInfoDb; import com.android.i18n.timezone.ZoneInfoDb;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;

View File

@@ -18,8 +18,8 @@ package android.text.format;
import android.util.TimeFormatException; import android.util.TimeFormatException;
import libcore.timezone.ZoneInfoDb; import com.android.i18n.timezone.ZoneInfoData;
import libcore.util.ZoneInfo; import com.android.i18n.timezone.ZoneInfoDb;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
@@ -1059,15 +1059,15 @@ public class Time {
* to the enclosing object, but others do not: thus separate state is retained. * to the enclosing object, but others do not: thus separate state is retained.
*/ */
private static class TimeCalculator { private static class TimeCalculator {
public final ZoneInfo.WallTime wallTime; public final ZoneInfoData.WallTime wallTime;
public String timezone; public String timezone;
// Information about the current timezone. // Information about the current timezone.
private ZoneInfo zoneInfo; private ZoneInfoData mZoneInfoData;
public TimeCalculator(String timezoneId) { public TimeCalculator(String timezoneId) {
this.zoneInfo = lookupZoneInfo(timezoneId); this.mZoneInfoData = lookupZoneInfoData(timezoneId);
this.wallTime = new ZoneInfo.WallTime(); this.wallTime = new ZoneInfoData.WallTime();
} }
public long toMillis(boolean ignoreDst) { public long toMillis(boolean ignoreDst) {
@@ -1075,7 +1075,7 @@ public class Time {
wallTime.setIsDst(-1); wallTime.setIsDst(-1);
} }
int r = wallTime.mktime(zoneInfo); int r = wallTime.mktime(mZoneInfoData);
if (r == -1) { if (r == -1) {
return -1; return -1;
} }
@@ -1087,7 +1087,7 @@ public class Time {
int intSeconds = (int) (millis / 1000); int intSeconds = (int) (millis / 1000);
updateZoneInfoFromTimeZone(); updateZoneInfoFromTimeZone();
wallTime.localtime(intSeconds, zoneInfo); wallTime.localtime(intSeconds, mZoneInfoData);
} }
public String format(String format) { public String format(String format) {
@@ -1095,31 +1095,31 @@ public class Time {
format = "%c"; format = "%c";
} }
TimeFormatter formatter = new TimeFormatter(); TimeFormatter formatter = new TimeFormatter();
return formatter.format(format, wallTime, zoneInfo); return formatter.format(format, wallTime, mZoneInfoData);
} }
private void updateZoneInfoFromTimeZone() { private void updateZoneInfoFromTimeZone() {
if (!zoneInfo.getID().equals(timezone)) { if (!mZoneInfoData.getID().equals(timezone)) {
this.zoneInfo = lookupZoneInfo(timezone); this.mZoneInfoData = lookupZoneInfoData(timezone);
} }
} }
private static ZoneInfo lookupZoneInfo(String timezoneId) { private static ZoneInfoData lookupZoneInfoData(String timezoneId) {
ZoneInfo zoneInfo = ZoneInfoDb.getInstance().makeTimeZone(timezoneId); ZoneInfoData zoneInfoData = ZoneInfoDb.getInstance().makeZoneInfoData(timezoneId);
if (zoneInfo == null) { if (zoneInfoData == null) {
zoneInfo = ZoneInfoDb.getInstance().makeTimeZone("GMT"); zoneInfoData = ZoneInfoDb.getInstance().makeZoneInfoData("GMT");
} }
if (zoneInfo == null) { if (zoneInfoData == null) {
throw new AssertionError("GMT not found: \"" + timezoneId + "\""); throw new AssertionError("GMT not found: \"" + timezoneId + "\"");
} }
return zoneInfo; return zoneInfoData;
} }
public void switchTimeZone(String timezone) { public void switchTimeZone(String timezone) {
int seconds = wallTime.mktime(zoneInfo); int seconds = wallTime.mktime(mZoneInfoData);
this.timezone = timezone; this.timezone = timezone;
updateZoneInfoFromTimeZone(); updateZoneInfoFromTimeZone();
wallTime.localtime(seconds, zoneInfo); wallTime.localtime(seconds, mZoneInfoData);
} }
public String format2445(boolean hasTime) { public String format2445(boolean hasTime) {

View File

@@ -22,8 +22,9 @@ package android.text.format;
import android.content.res.Resources; import android.content.res.Resources;
import com.android.i18n.timezone.ZoneInfoData;
import libcore.icu.LocaleData; import libcore.icu.LocaleData;
import libcore.util.ZoneInfo;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.time.Instant; import java.time.Instant;
@@ -94,8 +95,8 @@ class TimeFormatter {
* incorrect digit localization behavior. * incorrect digit localization behavior.
*/ */
String formatMillisWithFixedFormat(long timeMillis) { String formatMillisWithFixedFormat(long timeMillis) {
// This method is deliberately not a general purpose replacement for // This method is deliberately not a general purpose replacement for format(String,
// format(String, ZoneInfo.WallTime, ZoneInfo): It hard-codes the pattern used; many of the // ZoneInfoData.WallTime, ZoneInfoData): It hard-codes the pattern used; many of the
// pattern characters supported by Time.format() have unusual behavior which would make // pattern characters supported by Time.format() have unusual behavior which would make
// using java.time.format or similar packages difficult. It would be a lot of work to share // using java.time.format or similar packages difficult. It would be a lot of work to share
// behavior and many internal Android usecases can be covered by this common pattern // behavior and many internal Android usecases can be covered by this common pattern
@@ -144,7 +145,8 @@ class TimeFormatter {
/** /**
* Format the specified {@code wallTime} using {@code pattern}. The output is returned. * Format the specified {@code wallTime} using {@code pattern}. The output is returned.
*/ */
public String format(String pattern, ZoneInfo.WallTime wallTime, ZoneInfo zoneInfo) { public String format(String pattern, ZoneInfoData.WallTime wallTime,
ZoneInfoData zoneInfoData) {
try { try {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
@@ -153,7 +155,7 @@ class TimeFormatter {
// and locale sensitive strings are output directly using outputBuilder. // and locale sensitive strings are output directly using outputBuilder.
numberFormatter = new Formatter(stringBuilder, Locale.US); numberFormatter = new Formatter(stringBuilder, Locale.US);
formatInternal(pattern, wallTime, zoneInfo); formatInternal(pattern, wallTime, zoneInfoData);
String result = stringBuilder.toString(); String result = stringBuilder.toString();
// The localizeDigits() behavior is the source of a bug since some formats are defined // The localizeDigits() behavior is the source of a bug since some formats are defined
// as being in ASCII and not localized. // as being in ASCII and not localized.
@@ -186,13 +188,14 @@ class TimeFormatter {
* Format the specified {@code wallTime} using {@code pattern}. The output is written to * Format the specified {@code wallTime} using {@code pattern}. The output is written to
* {@link #outputBuilder}. * {@link #outputBuilder}.
*/ */
private void formatInternal(String pattern, ZoneInfo.WallTime wallTime, ZoneInfo zoneInfo) { private void formatInternal(String pattern, ZoneInfoData.WallTime wallTime,
ZoneInfoData zoneInfoData) {
CharBuffer formatBuffer = CharBuffer.wrap(pattern); CharBuffer formatBuffer = CharBuffer.wrap(pattern);
while (formatBuffer.remaining() > 0) { while (formatBuffer.remaining() > 0) {
boolean outputCurrentChar = true; boolean outputCurrentChar = true;
char currentChar = formatBuffer.get(formatBuffer.position()); char currentChar = formatBuffer.get(formatBuffer.position());
if (currentChar == '%') { if (currentChar == '%') {
outputCurrentChar = handleToken(formatBuffer, wallTime, zoneInfo); outputCurrentChar = handleToken(formatBuffer, wallTime, zoneInfoData);
} }
if (outputCurrentChar) { if (outputCurrentChar) {
outputBuilder.append(formatBuffer.get(formatBuffer.position())); outputBuilder.append(formatBuffer.get(formatBuffer.position()));
@@ -201,8 +204,8 @@ class TimeFormatter {
} }
} }
private boolean handleToken(CharBuffer formatBuffer, ZoneInfo.WallTime wallTime, private boolean handleToken(CharBuffer formatBuffer, ZoneInfoData.WallTime wallTime,
ZoneInfo zoneInfo) { ZoneInfoData zoneInfoData) {
// The char at formatBuffer.position() is expected to be '%' at this point. // The char at formatBuffer.position() is expected to be '%' at this point.
int modifier = 0; int modifier = 0;
@@ -247,10 +250,10 @@ class TimeFormatter {
outputYear(wallTime.getYear(), true, false, modifier); outputYear(wallTime.getYear(), true, false, modifier);
return false; return false;
case 'c': case 'c':
formatInternal(dateTimeFormat, wallTime, zoneInfo); formatInternal(dateTimeFormat, wallTime, zoneInfoData);
return false; return false;
case 'D': case 'D':
formatInternal("%m/%d/%y", wallTime, zoneInfo); formatInternal("%m/%d/%y", wallTime, zoneInfoData);
return false; return false;
case 'd': case 'd':
numberFormatter.format(getFormat(modifier, "%02d", "%2d", "%d", "%02d"), numberFormatter.format(getFormat(modifier, "%02d", "%2d", "%d", "%02d"),
@@ -272,7 +275,7 @@ class TimeFormatter {
wallTime.getMonthDay()); wallTime.getMonthDay());
return false; return false;
case 'F': case 'F':
formatInternal("%Y-%m-%d", wallTime, zoneInfo); formatInternal("%Y-%m-%d", wallTime, zoneInfoData);
return false; return false;
case 'H': case 'H':
numberFormatter.format(getFormat(modifier, "%02d", "%2d", "%d", "%02d"), numberFormatter.format(getFormat(modifier, "%02d", "%2d", "%d", "%02d"),
@@ -315,21 +318,21 @@ class TimeFormatter {
: localeData.amPm[0], FORCE_LOWER_CASE); : localeData.amPm[0], FORCE_LOWER_CASE);
return false; return false;
case 'R': case 'R':
formatInternal("%H:%M", wallTime, zoneInfo); formatInternal("%H:%M", wallTime, zoneInfoData);
return false; return false;
case 'r': case 'r':
formatInternal("%I:%M:%S %p", wallTime, zoneInfo); formatInternal("%I:%M:%S %p", wallTime, zoneInfoData);
return false; return false;
case 'S': case 'S':
numberFormatter.format(getFormat(modifier, "%02d", "%2d", "%d", "%02d"), numberFormatter.format(getFormat(modifier, "%02d", "%2d", "%d", "%02d"),
wallTime.getSecond()); wallTime.getSecond());
return false; return false;
case 's': case 's':
int timeInSeconds = wallTime.mktime(zoneInfo); int timeInSeconds = wallTime.mktime(zoneInfoData);
outputBuilder.append(Integer.toString(timeInSeconds)); outputBuilder.append(Integer.toString(timeInSeconds));
return false; return false;
case 'T': case 'T':
formatInternal("%H:%M:%S", wallTime, zoneInfo); formatInternal("%H:%M:%S", wallTime, zoneInfoData);
return false; return false;
case 't': case 't':
outputBuilder.append('\t'); outputBuilder.append('\t');
@@ -383,7 +386,7 @@ class TimeFormatter {
return false; return false;
} }
case 'v': case 'v':
formatInternal("%e-%b-%Y", wallTime, zoneInfo); formatInternal("%e-%b-%Y", wallTime, zoneInfoData);
return false; return false;
case 'W': case 'W':
int n = (wallTime.getYearDay() + DAYSPERWEEK - ( int n = (wallTime.getYearDay() + DAYSPERWEEK - (
@@ -395,10 +398,10 @@ class TimeFormatter {
numberFormatter.format("%d", wallTime.getWeekDay()); numberFormatter.format("%d", wallTime.getWeekDay());
return false; return false;
case 'X': case 'X':
formatInternal(timeOnlyFormat, wallTime, zoneInfo); formatInternal(timeOnlyFormat, wallTime, zoneInfoData);
return false; return false;
case 'x': case 'x':
formatInternal(dateOnlyFormat, wallTime, zoneInfo); formatInternal(dateOnlyFormat, wallTime, zoneInfoData);
return false; return false;
case 'y': case 'y':
outputYear(wallTime.getYear(), false, true, modifier); outputYear(wallTime.getYear(), false, true, modifier);
@@ -411,7 +414,8 @@ class TimeFormatter {
return false; return false;
} }
boolean isDst = wallTime.getIsDst() != 0; boolean isDst = wallTime.getIsDst() != 0;
modifyAndAppend(zoneInfo.getDisplayName(isDst, TimeZone.SHORT), modifier); modifyAndAppend(TimeZone.getTimeZone(zoneInfoData.getID())
.getDisplayName(isDst, TimeZone.SHORT), modifier);
return false; return false;
case 'z': { case 'z': {
if (wallTime.getIsDst() < 0) { if (wallTime.getIsDst() < 0) {
@@ -432,7 +436,7 @@ class TimeFormatter {
return false; return false;
} }
case '+': case '+':
formatInternal("%a %b %e %H:%M:%S %Z %Y", wallTime, zoneInfo); formatInternal("%a %b %e %H:%M:%S %Z %Y", wallTime, zoneInfoData);
return false; return false;
case '%': case '%':
// If conversion char is undefined, behavior is undefined. Print out the // If conversion char is undefined, behavior is undefined. Print out the

View File

@@ -50,14 +50,14 @@ public final class TzDataSetVersion {
* Returns the major tz data format version supported by this device. * Returns the major tz data format version supported by this device.
*/ */
public static int currentFormatMajorVersion() { public static int currentFormatMajorVersion() {
return libcore.timezone.TzDataSetVersion.currentFormatMajorVersion(); return com.android.i18n.timezone.TzDataSetVersion.currentFormatMajorVersion();
} }
/** /**
* Returns the minor tz data format version supported by this device. * Returns the minor tz data format version supported by this device.
*/ */
public static int currentFormatMinorVersion() { public static int currentFormatMinorVersion() {
return libcore.timezone.TzDataSetVersion.currentFormatMinorVersion(); return com.android.i18n.timezone.TzDataSetVersion.currentFormatMinorVersion();
} }
/** /**
@@ -65,7 +65,7 @@ public final class TzDataSetVersion {
* with the current system image, and set of active modules. * with the current system image, and set of active modules.
*/ */
public static boolean isCompatibleWithThisDevice(TzDataSetVersion tzDataSetVersion) { public static boolean isCompatibleWithThisDevice(TzDataSetVersion tzDataSetVersion) {
return libcore.timezone.TzDataSetVersion.isCompatibleWithThisDevice( return com.android.i18n.timezone.TzDataSetVersion.isCompatibleWithThisDevice(
tzDataSetVersion.mDelegate); tzDataSetVersion.mDelegate);
} }
@@ -76,8 +76,8 @@ public final class TzDataSetVersion {
public static TzDataSetVersion read() throws IOException, TzDataSetException { public static TzDataSetVersion read() throws IOException, TzDataSetException {
try { try {
return new TzDataSetVersion( return new TzDataSetVersion(
libcore.timezone.TzDataSetVersion.readTimeZoneModuleVersion()); com.android.i18n.timezone.TzDataSetVersion.readTimeZoneModuleVersion());
} catch (libcore.timezone.TzDataSetVersion.TzDataSetException e) { } catch (com.android.i18n.timezone.TzDataSetVersion.TzDataSetException e) {
throw new TzDataSetException(e.getMessage(), e); throw new TzDataSetException(e.getMessage(), e);
} }
} }
@@ -100,9 +100,9 @@ public final class TzDataSetVersion {
} }
@NonNull @NonNull
private final libcore.timezone.TzDataSetVersion mDelegate; private final com.android.i18n.timezone.TzDataSetVersion mDelegate;
private TzDataSetVersion(@NonNull libcore.timezone.TzDataSetVersion delegate) { private TzDataSetVersion(@NonNull com.android.i18n.timezone.TzDataSetVersion delegate) {
mDelegate = Objects.requireNonNull(delegate); mDelegate = Objects.requireNonNull(delegate);
} }

View File

@@ -41,16 +41,16 @@ public final class ZoneInfoDb {
public static ZoneInfoDb getInstance() { public static ZoneInfoDb getInstance() {
synchronized (sLock) { synchronized (sLock) {
if (sInstance == null) { if (sInstance == null) {
sInstance = new ZoneInfoDb(libcore.timezone.ZoneInfoDb.getInstance()); sInstance = new ZoneInfoDb(com.android.i18n.timezone.ZoneInfoDb.getInstance());
} }
} }
return sInstance; return sInstance;
} }
@NonNull @NonNull
private final libcore.timezone.ZoneInfoDb mDelegate; private final com.android.i18n.timezone.ZoneInfoDb mDelegate;
private ZoneInfoDb(libcore.timezone.ZoneInfoDb delegate) { private ZoneInfoDb(com.android.i18n.timezone.ZoneInfoDb delegate) {
mDelegate = Objects.requireNonNull(delegate); mDelegate = Objects.requireNonNull(delegate);
} }

View File

@@ -23,10 +23,11 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build; import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import com.android.i18n.timezone.ZoneInfoDb;
import libcore.timezone.CountryTimeZones; import libcore.timezone.CountryTimeZones;
import libcore.timezone.CountryTimeZones.TimeZoneMapping; import libcore.timezone.CountryTimeZones.TimeZoneMapping;
import libcore.timezone.TimeZoneFinder; import libcore.timezone.TimeZoneFinder;
import libcore.timezone.ZoneInfoDb;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;

View File

@@ -23,10 +23,9 @@ import android.service.runtime.RuntimeServiceInfoProto;
import android.util.Slog; import android.util.Slog;
import android.util.proto.ProtoOutputStream; import android.util.proto.ProtoOutputStream;
import libcore.timezone.TimeZoneDataFiles; import com.android.i18n.timezone.DebugInfo;
import libcore.util.CoreLibraryDebug; import com.android.i18n.timezone.I18nModuleDebug;
import libcore.util.DebugInfo; import com.android.i18n.timezone.TimeZoneDataFiles;
import com.android.internal.util.DumpUtils; import com.android.internal.util.DumpUtils;
import com.android.timezone.distro.DistroException; import com.android.timezone.distro.DistroException;
import com.android.timezone.distro.DistroVersion; import com.android.timezone.distro.DistroVersion;
@@ -61,14 +60,14 @@ public class RuntimeService extends Binder {
boolean protoFormat = hasOption(args, "--proto"); boolean protoFormat = hasOption(args, "--proto");
ProtoOutputStream proto = null; ProtoOutputStream proto = null;
DebugInfo coreLibraryDebugInfo = CoreLibraryDebug.getDebugInfo(); DebugInfo i18nLibraryDebugInfo = I18nModuleDebug.getDebugInfo();
addTimeZoneApkDebugInfo(coreLibraryDebugInfo); addTimeZoneApkDebugInfo(i18nLibraryDebugInfo);
if (protoFormat) { if (protoFormat) {
proto = new ProtoOutputStream(fd); proto = new ProtoOutputStream(fd);
reportTimeZoneInfoProto(coreLibraryDebugInfo, proto); reportTimeZoneInfoProto(i18nLibraryDebugInfo, proto);
} else { } else {
reportTimeZoneInfo(coreLibraryDebugInfo, pw); reportTimeZoneInfo(i18nLibraryDebugInfo, pw);
} }
if (protoFormat) { if (protoFormat) {

View File

@@ -37,6 +37,9 @@ import android.os.ParcelFileDescriptor;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Slog; import android.util.Slog;
import com.android.i18n.timezone.TimeZoneDataFiles;
import com.android.i18n.timezone.TzDataSetVersion;
import com.android.i18n.timezone.ZoneInfoDb;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.server.EventLogTags; import com.android.server.EventLogTags;
import com.android.server.SystemService; import com.android.server.SystemService;
@@ -46,10 +49,7 @@ import com.android.timezone.distro.StagedDistroOperation;
import com.android.timezone.distro.TimeZoneDistro; import com.android.timezone.distro.TimeZoneDistro;
import com.android.timezone.distro.installer.TimeZoneDistroInstaller; import com.android.timezone.distro.installer.TimeZoneDistroInstaller;
import libcore.timezone.TimeZoneDataFiles;
import libcore.timezone.TimeZoneFinder; import libcore.timezone.TimeZoneFinder;
import libcore.timezone.TzDataSetVersion;
import libcore.timezone.ZoneInfoDb;
import java.io.File; import java.io.File;
import java.io.FileDescriptor; import java.io.FileDescriptor;

View File

@@ -74,6 +74,7 @@ import android.view.WindowManager;
import android.view.contentcapture.ContentCaptureManager; import android.view.contentcapture.ContentCaptureManager;
import android.view.inputmethod.InputMethodSystemProperty; import android.view.inputmethod.InputMethodSystemProperty;
import com.android.i18n.timezone.ZoneInfoDb;
import com.android.internal.R; import com.android.internal.R;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.notification.SystemNotificationChannels; import com.android.internal.notification.SystemNotificationChannels;
@@ -165,8 +166,6 @@ import com.android.server.wm.ActivityTaskManagerService;
import com.android.server.wm.WindowManagerGlobalLock; import com.android.server.wm.WindowManagerGlobalLock;
import com.android.server.wm.WindowManagerService; import com.android.server.wm.WindowManagerService;
import libcore.timezone.ZoneInfoDb;
import dalvik.system.VMRuntime; import dalvik.system.VMRuntime;
import java.io.File; import java.io.File;

View File

@@ -43,13 +43,13 @@ import android.app.timezone.RulesManager;
import android.app.timezone.RulesState; import android.app.timezone.RulesState;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import com.android.i18n.timezone.TzDataSetVersion;
import com.android.timezone.distro.DistroVersion; import com.android.timezone.distro.DistroVersion;
import com.android.timezone.distro.StagedDistroOperation; import com.android.timezone.distro.StagedDistroOperation;
import com.android.timezone.distro.TimeZoneDistro; import com.android.timezone.distro.TimeZoneDistro;
import com.android.timezone.distro.installer.TimeZoneDistroInstaller; import com.android.timezone.distro.installer.TimeZoneDistroInstaller;
import libcore.io.IoUtils; import libcore.io.IoUtils;
import libcore.timezone.TzDataSetVersion;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;