• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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;
18 
19 import android.annotation.NonNull;
20 import android.car.annotation.ValueTypeDef;
21 import android.car.builtin.util.Slogf;
22 import android.car.hardware.CarPropertyValue;
23 import android.car.hardware.property.CarPropertyManager;
24 import android.car.hardware.property.ICarProperty;
25 import android.os.Bundle;
26 import android.os.IBinder;
27 
28 import java.util.Arrays;
29 
30 /**
31  * Utility to retrieve various static information from car. Each data are grouped as {@link Bundle}
32  * and relevant data can be checked from {@link Bundle} using pre-specified keys.
33  *
34  * @deprecated Use {@link CarPropertyManager} instead.
35  */
36 @Deprecated
37 public final class CarInfoManager extends CarManagerBase {
38 
39     private static final String TAG = CarInfoManager.class.getSimpleName();
40 
41     private final CarPropertyManager mCarPropertyMgr;
42     /**
43      * Key for manufacturer of the car. Passed in basic info Bundle.
44      * @hide
45      */
46     @ValueTypeDef(type = Integer.class)
47     public static final int BASIC_INFO_KEY_MANUFACTURER = 0x11100101;
48     /**
49      * Key for model name of the car. This information may not necessarily allow distinguishing
50      * different car models as the same name may be used for different cars depending on
51      * manufacturers. Passed in basic info Bundle.
52      * @hide
53      */
54     @ValueTypeDef(type = Integer.class)
55     public static final int BASIC_INFO_KEY_MODEL = 0x11100102;
56     /**
57      * Key for model year of the car in AD. Passed in basic info Bundle.
58      * @hide
59      */
60     @ValueTypeDef(type = Integer.class)
61     public static final int BASIC_INFO_KEY_MODEL_YEAR = 0x11400103;
62     /**
63      * Key for unique identifier for the car. This is not VIN, and id is persistent until user
64      * resets it. Passed in basic info Bundle.
65      * @hide
66      */
67     @ValueTypeDef(type = String.class)
68     public static final String BASIC_INFO_KEY_VEHICLE_ID = "android.car.vehicle-id";
69     /**
70      * Key for product configuration info.
71      * @hide
72      */
73     @ValueTypeDef(type = String.class)
74     public static final String INFO_KEY_PRODUCT_CONFIGURATION = "android.car.product-config";
75     /**
76      * Key for driver seat of the car.
77      * @hide
78      */
79     @ValueTypeDef(type = Integer.class)
80     public static final int BASIC_INFO_DRIVER_SEAT = 0x1540010a;
81     /**
82      * Key for EV port location of vehicle.
83      * @hide
84      */
85     @ValueTypeDef(type = Integer.class)
86     public static final int BASIC_INFO_EV_PORT_LOCATION = 0x11400109;
87     /**
88      * Key for fuel door location of vehicle.
89      * @hide
90      */
91     @ValueTypeDef(type = Integer.class)
92     public static final int BASIC_INFO_FUEL_DOOR_LOCATION = 0x11400108;
93     /**
94      * Key for Fuel Capacity in milliliters.  Passed in basic info Bundle.
95      * @hide
96      */
97     @ValueTypeDef(type = Integer.class)
98     public static final int BASIC_INFO_FUEL_CAPACITY = 0x11600104;
99     /**
100      * Key for Fuel Types.  This is an array of fuel types the vehicle supports.
101      * Passed in basic info Bundle.
102      * @hide
103      */
104     @ValueTypeDef(type = Integer.class)
105     public static final int BASIC_INFO_FUEL_TYPES = 0x11410105;
106     /**
107      * Key for EV Battery Capacity in WH.  Passed in basic info Bundle.
108      * @hide
109      */
110     @ValueTypeDef(type = Integer.class)
111     public static final int BASIC_INFO_EV_BATTERY_CAPACITY = 0x11600106;
112     /**
113      * Key for EV Connector Types.  This is an array of connector types the vehicle supports.
114      * Passed in basic info Bundle.
115      * @hide
116      */
117     @ValueTypeDef(type = Integer[].class)
118     public static final int BASIC_INFO_EV_CONNECTOR_TYPES = 0x11410107;
119 
120     /**
121      * @return Manufacturer of the car.  Empty if not available.
122      */
123     @NonNull
getManufacturer()124     public String getManufacturer() {
125         return  getPropertyWithDefaultValue(String.class, BASIC_INFO_KEY_MANUFACTURER, "");
126     }
127 
128     /**
129      * @return Model name of the car, empty if not available.  This information
130      * may not necessarily allow distinguishing different car models as the same
131      * name may be used for different cars depending on manufacturers.
132      */
133     @NonNull
getModel()134     public String getModel() {
135         return getPropertyWithDefaultValue(String.class, BASIC_INFO_KEY_MODEL, "");
136     }
137 
138     /**
139      * @return Model year of the car in AD.  Empty if not available.
140      * @deprecated Use {@link #getModelYearInInteger()} instead.
141      */
142     @Deprecated
143     @NonNull
getModelYear()144     public String getModelYear() {
145         int year =  getModelYearInInteger();
146         return year == 0 ? "" : Integer.toString(year);
147     }
148 
149     /**
150      * @return Model year of the car in AD.  0 if not available.
151      */
getModelYearInInteger()152     public int getModelYearInInteger() {
153         return getPropertyWithDefaultValue(Integer.class, BASIC_INFO_KEY_MODEL_YEAR, 0);
154     }
155 
156     /**
157      * @return always return empty string.
158      * @deprecated no support for car's identifier
159      */
160     @Deprecated
getVehicleId()161     public String getVehicleId() {
162         return "";
163     }
164 
165     /**
166      * @return Fuel capacity of the car in milliliters.  0 if car doesn't run on
167      *         fuel.
168      */
getFuelCapacity()169     public float getFuelCapacity() {
170         return getPropertyWithDefaultValue(Float.class, BASIC_INFO_FUEL_CAPACITY, 0f);
171     }
172 
173     /**
174      * @return Array of FUEL_TYPEs available in the car.  Empty array if no fuel
175      * types available.
176      */
getFuelTypes()177     public @FuelType.Enum int[] getFuelTypes() {
178         Integer[] fuels = getPropertyWithDefaultValue(Integer[].class, BASIC_INFO_FUEL_TYPES,
179                 new Integer[]{});
180         return Arrays.stream(fuels).mapToInt(Integer::intValue).toArray();
181     }
182 
183     /**
184      *
185      * @return Battery capacity of the car in Watt-Hour(Wh). Return 0 if car doesn't run on battery.
186      */
getEvBatteryCapacity()187     public float getEvBatteryCapacity() {
188         return getPropertyWithDefaultValue(Float.class, BASIC_INFO_EV_BATTERY_CAPACITY, 0f);
189     }
190 
191     /**
192      * @return Array of EV_CONNECTOR_TYPEs available in the car.  Empty array if
193      *         no connector types available.
194      */
getEvConnectorTypes()195     public @EvConnectorType.Enum int[] getEvConnectorTypes() {
196         Integer[] valueInHal = getPropertyWithDefaultValue(Integer[].class,
197                 BASIC_INFO_EV_CONNECTOR_TYPES, new Integer[]{});
198 
199         int[] connectorTypes = new int[valueInHal.length];
200         for (int i = 0; i < valueInHal.length; i++) {
201             switch (valueInHal[i]) {
202                 case 1: // IEC_TYPE_1_AC
203                     connectorTypes[i] = EvConnectorType.J1772;
204                     break;
205                 case 2: // IEC_TYPE_2_AC
206                     connectorTypes[i] = EvConnectorType.MENNEKES;
207                     break;
208                 case 3: // IEC_TYPE_3_AC
209                     connectorTypes[i] = EvConnectorType.SCAME;
210                     break;
211                 case 4: // IEC_TYPE_4_DC
212                     connectorTypes[i] = EvConnectorType.CHADEMO;
213                     break;
214                 case 5: // IEC_TYPE_1_CCS_DC
215                     connectorTypes[i] = EvConnectorType.COMBO_1;
216                     break;
217                 case 6: // IEC_TYPE_2_CCS_DC
218                     connectorTypes[i] = EvConnectorType.COMBO_2;
219                     break;
220                 case 7: // TESLA_ROADSTER
221                     connectorTypes[i] = EvConnectorType.TESLA_ROADSTER;
222                     break;
223                 case 8: // TESLA_HPWC
224                     connectorTypes[i] = EvConnectorType.TESLA_HPWC;
225                     break;
226                 case 9: // TESLA_SUPERCHARGER
227                     connectorTypes[i] = EvConnectorType.TESLA_SUPERCHARGER;
228                     break;
229                 case 10: // GBT_AC
230                     connectorTypes[i] = EvConnectorType.GBT;
231                     break;
232                 case 11: // GBT_DC
233                     connectorTypes[i] = EvConnectorType.GBT_DC;
234                     break;
235                 case 101: // OTHER
236                     connectorTypes[i] = EvConnectorType.OTHER;
237                     break;
238                 default:
239                     connectorTypes[i] = EvConnectorType.UNKNOWN;
240             }
241         }
242         return connectorTypes;
243     }
244 
245     /**
246      * @return Driver seat's location. Returns {@link VehicleAreaSeat#SEAT_UNKNOWN} if the sensor
247      * is not available.
248      */
getDriverSeat()249     public @VehicleAreaSeat.Enum int getDriverSeat() {
250         return getPropertyWithDefaultValue(Integer.class, BASIC_INFO_DRIVER_SEAT,
251                 VehicleAreaSeat.SEAT_UNKNOWN);
252     }
253 
254     /**
255      * @return EV port location of the car. Returns {@link PortLocationType#UNKNOWN} if the sensor
256      * is not available.
257      */
getEvPortLocation()258     public @PortLocationType.Enum int getEvPortLocation() {
259         return getPropertyWithDefaultValue(Integer.class, BASIC_INFO_EV_PORT_LOCATION,
260                 PortLocationType.UNKNOWN);
261     }
262 
263     /**
264      * @return Fuel door location of the car.Returns {@link PortLocationType#UNKNOWN} if the sensor
265      * is not available.
266      */
getFuelDoorLocation()267     public @PortLocationType.Enum int getFuelDoorLocation() {
268         return getPropertyWithDefaultValue(Integer.class, BASIC_INFO_FUEL_DOOR_LOCATION,
269                 PortLocationType.UNKNOWN);
270     }
271 
getPropertyWithDefaultValue(Class<T> clazz, int propId, T defaultValue)272     private <T> T getPropertyWithDefaultValue(Class<T> clazz, int propId, T defaultValue) {
273         try {
274             CarPropertyValue<T> carProp = mCarPropertyMgr.getProperty(
275                     clazz, propId, 0);
276             if (carProp != null && carProp.getStatus() == CarPropertyValue.STATUS_AVAILABLE) {
277                 return carProp.getValue();
278             }
279         } catch (Exception e) {
280             Slogf.e(TAG, "Failed to get property value for 0x:" + Integer.toHexString(propId)
281                     + " ,returns default value" + defaultValue);
282         }
283         return defaultValue;
284     }
285 
286     /** @hide */
CarInfoManager(Car car, IBinder service)287     public CarInfoManager(Car car, IBinder service) {
288         super(car);
289         ICarProperty mCarPropertyService = ICarProperty.Stub.asInterface(service);
290         mCarPropertyMgr = new CarPropertyManager(car, mCarPropertyService);
291     }
292 
293     /** @hide */
onCarDisconnected()294     public void onCarDisconnected() {
295         mCarPropertyMgr.onCarDisconnected();
296     }
297 }
298