1 /* 2 * Copyright (C) 2021 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.telemetry; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 import java.util.Objects; 24 25 /** 26 * A parcelable that wraps around the Manifest name and version. 27 * 28 * @hide 29 */ 30 public final class MetricsConfigKey implements Parcelable { 31 32 @NonNull 33 private String mName; 34 private int mVersion; 35 36 @NonNull getName()37 public String getName() { 38 return mName; 39 } 40 getVersion()41 public int getVersion() { 42 return mVersion; 43 } 44 45 @Override writeToParcel(@onNull Parcel out, int flags)46 public void writeToParcel(@NonNull Parcel out, int flags) { 47 out.writeString(mName); 48 out.writeInt(mVersion); 49 } 50 MetricsConfigKey(Parcel in)51 private MetricsConfigKey(Parcel in) { 52 mName = in.readString(); 53 mVersion = in.readInt(); 54 } 55 MetricsConfigKey(@onNull String name, int version)56 public MetricsConfigKey(@NonNull String name, int version) { 57 mName = name; 58 mVersion = version; 59 } 60 61 @Override describeContents()62 public int describeContents() { 63 return 0; 64 } 65 66 @Override equals(Object o)67 public boolean equals(Object o) { 68 if (!(o instanceof MetricsConfigKey)) { 69 return false; 70 } 71 MetricsConfigKey other = (MetricsConfigKey) o; 72 return mName.equals(other.getName()) && mVersion == other.getVersion(); 73 } 74 75 @Override hashCode()76 public int hashCode() { 77 return Objects.hash(mName, mVersion); 78 } 79 80 public static final @NonNull Parcelable.Creator<MetricsConfigKey> CREATOR = 81 new Parcelable.Creator<MetricsConfigKey>() { 82 @Override 83 public MetricsConfigKey createFromParcel(Parcel in) { 84 return new MetricsConfigKey(in); 85 } 86 87 @Override 88 public MetricsConfigKey[] newArray(int size) { 89 return new MetricsConfigKey[size]; 90 } 91 }; 92 } 93