add Java side vehiclenetwork API test and fix Java compatibility
- added exception infor for Java side as aidl generated code
always assumes it.
- changed Java side API to remove int result as exception
will be thrown for error code anyway.
- Native side still returns error code as there is no
exception support.
- added python script to generate java side const declaring source.
will add C++ side later (for checking HAL impl):
VehicleNetworkConsts.java is auto-generated using
vehiclehal_code_gen.py
bug: 24095928
Change-Id: If9dcd00e5ffd7411d2e3a5c8495633c7fd7be80c
(cherry picked from commit a73f6d72ac84959661559b5411fad783949e5134)
diff --git a/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/VehicleNetwork.java b/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/VehicleNetwork.java
index 8ed4433..54ff7d3 100644
--- a/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/VehicleNetwork.java
+++ b/libvehiclenetwork/java/src/com/android/car/vehiclenetwork/VehicleNetwork.java
@@ -31,16 +31,13 @@
/**
* System API to access Vehicle network. This is only for system services and applications should
- * not use this.
+ * not use this. All APIs will fail with security error if normal app tries this.
*/
public class VehicleNetwork {
public interface VehicleNetworkListener {
void onVehicleNetworkEvents(VehiclePropValues values);
}
- public static final int NO_ERROR = 0;
- public static final int ERROR_UNKNOWN = -1;
-
private static final String TAG = VehicleNetwork.class.getSimpleName();
private final IVehicleNetwork mService;
@@ -48,11 +45,13 @@
private final IVehicleNetworkListenerImpl mVehicleNetworkListener;
private final EventHandler mEventHandler;
- public VehicleNetwork createVehicleNetwork(VehicleNetworkListener listener, Looper looper) {
+ public static VehicleNetwork createVehicleNetwork(VehicleNetworkListener listener,
+ Looper looper) {
IVehicleNetwork service = IVehicleNetwork.Stub.asInterface(ServiceManager.getService(
IVehicleNetwork.class.getCanonicalName()));
if (service == null) {
- throw new RuntimeException("Vehicle network service not available");
+ throw new RuntimeException("Vehicle network service not available:" +
+ IVehicleNetwork.class.getCanonicalName());
}
return new VehicleNetwork(service, listener, looper);
}
@@ -65,6 +64,10 @@
mVehicleNetworkListener = new IVehicleNetworkListenerImpl(this);
}
+ public VehiclePropConfigs listProperties() {
+ return listProperties(0 /* all */);
+ }
+
public VehiclePropConfigs listProperties(int property) {
try {
VehiclePropConfigsParcelable parcelable = mService.listProperties(property);
@@ -77,15 +80,13 @@
return null;
}
- public int setProperty(VehiclePropValue value) {
+ public void setProperty(VehiclePropValue value) {
VehiclePropValueParcelable parcelable = new VehiclePropValueParcelable(value);
try {
- int r = mService.setProperty(parcelable);
- return r;
+ mService.setProperty(parcelable);
} catch (RemoteException e) {
handleRemoteException(e);
}
- return ERROR_UNKNOWN;
}
public VehiclePropValue getProperty(int property) {
@@ -100,14 +101,12 @@
return null;
}
- public int subscribe(int property, float sampleRate) {
+ public void subscribe(int property, float sampleRate) {
try {
- int r = mService.subscribe(mVehicleNetworkListener, property, sampleRate);
- return r;
+ mService.subscribe(mVehicleNetworkListener, property, sampleRate);
} catch (RemoteException e) {
handleRemoteException(e);
}
- return ERROR_UNKNOWN;
}
public void unsubscribe(int property) {