• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 com.android.internal.telephony;
18 
19 import java.util.Objects;
20 
21 /**
22  * Represent the version of underlying vendor HAL service.
23  * @see <a href="https://source.android.com/devices/architecture/hidl/versioning">
24  * HIDL versioning</a>.
25  */
26 public class HalVersion implements Comparable<HalVersion> {
27 
28     /** The HAL Version indicating that the version is unsupported */
29     public static final HalVersion UNSUPPORTED = new HalVersion(-2, -2);
30 
31     /** The HAL Version indicating that the version is unknown or invalid */
32     public static final HalVersion UNKNOWN = new HalVersion(-1, -1);
33 
34     public final int major;
35 
36     public final int minor;
37 
HalVersion(int major, int minor)38     public HalVersion(int major, int minor) {
39         this.major = major;
40         this.minor = minor;
41     }
42 
43     @Override
compareTo(HalVersion ver)44     public int compareTo(HalVersion ver) {
45         if (ver == null) {
46             return 1;
47         }
48         if (this.major > ver.major) {
49             return 1;
50         } else if (this.major < ver.major) {
51             return -1;
52         } else if (this.minor > ver.minor) {
53             return 1;
54         } else if (this.minor < ver.minor) {
55             return -1;
56         }
57         return 0;
58     }
59 
60     @Override
hashCode()61     public int hashCode() {
62         return Objects.hash(major, minor);
63     }
64 
65     @Override
equals(Object o)66     public boolean equals(Object o) {
67         return ((o instanceof HalVersion) && (o == this || compareTo((HalVersion) o) == 0));
68     }
69 
70     /**
71      * @return True if the version is greater than the compared version.
72      */
greater(HalVersion ver)73     public boolean greater(HalVersion ver) {
74         return compareTo(ver) > 0;
75     }
76 
77     /**
78      * @return True if the version is less than the compared version.
79      */
less(HalVersion ver)80     public boolean less(HalVersion ver) {
81         return compareTo(ver) < 0;
82     }
83 
84     /**
85      * @return True if the version is greater than or equal to the compared version.
86      */
greaterOrEqual(HalVersion ver)87     public boolean greaterOrEqual(HalVersion ver) {
88         return greater(ver) || equals(ver);
89     }
90 
91     /**
92      * @return True if the version is less than or equal to the compared version.
93      */
lessOrEqual(HalVersion ver)94     public boolean lessOrEqual(HalVersion ver) {
95         return less(ver) || equals(ver);
96     }
97 
98     @Override
toString()99     public String toString() {
100         return major + "." + minor;
101     }
102 }
103