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