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