aboutsummaryrefslogtreecommitdiff
path: root/car-lib
diff options
context:
space:
mode:
authorKai Wang <kwangsudo@google.com>2018-06-21 06:36:22 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-06-21 06:36:22 +0000
commit12eecfd9600c0f48b3652733f60c29e70ad6650b (patch)
treee505d2db6525b4b5294bc02bc81d45db1a9e66d0 /car-lib
parentf4339b8cb132a3b6635f4516eb7f65cf8e074fe7 (diff)
parenta456cd7fa8d51c92f25ad4515cc2f13131d78e82 (diff)
downloadCar-12eecfd9600c0f48b3652733f60c29e70ad6650b.tar.gz
Merge "Import CarPropertyManager into CarInfoManager" into pi-dev
Diffstat (limited to 'car-lib')
-rw-r--r--car-lib/src/android/car/CarInfoManager.java52
-rw-r--r--car-lib/src/android/car/hardware/property/CarPropertyManager.java11
2 files changed, 22 insertions, 41 deletions
diff --git a/car-lib/src/android/car/CarInfoManager.java b/car-lib/src/android/car/CarInfoManager.java
index c18d18eb1d..ffeaa93601 100644
--- a/car-lib/src/android/car/CarInfoManager.java
+++ b/car-lib/src/android/car/CarInfoManager.java
@@ -16,16 +16,12 @@
package android.car;
-import static java.lang.Integer.toHexString;
-
import android.annotation.Nullable;
import android.car.annotation.ValueTypeDef;
import android.car.hardware.CarPropertyValue;
-import android.car.hardware.property.ICarProperty;
+import android.car.hardware.property.CarPropertyManager;
import android.os.Bundle;
import android.os.IBinder;
-import android.os.RemoteException;
-import android.util.Log;
/**
@@ -36,6 +32,7 @@ public final class CarInfoManager implements CarManagerBase{
private static final boolean DBG = false;
private static final String TAG = "CarInfoManager";
+ private final CarPropertyManager mCarPropertyMgr;
/**
* Key for manufacturer of the car. Passed in basic info Bundle.
* @hide
@@ -115,14 +112,12 @@ public final class CarInfoManager implements CarManagerBase{
@ValueTypeDef(type = Integer[].class)
public static final int BASIC_INFO_EV_CONNECTOR_TYPES = 0x11410107;
- private final ICarProperty mService;
-
/**
* @return Manufacturer of the car. Null if not available.
*/
@Nullable
public String getManufacturer() throws CarNotConnectedException {
- CarPropertyValue<String> carProp = getProperty(String.class,
+ CarPropertyValue<String> carProp = mCarPropertyMgr.getProperty(String.class,
BASIC_INFO_KEY_MANUFACTURER, 0);
return carProp != null ? carProp.getValue() : null;
}
@@ -134,7 +129,8 @@ public final class CarInfoManager implements CarManagerBase{
*/
@Nullable
public String getModel() throws CarNotConnectedException {
- CarPropertyValue<String> carProp = getProperty(String.class, BASIC_INFO_KEY_MODEL, 0);
+ CarPropertyValue<String> carProp = mCarPropertyMgr.getProperty(
+ String.class, BASIC_INFO_KEY_MODEL, 0);
return carProp != null ? carProp.getValue() : null;
}
@@ -143,7 +139,7 @@ public final class CarInfoManager implements CarManagerBase{
*/
@Nullable
public String getModelYear() throws CarNotConnectedException {
- CarPropertyValue<String> carProp = getProperty(String.class,
+ CarPropertyValue<String> carProp = mCarPropertyMgr.getProperty(String.class,
BASIC_INFO_KEY_MODEL_YEAR, 0);
return carProp != null ? carProp.getValue() : null;
}
@@ -163,7 +159,7 @@ public final class CarInfoManager implements CarManagerBase{
* fuel.
*/
public float getFuelCapacity() throws CarNotConnectedException {
- CarPropertyValue<Float> carProp = getProperty(Float.class,
+ CarPropertyValue<Float> carProp = mCarPropertyMgr.getProperty(Float.class,
BASIC_INFO_FUEL_CAPACITY, 0);
return carProp != null ? carProp.getValue() : 0f;
}
@@ -173,7 +169,8 @@ public final class CarInfoManager implements CarManagerBase{
* types available.
*/
public @FuelType.Enum int[] getFuelTypes() throws CarNotConnectedException {
- CarPropertyValue<int[]> carProp = getProperty(int[].class, BASIC_INFO_FUEL_TYPES, 0);
+ CarPropertyValue<int[]> carProp = mCarPropertyMgr.getProperty(
+ int[].class, BASIC_INFO_FUEL_TYPES, 0);
return carProp != null ? carProp.getValue() : new int[0];
}
@@ -182,7 +179,7 @@ public final class CarInfoManager implements CarManagerBase{
* battery.
*/
public float getEvBatteryCapacity() throws CarNotConnectedException {
- CarPropertyValue<Float> carProp = getProperty(Float.class,
+ CarPropertyValue<Float> carProp = mCarPropertyMgr.getProperty(Float.class,
BASIC_INFO_EV_BATTERY_CAPACITY, 0);
return carProp != null ? carProp.getValue() : 0f;
}
@@ -192,42 +189,19 @@ public final class CarInfoManager implements CarManagerBase{
* no connector types available.
*/
public @EvConnectorType.Enum int[] getEvConnectorTypes() throws CarNotConnectedException {
- CarPropertyValue<int[]> carProp = getProperty(int[].class,
+ CarPropertyValue<int[]> carProp = mCarPropertyMgr.getProperty(int[].class,
BASIC_INFO_EV_CONNECTOR_TYPES, 0);
return carProp != null ? carProp.getValue() : new int[0];
}
/** @hide */
CarInfoManager(IBinder service) {
- mService = ICarProperty.Stub.asInterface(service);
+ mCarPropertyMgr = new CarPropertyManager(service, null, DBG, TAG);
}
/** @hide */
public void onCarDisconnected() {
+ mCarPropertyMgr.onCarDisconnected();
}
- private <E> CarPropertyValue<E> getProperty(Class<E> clazz, int propId, int area)
- throws CarNotConnectedException {
- if (DBG) {
- Log.d(TAG, "getProperty, propId: 0x" + toHexString(propId)
- + ", area: 0x" + toHexString(area) + ", class: " + clazz);
- }
- try {
- CarPropertyValue<E> propVal = mService.getProperty(propId, area);
- if (propVal != null && propVal.getValue() != null) {
- Class<?> actualClass = propVal.getValue().getClass();
- if (actualClass != clazz) {
- throw new IllegalArgumentException("Invalid property type. " + "Expected: "
- + clazz + ", but was: " + actualClass);
- }
- }
- return propVal;
- } catch (RemoteException e) {
- Log.e(TAG, "getProperty failed with " + e.toString()
- + ", propId: 0x" + toHexString(propId) + ", area: 0x" + toHexString(area), e);
- throw new CarNotConnectedException(e);
- } catch (IllegalArgumentException e) {
- return null;
- }
- }
}
diff --git a/car-lib/src/android/car/hardware/property/CarPropertyManager.java b/car-lib/src/android/car/hardware/property/CarPropertyManager.java
index 81508dab2b..dc23adf71e 100644
--- a/car-lib/src/android/car/hardware/property/CarPropertyManager.java
+++ b/car-lib/src/android/car/hardware/property/CarPropertyManager.java
@@ -18,6 +18,7 @@ package android.car.hardware.property;
import static java.lang.Integer.toHexString;
+import android.annotation.Nullable;
import android.car.CarApiUtil;
import android.car.CarManagerBase;
import android.car.CarNotConnectedException;
@@ -70,7 +71,7 @@ public class CarPropertyManager implements CarManagerBase {
/**
* Get an instance of the CarPropertyManager.
*/
- public CarPropertyManager(IBinder service, Handler handler, boolean dbg, String tag) {
+ public CarPropertyManager(IBinder service, @Nullable Handler handler, boolean dbg, String tag) {
mDbg = dbg;
mTag = tag;
mService = ICarProperty.Stub.asInterface(service);
@@ -80,6 +81,10 @@ public class CarPropertyManager implements CarManagerBase {
Log.e(mTag, "getPropertyList exception ", e);
throw new RuntimeException(e);
}
+ if (handler == null) {
+ mHandler = null;
+ return;
+ }
mHandler = new SingleMessageHandler<CarPropertyEvent>(handler.getLooper(),
MSG_GENERIC_EVENT) {
@Override
@@ -161,7 +166,9 @@ public class CarPropertyManager implements CarManagerBase {
}
private void handleEvent(List<CarPropertyEvent> events) {
- mHandler.sendEvents(events);
+ if (mHandler != null) {
+ mHandler.sendEvents(events);
+ }
}
/**