1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.timezone;
import android.annotation.NonNull;
import android.annotation.Nullable;
import com.android.i18n.timezone.TimeZoneDataFiles;
import com.android.internal.annotations.VisibleForTesting;
import java.io.IOException;
import java.util.Objects;
/**
* Version information associated with the set of time zone data on a device.
*
* <p>Time Zone Data Sets have a major ({@link #getFormatMajorVersion()}) and minor
* ({@link #currentFormatMinorVersion()}) version number:
* <ul>
* <li>Major version numbers are mutually incompatible. e.g. v2 is not compatible with a v1 or a
* v3 device.</li>
* <li>Minor version numbers are backwards compatible. e.g. a v2.2 data set will work
* on a v2.1 device but not a v2.3 device. The minor version is reset to 1 when the major version
* is incremented.</li>
* </ul>
*
* <p>Data sets contain time zone rules and other data associated wtih a tzdb release
* ({@link #getRulesVersion()}) and an additional Android-specific revision number
* ({@link #getRevision()}).
*
* <p>See platform/system/timezone/README.android for more information.
* @hide
*/
@VisibleForTesting
public final class TzDataSetVersion {
/**
* Returns the major tz data format version supported by this device.
*/
public static int currentFormatMajorVersion() {
return com.android.i18n.timezone.TzDataSetVersion.currentFormatMajorVersion();
}
/**
* Returns the minor tz data format version supported by this device.
*/
public static int currentFormatMinorVersion() {
return com.android.i18n.timezone.TzDataSetVersion.currentFormatMinorVersion();
}
/**
* Returns true if the version information provided would be compatible with this device, i.e.
* with the current system image, and set of active modules.
*/
public static boolean isCompatibleWithThisDevice(TzDataSetVersion tzDataSetVersion) {
return com.android.i18n.timezone.TzDataSetVersion.isCompatibleWithThisDevice(
tzDataSetVersion.mDelegate);
}
/**
* Reads the current Android time zone data set version file.
*/
@NonNull
public static TzDataSetVersion read() throws IOException, TzDataSetException {
try {
return new TzDataSetVersion(TimeZoneDataFiles.readTimeZoneModuleVersion());
} catch (com.android.i18n.timezone.TzDataSetVersion.TzDataSetException e) {
throw new TzDataSetException(e.getMessage(), e);
}
}
/**
* A checked exception used in connection with time zone data sets.
* @hide
*/
public static final class TzDataSetException extends Exception {
/** Creates an instance with a message. */
public TzDataSetException(String message) {
super(message);
}
/** Creates an instance with a message and a cause. */
public TzDataSetException(String message, Throwable cause) {
super(message, cause);
}
}
@NonNull
private final com.android.i18n.timezone.TzDataSetVersion mDelegate;
private TzDataSetVersion(@NonNull com.android.i18n.timezone.TzDataSetVersion delegate) {
mDelegate = Objects.requireNonNull(delegate);
}
/** Returns the major version number. See {@link TzDataSetVersion}. */
public int getFormatMajorVersion() {
return mDelegate.getFormatMajorVersion();
}
/** Returns the minor version number. See {@link TzDataSetVersion}. */
public int getFormatMinorVersion() {
return mDelegate.getFormatMinorVersion();
}
/** Returns the tzdb version string. See {@link TzDataSetVersion}. */
@NonNull
public String getRulesVersion() {
return mDelegate.getRulesVersion();
}
/** Returns the Android revision. See {@link TzDataSetVersion}. */
public int getRevision() {
return mDelegate.getRevision();
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TzDataSetVersion that = (TzDataSetVersion) o;
return mDelegate.equals(that.mDelegate);
}
@Override
public int hashCode() {
return Objects.hash(mDelegate);
}
@Override
public String toString() {
return mDelegate.toString();
}
}
|