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.hardware; 18 19 import android.os.Bundle; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * A CarSensorConfig object corresponds to a single sensor type coming from the car. 25 * @hide 26 */ 27 public class CarSensorConfig implements Parcelable { 28 /** List of property specific mapped elements in bundle for WHEEL_TICK_DISTANCE sensor*/ 29 /** @hide */ 30 public static final String WHEEL_TICK_DISTANCE_SUPPORTED_WHEELS = 31 "android.car.wheelTickDistanceSupportedWheels"; 32 /** @hide */ 33 public static final String WHEEL_TICK_DISTANCE_FRONT_LEFT_UM_PER_TICK = 34 "android.car.wheelTickDistanceFrontLeftUmPerTick"; 35 /** @hide */ 36 public static final String WHEEL_TICK_DISTANCE_FRONT_RIGHT_UM_PER_TICK = 37 "android.car.wheelTickDistanceFrontRightUmPerTick"; 38 /** @hide */ 39 public static final String WHEEL_TICK_DISTANCE_REAR_RIGHT_UM_PER_TICK = 40 "android.car.wheelTickDistanceRearRightUmPerTick"; 41 /** @hide */ 42 public static final String WHEEL_TICK_DISTANCE_REAR_LEFT_UM_PER_TICK = 43 "android.car.wheelTickDistanceRearLeftUmPerTick"; 44 45 /** Config data stored in Bundle */ 46 private final Bundle mConfig; 47 private final int mType; 48 49 /** @hide */ CarSensorConfig(Parcel in)50 public CarSensorConfig(Parcel in) { 51 mType = in.readInt(); 52 mConfig = in.readBundle(); 53 } 54 55 /** @hide */ 56 @Override describeContents()57 public int describeContents() { 58 return 0; 59 } 60 61 /** @hide */ 62 @Override writeToParcel(Parcel dest, int flags)63 public void writeToParcel(Parcel dest, int flags) { 64 dest.writeInt(mType); 65 dest.writeBundle(mConfig); 66 } 67 68 /** @hide */ 69 public static final Parcelable.Creator<CarSensorConfig> CREATOR = 70 new Parcelable.Creator<CarSensorConfig>() { 71 72 @Override 73 public CarSensorConfig createFromParcel(Parcel in) { 74 return new CarSensorConfig(in); 75 } 76 77 @Override 78 public CarSensorConfig[] newArray(int size) { 79 return new CarSensorConfig[size]; 80 } 81 }; 82 83 /** @hide */ CarSensorConfig(int type, Bundle b)84 public CarSensorConfig(int type, Bundle b) { 85 mType = type; 86 mConfig = b.deepCopy(); 87 } 88 checkType(int type)89 private void checkType(int type) { 90 if (mType == type) { 91 return; 92 } 93 throw new UnsupportedOperationException(String.format( 94 "Invalid sensor type: expected %d, got %d", type, mType)); 95 } 96 97 /** @hide */ getBundle()98 public Bundle getBundle() { 99 return mConfig; 100 } 101 102 /** @hide */ getInt(String key)103 public int getInt(String key) { 104 if (mConfig.containsKey(key)) { 105 return mConfig.getInt(key); 106 } 107 throw new IllegalArgumentException("SensorType " + mType 108 + " does not contain key: " + key); 109 } 110 111 /** @hide */ getType()112 public int getType() { 113 return mType; 114 } 115 116 /** @hide */ 117 @Override toString()118 public String toString() { 119 StringBuilder sb = new StringBuilder(); 120 sb.append(getClass().getName() + "["); 121 sb.append("mType: " + mType); 122 sb.append("mConfig: " + mConfig.toString()); 123 sb.append("]"); 124 return sb.toString(); 125 } 126 } 127