blob: be732e4c0188eb59042befc073c70c00fff17d90 [file] [log] [blame]
Neil Fullerfe6ec562017-03-16 18:29:36 +00001/*
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
17package android.app.timezone;
18
19import android.os.Parcel;
20import 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 Fullerfe6ec562017-03-16 18:29:36 +000038public 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
48 public static final Creator<DistroFormatVersion> CREATOR = new Creator<DistroFormatVersion>() {
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}