1 /* 2 * Copyright (C) 2016 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.hardware; 18 19 import static java.lang.Integer.toHexString; 20 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 /** 26 * Stores values broken down by area for a vehicle property. 27 * 28 * @param <T> refer to Parcel#writeValue(Object) to get a list of all supported types. The class 29 * should be visible to framework as default class loader is being used here. 30 * 31 * @hide 32 */ 33 @SystemApi 34 public class CarPropertyValue<T> implements Parcelable { 35 private final int mPropertyId; 36 private final int mAreaId; 37 private final T mValue; 38 CarPropertyValue(int propertyId, T value)39 public CarPropertyValue(int propertyId, T value) { 40 this(propertyId, 0, value); 41 } 42 CarPropertyValue(int propertyId, int areaId, T value)43 public CarPropertyValue(int propertyId, int areaId, T value) { 44 mPropertyId = propertyId; 45 mAreaId = areaId; 46 mValue = value; 47 } 48 49 @SuppressWarnings("unchecked") CarPropertyValue(Parcel in)50 public CarPropertyValue(Parcel in) { 51 mPropertyId = in.readInt(); 52 mAreaId = in.readInt(); 53 mValue = (T) in.readValue(getClass().getClassLoader()); 54 } 55 56 public static final Creator<CarPropertyValue> CREATOR = new Creator<CarPropertyValue>() { 57 @Override 58 public CarPropertyValue createFromParcel(Parcel in) { 59 return new CarPropertyValue(in); 60 } 61 62 @Override 63 public CarPropertyValue[] newArray(int size) { 64 return new CarPropertyValue[size]; 65 } 66 }; 67 68 @Override describeContents()69 public int describeContents() { 70 return 0; 71 } 72 73 @Override writeToParcel(Parcel dest, int flags)74 public void writeToParcel(Parcel dest, int flags) { 75 dest.writeInt(mPropertyId); 76 dest.writeInt(mAreaId); 77 dest.writeValue(mValue); 78 } 79 getPropertyId()80 public int getPropertyId() { 81 return mPropertyId; 82 } 83 getAreaId()84 public int getAreaId() { 85 return mAreaId; 86 } 87 getValue()88 public T getValue() { 89 return mValue; 90 } 91 92 @Override toString()93 public String toString() { 94 return "CarPropertyValue{" + 95 "mPropertyId=0x" + toHexString(mPropertyId) + 96 ", mAreaId=0x" + toHexString(mAreaId) + 97 ", mValue=" + mValue + 98 '}'; 99 } 100 } 101