• 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.Objects;
34 import java.util.Set;
35 
36 /**
37  * A Vehicle Map Service layer with a list of publisher IDs it is associated with.
38  *
39  * @hide
40  */
41 @SystemApi
42 public final class VmsAssociatedLayer implements Parcelable {
43     /**
44      * Layer being offered
45      */
46     private final @NonNull VmsLayer mVmsLayer;
47 
48     /**
49      * IDs of providers that publish the layer
50      */
51     private @NonNull Set<Integer> mProviderIds;
52 
onConstructed()53     private void onConstructed() {
54         mProviderIds = Collections.unmodifiableSet(mProviderIds);
55     }
56 
parcelProviderIds(Parcel dest, int flags)57     private void parcelProviderIds(Parcel dest, int flags) {
58         ParcelHelper.writeArraySet(dest, new ArraySet<>(mProviderIds));
59     }
60 
61     @SuppressWarnings("unchecked")
unparcelProviderIds(Parcel in)62     private Set<Integer> unparcelProviderIds(Parcel in) {
63         return (Set<Integer>) ParcelHelper.readArraySet(in, Integer.class.getClassLoader());
64     }
65 
66     /**
67      * IDs of publishers that publish the layer
68      *
69      * @deprecated Use {@link #getProviderIds()} instead
70      */
71     @Deprecated
72     @NonNull
73     @AddedInOrBefore(majorVersion = 33)
getPublisherIds()74     public Set<Integer> getPublisherIds() {
75         return mProviderIds;
76     }
77 
78     /**
79      * Creates a new VmsAssociatedLayer.
80      *
81      * @param vmsLayer
82      *   Layer being offered
83      * @param providerIds
84      *   IDs of providers that publish the layer
85      */
VmsAssociatedLayer( @onNull VmsLayer vmsLayer, @NonNull Set<Integer> providerIds)86     public VmsAssociatedLayer(
87             @NonNull VmsLayer vmsLayer,
88             @NonNull Set<Integer> providerIds) {
89         this.mVmsLayer = vmsLayer;
90         AnnotationValidations.validate(
91                 NonNull.class, null, mVmsLayer);
92         this.mProviderIds = providerIds;
93         AnnotationValidations.validate(
94                 NonNull.class, null, mProviderIds);
95 
96         onConstructed();
97     }
98 
99     /**
100      * Layer being offered
101      */
102     @AddedInOrBefore(majorVersion = 33)
getVmsLayer()103     public @NonNull VmsLayer getVmsLayer() {
104         return mVmsLayer;
105     }
106 
107     /**
108      * IDs of providers that publish the layer
109      */
110     @AddedInOrBefore(majorVersion = 33)
getProviderIds()111     public @NonNull Set<Integer> getProviderIds() {
112         return mProviderIds;
113     }
114 
115     @Override
116     @AddedInOrBefore(majorVersion = 33)
toString()117     public String toString() {
118         // You can override field toString logic by defining methods like:
119         // String fieldNameToString() { ... }
120 
121         return "VmsAssociatedLayer { " +
122                 "vmsLayer = " + mVmsLayer + ", " +
123                 "providerIds = " + mProviderIds +
124         " }";
125     }
126 
127     @Override
128     @AddedInOrBefore(majorVersion = 33)
equals(@ndroid.annotation.Nullable Object o)129     public boolean equals(@android.annotation.Nullable Object o) {
130         // You can override field equality logic by defining either of the methods like:
131         // boolean fieldNameEquals(VmsAssociatedLayer other) { ... }
132         // boolean fieldNameEquals(FieldType otherValue) { ... }
133 
134         if (this == o) return true;
135         if (o == null || getClass() != o.getClass()) return false;
136         @SuppressWarnings("unchecked")
137         VmsAssociatedLayer that = (VmsAssociatedLayer) o;
138         //noinspection PointlessBooleanExpression
139         return true
140                 && Objects.equals(mVmsLayer, that.mVmsLayer)
141                 && Objects.equals(mProviderIds, that.mProviderIds);
142     }
143 
144     @Override
145     @AddedInOrBefore(majorVersion = 33)
hashCode()146     public int hashCode() {
147         // You can override field hashCode logic by defining methods like:
148         // int fieldNameHashCode() { ... }
149 
150         int _hash = 1;
151         _hash = 31 * _hash + Objects.hashCode(mVmsLayer);
152         _hash = 31 * _hash + Objects.hashCode(mProviderIds);
153         return _hash;
154     }
155 
156     @Override
157     @AddedInOrBefore(majorVersion = 33)
writeToParcel(@onNull Parcel dest, int flags)158     public void writeToParcel(@NonNull Parcel dest, int flags) {
159         // You can override field parcelling by defining methods like:
160         // void parcelFieldName(Parcel dest, int flags) { ... }
161 
162         dest.writeTypedObject(mVmsLayer, flags);
163         parcelProviderIds(dest, flags);
164     }
165 
166     @Override
167     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
168     @AddedInOrBefore(majorVersion = 33)
describeContents()169     public int describeContents() { return 0; }
170 
171     /** @hide */
172     @SuppressWarnings({"unchecked", "RedundantCast"})
VmsAssociatedLayer(@onNull Parcel in)173     /* package-private */ VmsAssociatedLayer(@NonNull Parcel in) {
174         // You can override field unparcelling by defining methods like:
175         // static FieldType unparcelFieldName(Parcel in) { ... }
176 
177         VmsLayer vmsLayer = (VmsLayer) in.readTypedObject(VmsLayer.CREATOR);
178         Set<Integer> providerIds = unparcelProviderIds(in);
179 
180         this.mVmsLayer = vmsLayer;
181         AnnotationValidations.validate(
182                 NonNull.class, null, mVmsLayer);
183         this.mProviderIds = providerIds;
184         AnnotationValidations.validate(
185                 NonNull.class, null, mProviderIds);
186 
187         onConstructed();
188     }
189 
190     @AddedInOrBefore(majorVersion = 33)
191     public static final @NonNull Parcelable.Creator<VmsAssociatedLayer> CREATOR
192             = new Parcelable.Creator<VmsAssociatedLayer>() {
193         @Override
194         public VmsAssociatedLayer[] newArray(int size) {
195             return new VmsAssociatedLayer[size];
196         }
197 
198         @Override
199         public VmsAssociatedLayer createFromParcel(@NonNull Parcel in) {
200             return new VmsAssociatedLayer(in);
201         }
202     };
203 }
204