• 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  * A Vehicle Map Service layer offering for a single publisher.
37  *
38  * Contains all layers the publisher can offer, and the layers that offering depends on.
39  *
40  * A layer will not be advertised to subscribers unless all of its dependencies are met.
41  *
42  * @deprecated Use {@link VmsClient#setProviderOfferings(int, Set)} instead
43  *
44  * @hide
45  */
46 @Deprecated
47 @SystemApi
48 public final class VmsLayersOffering implements Parcelable {
49     /**
50      * Layers and dependencies in the offering
51      */
52     private @NonNull Set<VmsLayerDependency> mDependencies;
53 
54     /**
55      * ID of the publisher making the offering
56      */
57     private final int mPublisherId;
58 
onConstructed()59     private void onConstructed() {
60         mDependencies = Collections.unmodifiableSet(mDependencies);
61     }
62 
parcelDependencies(Parcel dest, int flags)63     private void parcelDependencies(Parcel dest, int flags) {
64         ParcelHelper.writeArraySet(dest, new ArraySet<>(mDependencies));
65     }
66 
67     @SuppressWarnings("unchecked")
unparcelDependencies(Parcel in)68     private Set<VmsLayerDependency> unparcelDependencies(Parcel in) {
69         return (Set<VmsLayerDependency>) ParcelHelper.readArraySet(in,
70                 VmsLayerDependency.class.getClassLoader());
71     }
72 
73     /**
74      * Creates a new VmsLayersOffering.
75      *
76      * @param dependencies
77      *   Layers and dependencies in the offering
78      * @param publisherId
79      *   ID of the publisher making the offering
80      */
VmsLayersOffering( @onNull Set<VmsLayerDependency> dependencies, int publisherId)81     public VmsLayersOffering(
82             @NonNull Set<VmsLayerDependency> dependencies,
83             int publisherId) {
84         this.mDependencies = dependencies;
85         AnnotationValidations.validate(
86                 NonNull.class, null, mDependencies);
87         this.mPublisherId = publisherId;
88 
89         onConstructed();
90     }
91 
92     /**
93      * Layers and dependencies in the offering
94      */
95     @AddedInOrBefore(majorVersion = 33)
getDependencies()96     public @NonNull Set<VmsLayerDependency> getDependencies() {
97         return mDependencies;
98     }
99 
100     /**
101      * ID of the publisher making the offering
102      */
103     @AddedInOrBefore(majorVersion = 33)
getPublisherId()104     public int getPublisherId() {
105         return mPublisherId;
106     }
107 
108     @Override
109     @AddedInOrBefore(majorVersion = 33)
toString()110     public String toString() {
111         // You can override field toString logic by defining methods like:
112         // String fieldNameToString() { ... }
113 
114         return "VmsLayersOffering { " +
115                 "dependencies = " + mDependencies + ", " +
116                 "publisherId = " + mPublisherId +
117         " }";
118     }
119 
120     @Override
121     @AddedInOrBefore(majorVersion = 33)
equals(@ndroid.annotation.Nullable Object o)122     public boolean equals(@android.annotation.Nullable Object o) {
123         // You can override field equality logic by defining either of the methods like:
124         // boolean fieldNameEquals(VmsLayersOffering other) { ... }
125         // boolean fieldNameEquals(FieldType otherValue) { ... }
126 
127         if (this == o) return true;
128         if (o == null || getClass() != o.getClass()) return false;
129         @SuppressWarnings("unchecked")
130         VmsLayersOffering that = (VmsLayersOffering) o;
131         //noinspection PointlessBooleanExpression
132         return true
133                 && java.util.Objects.equals(mDependencies, that.mDependencies)
134                 && mPublisherId == that.mPublisherId;
135     }
136 
137     @Override
138     @AddedInOrBefore(majorVersion = 33)
hashCode()139     public int hashCode() {
140         // You can override field hashCode logic by defining methods like:
141         // int fieldNameHashCode() { ... }
142 
143         int _hash = 1;
144         _hash = 31 * _hash + java.util.Objects.hashCode(mDependencies);
145         _hash = 31 * _hash + mPublisherId;
146         return _hash;
147     }
148 
149     @Override
150     @AddedInOrBefore(majorVersion = 33)
writeToParcel(@onNull Parcel dest, int flags)151     public void writeToParcel(@NonNull Parcel dest, int flags) {
152         // You can override field parcelling by defining methods like:
153         // void parcelFieldName(Parcel dest, int flags) { ... }
154 
155         parcelDependencies(dest, flags);
156         dest.writeInt(mPublisherId);
157     }
158 
159     @Override
160     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
161     @AddedInOrBefore(majorVersion = 33)
describeContents()162     public int describeContents() { return 0; }
163 
164     /** @hide */
165     @SuppressWarnings({"unchecked", "RedundantCast"})
VmsLayersOffering(@onNull Parcel in)166     /* package-private */ VmsLayersOffering(@NonNull Parcel in) {
167         // You can override field unparcelling by defining methods like:
168         // static FieldType unparcelFieldName(Parcel in) { ... }
169 
170         Set<VmsLayerDependency> dependencies = unparcelDependencies(in);
171         int publisherId = in.readInt();
172 
173         this.mDependencies = dependencies;
174         AnnotationValidations.validate(
175                 NonNull.class, null, mDependencies);
176         this.mPublisherId = publisherId;
177 
178         onConstructed();
179     }
180 
181     @AddedInOrBefore(majorVersion = 33)
182     public static final @NonNull Parcelable.Creator<VmsLayersOffering> CREATOR
183             = new Parcelable.Creator<VmsLayersOffering>() {
184         @Override
185         public VmsLayersOffering[] newArray(int size) {
186             return new VmsLayersOffering[size];
187         }
188 
189         @Override
190         public VmsLayersOffering createFromParcel(@NonNull Parcel in) {
191             return new VmsLayersOffering(in);
192         }
193     };
194 }
195