Neil Fuller | fe6ec56 | 2017-03-16 18:29:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app.timezone; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | |
| 22 | /** |
| 23 | * Versioning information about a distro's format or a device's supported format. |
| 24 | * |
| 25 | * <p>The following properties are included: |
| 26 | * <dl> |
| 27 | * <dt>majorVersion</dt> |
| 28 | * <dd>the major distro format version. Major versions differences are not compatible - e.g. |
| 29 | * 2 is not compatible with 1 or 3.</dd> |
| 30 | * <dt>minorVersion</dt> |
| 31 | * <dd>the minor distro format version. Minor versions should be backwards compatible iff the |
| 32 | * major versions match exactly, i.e. version 2.2 will be compatible with 2.1 devices but not |
| 33 | * 2.3 devices.</dd> |
| 34 | * </dl> |
| 35 | * |
| 36 | * @hide |
| 37 | */ |
Neil Fuller | fe6ec56 | 2017-03-16 18:29:36 +0000 | [diff] [blame] | 38 | public final class DistroFormatVersion implements Parcelable { |
| 39 | |
| 40 | private final int mMajorVersion; |
| 41 | private final int mMinorVersion; |
| 42 | |
| 43 | public DistroFormatVersion(int majorVersion, int minorVersion) { |
| 44 | mMajorVersion = Utils.validateVersion("major", majorVersion); |
| 45 | mMinorVersion = Utils.validateVersion("minor", minorVersion); |
| 46 | } |
| 47 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 48 | public static final @android.annotation.NonNull Creator<DistroFormatVersion> CREATOR = new Creator<DistroFormatVersion>() { |
Neil Fuller | fe6ec56 | 2017-03-16 18:29:36 +0000 | [diff] [blame] | 49 | public DistroFormatVersion createFromParcel(Parcel in) { |
| 50 | int majorVersion = in.readInt(); |
| 51 | int minorVersion = in.readInt(); |
| 52 | return new DistroFormatVersion(majorVersion, minorVersion); |
| 53 | } |
| 54 | |
| 55 | public DistroFormatVersion[] newArray(int size) { |
| 56 | return new DistroFormatVersion[size]; |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | public int getMajorVersion() { |
| 61 | return mMajorVersion; |
| 62 | } |
| 63 | |
| 64 | public int getMinorVersion() { |
| 65 | return mMinorVersion; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int describeContents() { |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void writeToParcel(Parcel out, int flags) { |
| 75 | out.writeInt(mMajorVersion); |
| 76 | out.writeInt(mMinorVersion); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * If this object describes a device's supported version and the parameter describes a distro's |
| 81 | * version, this method returns whether the device would accept the distro. |
| 82 | */ |
| 83 | public boolean supports(DistroFormatVersion distroFormatVersion) { |
| 84 | return mMajorVersion == distroFormatVersion.mMajorVersion |
| 85 | && mMinorVersion <= distroFormatVersion.mMinorVersion; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public boolean equals(Object o) { |
| 90 | if (this == o) { |
| 91 | return true; |
| 92 | } |
| 93 | if (o == null || getClass() != o.getClass()) { |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | DistroFormatVersion that = (DistroFormatVersion) o; |
| 98 | |
| 99 | if (mMajorVersion != that.mMajorVersion) { |
| 100 | return false; |
| 101 | } |
| 102 | return mMinorVersion == that.mMinorVersion; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public int hashCode() { |
| 107 | int result = mMajorVersion; |
| 108 | result = 31 * result + mMinorVersion; |
| 109 | return result; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public String toString() { |
| 114 | return "DistroFormatVersion{" |
| 115 | + "mMajorVersion=" + mMajorVersion |
| 116 | + ", mMinorVersion=" + mMinorVersion |
| 117 | + '}'; |
| 118 | } |
| 119 | } |