• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.car.hal;
17 
18 import static java.lang.Integer.toHexString;
19 
20 import android.car.hardware.CarPropertyConfig;
21 import android.car.hardware.CarPropertyValue;
22 import android.hardware.automotive.vehicle.VehiclePropertyType;
23 
24 
25 /**
26  * Utility functions to work with {@link CarPropertyConfig} and {@link CarPropertyValue}
27  */
28 /*package*/ final class CarPropertyUtils {
29 
30     /* Utility class has no public constructor */
CarPropertyUtils()31     private CarPropertyUtils() {}
32 
33     /**
34      * Gets the Java Class for the given property type.
35      *
36      * @param halType One of the {@link VehiclePropertyType}.
37      * @return The java class for the type.
38      */
getJavaClass(int halType)39     public static Class<?> getJavaClass(int halType) {
40         switch (halType) {
41             case VehiclePropertyType.BOOLEAN:
42                 return Boolean.class;
43             case VehiclePropertyType.FLOAT:
44                 return Float.class;
45             case VehiclePropertyType.INT32:
46                 return Integer.class;
47             case VehiclePropertyType.INT64:
48                 return Long.class;
49             case VehiclePropertyType.FLOAT_VEC:
50                 return Float[].class;
51             case VehiclePropertyType.INT32_VEC:
52                 return Integer[].class;
53             case VehiclePropertyType.INT64_VEC:
54                 return Long[].class;
55             case VehiclePropertyType.STRING:
56                 return String.class;
57             case VehiclePropertyType.BYTES:
58                 return byte[].class;
59             case VehiclePropertyType.MIXED:
60                 return Object[].class;
61             default:
62                 throw new IllegalArgumentException("Unexpected type: " + toHexString(halType));
63         }
64     }
65 }
66