summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'car-lib/src/android/car/CarInfoManager.java')
-rw-r--r--car-lib/src/android/car/CarInfoManager.java56
1 files changed, 13 insertions, 43 deletions
diff --git a/car-lib/src/android/car/CarInfoManager.java b/car-lib/src/android/car/CarInfoManager.java
index b228ca7c..d90883b6 100644
--- a/car-lib/src/android/car/CarInfoManager.java
+++ b/car-lib/src/android/car/CarInfoManager.java
@@ -16,16 +16,12 @@
16 16
17package android.car; 17package android.car;
18 18
19import static java.lang.Integer.toHexString;
20
21import android.annotation.Nullable; 19import android.annotation.Nullable;
22import android.car.annotation.ValueTypeDef; 20import android.car.annotation.ValueTypeDef;
23import android.car.hardware.CarPropertyValue; 21import android.car.hardware.CarPropertyValue;
24import android.car.hardware.property.ICarProperty; 22import android.car.hardware.property.CarPropertyManager;
25import android.os.Bundle; 23import android.os.Bundle;
26import android.os.IBinder; 24import android.os.IBinder;
27import android.os.RemoteException;
28import android.util.Log;
29 25
30 26
31/** 27/**
@@ -36,6 +32,7 @@ public final class CarInfoManager implements CarManagerBase{
36 32
37 private static final boolean DBG = false; 33 private static final boolean DBG = false;
38 private static final String TAG = "CarInfoManager"; 34 private static final String TAG = "CarInfoManager";
35 private final CarPropertyManager mCarPropertyMgr;
39 /** 36 /**
40 * Key for manufacturer of the car. Passed in basic info Bundle. 37 * Key for manufacturer of the car. Passed in basic info Bundle.
41 * @hide 38 * @hide
@@ -112,17 +109,15 @@ public final class CarInfoManager implements CarManagerBase{
112 * Passed in basic info Bundle. 109 * Passed in basic info Bundle.
113 * @hide 110 * @hide
114 */ 111 */
115 @ValueTypeDef(type = Integer.class) 112 @ValueTypeDef(type = Integer[].class)
116 public static final int BASIC_INFO_EV_CONNECTOR_TYPES = 0x11410107; 113 public static final int BASIC_INFO_EV_CONNECTOR_TYPES = 0x11410107;
117 114
118 private final ICarProperty mService;
119
120 /** 115 /**
121 * @return Manufacturer of the car. Null if not available. 116 * @return Manufacturer of the car. Null if not available.
122 */ 117 */
123 @Nullable 118 @Nullable
124 public String getManufacturer() throws CarNotConnectedException { 119 public String getManufacturer() throws CarNotConnectedException {
125 CarPropertyValue<String> carProp = getProperty(String.class, 120 CarPropertyValue<String> carProp = mCarPropertyMgr.getProperty(String.class,
126 BASIC_INFO_KEY_MANUFACTURER, 0); 121 BASIC_INFO_KEY_MANUFACTURER, 0);
127 return carProp != null ? carProp.getValue() : null; 122 return carProp != null ? carProp.getValue() : null;
128 } 123 }
@@ -134,7 +129,8 @@ public final class CarInfoManager implements CarManagerBase{
134 */ 129 */
135 @Nullable 130 @Nullable
136 public String getModel() throws CarNotConnectedException { 131 public String getModel() throws CarNotConnectedException {
137 CarPropertyValue<String> carProp = getProperty(String.class, BASIC_INFO_KEY_MODEL, 0); 132 CarPropertyValue<String> carProp = mCarPropertyMgr.getProperty(
133 String.class, BASIC_INFO_KEY_MODEL, 0);
138 return carProp != null ? carProp.getValue() : null; 134 return carProp != null ? carProp.getValue() : null;
139 } 135 }
140 136
@@ -143,7 +139,7 @@ public final class CarInfoManager implements CarManagerBase{
143 */ 139 */
144 @Nullable 140 @Nullable
145 public String getModelYear() throws CarNotConnectedException { 141 public String getModelYear() throws CarNotConnectedException {
146 CarPropertyValue<String> carProp = getProperty(String.class, 142 CarPropertyValue<String> carProp = mCarPropertyMgr.getProperty(String.class,
147 BASIC_INFO_KEY_MODEL_YEAR, 0); 143 BASIC_INFO_KEY_MODEL_YEAR, 0);
148 return carProp != null ? carProp.getValue() : null; 144 return carProp != null ? carProp.getValue() : null;
149 } 145 }
@@ -163,7 +159,7 @@ public final class CarInfoManager implements CarManagerBase{
163 * fuel. 159 * fuel.
164 */ 160 */
165 public float getFuelCapacity() throws CarNotConnectedException { 161 public float getFuelCapacity() throws CarNotConnectedException {
166 CarPropertyValue<Float> carProp = getProperty(Float.class, 162 CarPropertyValue<Float> carProp = mCarPropertyMgr.getProperty(Float.class,
167 BASIC_INFO_FUEL_CAPACITY, 0); 163 BASIC_INFO_FUEL_CAPACITY, 0);
168 return carProp != null ? carProp.getValue() : 0f; 164 return carProp != null ? carProp.getValue() : 0f;
169 } 165 }
@@ -173,8 +169,7 @@ public final class CarInfoManager implements CarManagerBase{
173 * types available. 169 * types available.
174 */ 170 */
175 public @FuelType.Enum int[] getFuelTypes() throws CarNotConnectedException { 171 public @FuelType.Enum int[] getFuelTypes() throws CarNotConnectedException {
176 CarPropertyValue<int[]> carProp = getProperty(int[].class, BASIC_INFO_FUEL_TYPES, 0); 172 return mCarPropertyMgr.getIntArrayProperty(BASIC_INFO_FUEL_TYPES, 0);
177 return carProp != null ? carProp.getValue() : new int[0];
178 } 173 }
179 174
180 /** 175 /**
@@ -182,7 +177,7 @@ public final class CarInfoManager implements CarManagerBase{
182 * battery. 177 * battery.
183 */ 178 */
184 public float getEvBatteryCapacity() throws CarNotConnectedException { 179 public float getEvBatteryCapacity() throws CarNotConnectedException {
185 CarPropertyValue<Float> carProp = getProperty(Float.class, 180 CarPropertyValue<Float> carProp = mCarPropertyMgr.getProperty(Float.class,
186 BASIC_INFO_EV_BATTERY_CAPACITY, 0); 181 BASIC_INFO_EV_BATTERY_CAPACITY, 0);
187 return carProp != null ? carProp.getValue() : 0f; 182 return carProp != null ? carProp.getValue() : 0f;
188 } 183 }
@@ -192,42 +187,17 @@ public final class CarInfoManager implements CarManagerBase{
192 * no connector types available. 187 * no connector types available.
193 */ 188 */
194 public @EvConnectorType.Enum int[] getEvConnectorTypes() throws CarNotConnectedException { 189 public @EvConnectorType.Enum int[] getEvConnectorTypes() throws CarNotConnectedException {
195 CarPropertyValue<int[]> carProp = getProperty(int[].class, 190 return mCarPropertyMgr.getIntArrayProperty(BASIC_INFO_EV_CONNECTOR_TYPES, 0);
196 BASIC_INFO_EV_CONNECTOR_TYPES, 0);
197 return carProp != null ? carProp.getValue() : new int[0];
198 } 191 }
199 192
200 /** @hide */ 193 /** @hide */
201 CarInfoManager(IBinder service) { 194 CarInfoManager(IBinder service) {
202 mService = ICarProperty.Stub.asInterface(service); 195 mCarPropertyMgr = new CarPropertyManager(service, null, DBG, TAG);
203 } 196 }
204 197
205 /** @hide */ 198 /** @hide */
206 public void onCarDisconnected() { 199 public void onCarDisconnected() {
200 mCarPropertyMgr.onCarDisconnected();
207 } 201 }
208 202
209 private <E> CarPropertyValue<E> getProperty(Class<E> clazz, int propId, int area)
210 throws CarNotConnectedException {
211 if (DBG) {
212 Log.d(TAG, "getProperty, propId: 0x" + toHexString(propId)
213 + ", area: 0x" + toHexString(area) + ", class: " + clazz);
214 }
215 try {
216 CarPropertyValue<E> propVal = mService.getProperty(propId, area);
217 if (propVal != null && propVal.getValue() != null) {
218 Class<?> actualClass = propVal.getValue().getClass();
219 if (actualClass != clazz) {
220 throw new IllegalArgumentException("Invalid property type. " + "Expected: "
221 + clazz + ", but was: " + actualClass);
222 }
223 }
224 return propVal;
225 } catch (RemoteException e) {
226 Log.e(TAG, "getProperty failed with " + e.toString()
227 + ", propId: 0x" + toHexString(propId) + ", area: 0x" + toHexString(area), e);
228 throw new CarNotConnectedException(e);
229 } catch (IllegalArgumentException e) {
230 return null;
231 }
232 }
233} 203}