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