• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.car.vms;
18 
19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE;
20 
21 import android.annotation.NonNull;
22 import android.annotation.SystemApi;
23 import android.car.annotation.AddedInOrBefore;
24 import android.car.builtin.os.ParcelHelper;
25 import android.os.Parcel;
26 import android.os.Parcelable;
27 import android.util.ArraySet;
28 
29 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
30 import com.android.car.internal.util.AnnotationValidations;
31 
32 import java.util.Collections;
33 import java.util.Set;
34 
35 /**
36  * Availability of Vehicle Map Service layers.
37  *
38  * The layer availability is used by subscribers to determine which {@link VmsLayer}s are available
39  * for subscription and which publishers are offering to publish data for those layers. However,
40  * the Vehicle Map Service will allow subscription requests for unavailable layers.
41  *
42  * Sequence numbers are used to indicate the succession of availability states, and increase
43  * monotonically with each change in layer availability. They must be used by clients to ignore
44  * states that are received out-of-order.
45  *
46  * @hide
47  */
48 @SystemApi
49 public final class VmsAvailableLayers implements Parcelable {
50     /**
51      * Sequence number of the availability state
52      */
53     private final int mSequenceNumber;
54 
55     /**
56      * Set of layers available for subscription
57      */
58     private @NonNull Set<VmsAssociatedLayer> mAssociatedLayers;
59 
onConstructed()60     private void onConstructed() {
61         mAssociatedLayers = Collections.unmodifiableSet(mAssociatedLayers);
62     }
63 
parcelAssociatedLayers(Parcel dest, int flags)64     private void parcelAssociatedLayers(Parcel dest, int flags) {
65         ParcelHelper.writeArraySet(dest, new ArraySet<>(mAssociatedLayers));
66     }
67 
68     @SuppressWarnings("unchecked")
unparcelAssociatedLayers(Parcel in)69     private Set<VmsAssociatedLayer> unparcelAssociatedLayers(Parcel in) {
70         return (Set<VmsAssociatedLayer>) ParcelHelper.readArraySet(in,
71                 VmsAssociatedLayer.class.getClassLoader());
72     }
73 
74     /**
75      * Creates a new VmsAvailableLayers.
76      *
77      * @param associatedLayers
78      *   Set of layers available for subscription
79      * @param sequenceNumber
80      *   Sequence number of the availability state
81      * @deprecated Use {@link #VmsAvailableLayers(int, Set)} instead
82      */
83     @Deprecated
VmsAvailableLayers(@onNull Set<VmsAssociatedLayer> associatedLayers, int sequenceNumber)84     public VmsAvailableLayers(@NonNull Set<VmsAssociatedLayer> associatedLayers,
85             int sequenceNumber) {
86         this(sequenceNumber, associatedLayers);
87     }
88 
89     /**
90      * Sequence number of the availability state
91      *
92      * @deprecated Use {@link #getSequenceNumber()} instead
93      */
94     @Deprecated
95     @AddedInOrBefore(majorVersion = 33)
getSequence()96     public int getSequence() {
97         return mSequenceNumber;
98     }
99 
100     /**
101      * Creates a new VmsAvailableLayers.
102      *
103      * @param sequenceNumber
104      *   Sequence number of the availability state
105      * @param associatedLayers
106      *   Set of layers available for subscription
107      */
VmsAvailableLayers( int sequenceNumber, @NonNull Set<VmsAssociatedLayer> associatedLayers)108     public VmsAvailableLayers(
109             int sequenceNumber,
110             @NonNull Set<VmsAssociatedLayer> associatedLayers) {
111         this.mSequenceNumber = sequenceNumber;
112         this.mAssociatedLayers = associatedLayers;
113         AnnotationValidations.validate(
114                 NonNull.class, null, mAssociatedLayers);
115 
116         onConstructed();
117     }
118 
119     /**
120      * Sequence number of the availability state
121      */
122     @AddedInOrBefore(majorVersion = 33)
getSequenceNumber()123     public int getSequenceNumber() {
124         return mSequenceNumber;
125     }
126 
127     /**
128      * Set of layers available for subscription
129      */
130     @AddedInOrBefore(majorVersion = 33)
getAssociatedLayers()131     public @NonNull Set<VmsAssociatedLayer> getAssociatedLayers() {
132         return mAssociatedLayers;
133     }
134 
135     @Override
136     @AddedInOrBefore(majorVersion = 33)
toString()137     public String toString() {
138         // You can override field toString logic by defining methods like:
139         // String fieldNameToString() { ... }
140 
141         return "VmsAvailableLayers { " +
142                 "sequenceNumber = " + mSequenceNumber + ", " +
143                 "associatedLayers = " + mAssociatedLayers +
144         " }";
145     }
146 
147     @Override
148     @AddedInOrBefore(majorVersion = 33)
equals(@ndroid.annotation.Nullable Object o)149     public boolean equals(@android.annotation.Nullable Object o) {
150         // You can override field equality logic by defining either of the methods like:
151         // boolean fieldNameEquals(VmsAvailableLayers other) { ... }
152         // boolean fieldNameEquals(FieldType otherValue) { ... }
153 
154         if (this == o) return true;
155         if (o == null || getClass() != o.getClass()) return false;
156         @SuppressWarnings("unchecked")
157         VmsAvailableLayers that = (VmsAvailableLayers) o;
158         //noinspection PointlessBooleanExpression
159         return true
160                 && mSequenceNumber == that.mSequenceNumber
161                 && java.util.Objects.equals(mAssociatedLayers, that.mAssociatedLayers);
162     }
163 
164     @Override
165     @AddedInOrBefore(majorVersion = 33)
hashCode()166     public int hashCode() {
167         // You can override field hashCode logic by defining methods like:
168         // int fieldNameHashCode() { ... }
169 
170         int _hash = 1;
171         _hash = 31 * _hash + mSequenceNumber;
172         _hash = 31 * _hash + java.util.Objects.hashCode(mAssociatedLayers);
173         return _hash;
174     }
175 
176     @Override
177     @AddedInOrBefore(majorVersion = 33)
writeToParcel(@onNull Parcel dest, int flags)178     public void writeToParcel(@NonNull Parcel dest, int flags) {
179         // You can override field parcelling by defining methods like:
180         // void parcelFieldName(Parcel dest, int flags) { ... }
181 
182         dest.writeInt(mSequenceNumber);
183         parcelAssociatedLayers(dest, flags);
184     }
185 
186     @Override
187     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
188     @AddedInOrBefore(majorVersion = 33)
describeContents()189     public int describeContents() { return 0; }
190 
191     /** @hide */
192     @SuppressWarnings({"unchecked", "RedundantCast"})
VmsAvailableLayers(@onNull Parcel in)193     /* package-private */ VmsAvailableLayers(@NonNull Parcel in) {
194         // You can override field unparcelling by defining methods like:
195         // static FieldType unparcelFieldName(Parcel in) { ... }
196 
197         int sequenceNumber = in.readInt();
198         Set<VmsAssociatedLayer> associatedLayers = unparcelAssociatedLayers(in);
199 
200         this.mSequenceNumber = sequenceNumber;
201         this.mAssociatedLayers = associatedLayers;
202         AnnotationValidations.validate(
203                 NonNull.class, null, mAssociatedLayers);
204 
205         onConstructed();
206     }
207 
208     @AddedInOrBefore(majorVersion = 33)
209     public static final @NonNull Parcelable.Creator<VmsAvailableLayers> CREATOR
210             = new Parcelable.Creator<VmsAvailableLayers>() {
211         @Override
212         public VmsAvailableLayers[] newArray(int size) {
213             return new VmsAvailableLayers[size];
214         }
215 
216         @Override
217         public VmsAvailableLayers createFromParcel(@NonNull Parcel in) {
218             return new VmsAvailableLayers(in);
219         }
220     };
221 }
222