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