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.support.car.hardware; 18 19 import static androidx.annotation.RestrictTo.Scope.GROUP_ID; 20 21 import android.os.Bundle; 22 23 import androidx.annotation.RestrictTo; 24 25 /** 26 * A CarSensorConfig object corresponds to a single sensor type coming from the car. 27 * @hide 28 */ 29 public class CarSensorConfig { 30 /** List of property specific mapped elements in bundle for WHEEL_TICK_DISTANCE sensor*/ 31 /** @hide */ 32 public final static String WHEEL_TICK_DISTANCE_SUPPORTED_WHEELS = 33 "android.car.wheelTickDistanceSupportedWheels"; 34 /** @hide */ 35 public final static String WHEEL_TICK_DISTANCE_FRONT_LEFT_UM_PER_TICK = 36 "android.car.wheelTickDistanceFrontLeftUmPerTick"; 37 /** @hide */ 38 public final static String WHEEL_TICK_DISTANCE_FRONT_RIGHT_UM_PER_TICK = 39 "android.car.wheelTickDistanceFrontRightUmPerTick"; 40 /** @hide */ 41 public final static String WHEEL_TICK_DISTANCE_REAR_RIGHT_UM_PER_TICK = 42 "android.car.wheelTickDistanceRearRightUmPerTick"; 43 /** @hide */ 44 public final static String WHEEL_TICK_DISTANCE_REAR_LEFT_UM_PER_TICK = 45 "android.car.wheelTickDistanceRearLeftUmPerTick"; 46 47 /** Config data stored in Bundle */ 48 private final Bundle mConfig; 49 private final int mType; 50 51 private final static int RAW_BUNDLE_SIZE = 4; 52 private final static int WHEEL_TICK_DISTANCE_BUNDLE_SIZE = 6; 53 54 /** 55 * Constructs a {@link CarSensorConfig}. Handled by CarSensorManager implementations. 56 * App developers need not worry about constructing these objects. 57 * @hide 58 */ 59 @RestrictTo(GROUP_ID) 60 public CarSensorConfig(int type, Bundle in) { 61 mType = type; 62 mConfig = in.deepCopy(); 63 } 64 65 private void checkType(int type) { 66 if (mType == type) { 67 return; 68 } 69 throw new UnsupportedOperationException(String.format( 70 "Invalid sensor type: expected %d, got %d", type, mType)); 71 } 72 73 /** @hide */ 74 public int getInt(String key) { 75 if (mConfig.containsKey(key)) { 76 return mConfig.getInt(key); 77 } else { 78 throw new IllegalArgumentException("SensorType " + mType + 79 " does not contain key: " + key); 80 } 81 } 82 83 /** @hide */ 84 public int getType() { 85 return mType; 86 } 87 88 /** @hide */ 89 @Override 90 public String toString() { 91 StringBuilder sb = new StringBuilder(); 92 sb.append(getClass().getName() + "["); 93 sb.append("mConfig: " + mConfig.toString()); 94 sb.append("mType: " + mType); 95 sb.append("]"); 96 return sb.toString(); 97 } 98 } 99