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